OSDN Git Service

greybus: esX: use one byte to encode cport ids in header
authorAlex Elder <elder@linaro.org>
Sat, 13 Jun 2015 16:02:11 +0000 (11:02 -0500)
committerGreg Kroah-Hartman <gregkh@google.com>
Mon, 15 Jun 2015 23:49:00 +0000 (16:49 -0700)
We now limit the maximum value for both host and module CPort ids,
and we know they can always be represented in a single byte.

Make use of this by using only one of the two pad bytes for encoding
the CPort id in a message header.

(Note that we have never used a CPort higher than 255.  Encoding
such a small CPort id in little endian 2-byte format has the same
result as what is done here.)

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
drivers/staging/greybus/es1.c
drivers/staging/greybus/es2.c

index 945dbe6..d6824b6 100644 (file)
@@ -173,19 +173,19 @@ static void free_urb(struct es1_ap_dev *es1, struct urb *urb)
 static void
 gb_message_cport_pack(struct gb_operation_msg_hdr *header, u16 cport_id)
 {
-       put_unaligned_le16(cport_id, header->pad);
+       header->pad[0] = cport_id;
 }
 
 /* Clear the pad bytes used for the CPort id */
 static void gb_message_cport_clear(struct gb_operation_msg_hdr *header)
 {
-       put_unaligned_le16(0, header->pad);
+       header->pad[0] = 0;
 }
 
 /* Extract the CPort id packed into the header, and clear it */
 static u16 gb_message_cport_unpack(struct gb_operation_msg_hdr *header)
 {
-       u16 cport_id = get_unaligned_le16(header->pad);
+       u16 cport_id = header->pad[0];
 
        gb_message_cport_clear(header);
 
@@ -574,6 +574,9 @@ static int ap_probe(struct usb_interface *interface,
        u8 ap_intf_id = 0x01;   // FIXME - get endo "ID" from the SVC
        u8 svc_interval = 0;
 
+       /* We need to fit a CPort ID in one byte of a message header */
+       BUILD_BUG_ON(CPORT_ID_MAX > U8_MAX);
+
        udev = usb_get_dev(interface_to_usbdev(interface));
 
        hd = greybus_create_hd(&es1_driver, &udev->dev, ES1_GBUF_MSG_SIZE_MAX);
index d6966bf..450a016 100644 (file)
@@ -173,19 +173,19 @@ static void free_urb(struct es1_ap_dev *es1, struct urb *urb)
 static void
 gb_message_cport_pack(struct gb_operation_msg_hdr *header, u16 cport_id)
 {
-       put_unaligned_le16(cport_id, header->pad);
+       header->pad[0] = cport_id;
 }
 
 /* Clear the pad bytes used for the CPort id */
 static void gb_message_cport_clear(struct gb_operation_msg_hdr *header)
 {
-       put_unaligned_le16(0, header->pad);
+       header->pad[0] = 0;
 }
 
 /* Extract the CPort id packed into the header, and clear it */
 static u16 gb_message_cport_unpack(struct gb_operation_msg_hdr *header)
 {
-       u16 cport_id = get_unaligned_le16(header->pad);
+       u16 cport_id = header->pad[0];
 
        gb_message_cport_clear(header);
 
@@ -574,6 +574,9 @@ static int ap_probe(struct usb_interface *interface,
        u8 ap_intf_id = 0x01;   // FIXME - get endo "ID" from the SVC
        u8 svc_interval = 0;
 
+       /* We need to fit a CPort ID in one byte of a message header */
+       BUILD_BUG_ON(CPORT_ID_MAX > U8_MAX);
+
        udev = usb_get_dev(interface_to_usbdev(interface));
 
        hd = greybus_create_hd(&es1_driver, &udev->dev, ES1_GBUF_MSG_SIZE_MAX);