]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
greybus: fill in destination data at send time
authorAlex Elder <elder@linaro.org>
Tue, 18 Nov 2014 19:26:41 +0000 (13:26 -0600)
committerGreg Kroah-Hartman <greg@kroah.com>
Tue, 18 Nov 2014 20:46:15 +0000 (12:46 -0800)
For ES1 we need to insert the destination CPort id before the data
to be sent over UniPro.  Currently this is done at the time the
buffer is created, but there's no need to do so until we're actually
going to send the content of the buffer.

Move the setting of that destination information into submit_gbuf().
Note that this allows us to defer initializing a few other gbuf
fields until after we know the buffer allocation has succeeded.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
drivers/staging/greybus/es1-ap-usb.c
drivers/staging/greybus/operation.c

index a98a2cb67211862d67e56241f01a1ed069dbdb2e..a92f8934928a078bad1f343cff64d92e2190b260 100644 (file)
@@ -95,7 +95,6 @@ static void cport_out_callback(struct urb *urb);
 static int alloc_gbuf_data(struct gbuf *gbuf, unsigned int size,
                                gfp_t gfp_mask)
 {
-       u8 dest_cport_id = gbuf->dest_cport_id;
        u8 *buffer;
 
        if (gbuf->transfer_buffer)
@@ -122,15 +121,6 @@ static int alloc_gbuf_data(struct gbuf *gbuf, unsigned int size,
                return -ENOMEM;
        buffer += GB_BUFFER_ALIGN;
 
-       /* Insert the cport id for outbound buffers */
-       if (dest_cport_id != CPORT_ID_BAD && dest_cport_id > (u16)U8_MAX) {
-               pr_err("dest_cport_id (%hd) is out of range!\n",
-                       gbuf->dest_cport_id);
-               kfree(buffer);
-               return -EINVAL;
-       }
-       *(buffer - 1) = gbuf->dest_cport_id;
-
        gbuf->transfer_buffer = buffer;
        gbuf->transfer_buffer_length = size;
 
@@ -212,6 +202,7 @@ static int submit_gbuf(struct gbuf *gbuf, gfp_t gfp_mask)
        struct greybus_host_device *hd = gbuf->hd;
        struct es1_ap_dev *es1 = hd_to_es1(hd);
        struct usb_device *udev = es1->usb_dev;
+       u16 dest_cport_id = gbuf->dest_cport_id;
        int retval;
        u8 *transfer_buffer;
        u8 *buffer;
@@ -222,11 +213,17 @@ static int submit_gbuf(struct gbuf *gbuf, gfp_t gfp_mask)
                return -EINVAL;
        buffer = &transfer_buffer[-1];  /* yes, we mean -1 */
 
-       /* Do one last check of the target CPort id */
-       if (*buffer == CPORT_ID_BAD) {
-               pr_err("request to submit inbound buffer\n");
+       /* Do one last check of the target CPort id before filling it in */
+       if (dest_cport_id == CPORT_ID_BAD) {
+               pr_err("request to send inbound data buffer\n");
+               return -EINVAL;
+       }
+       if (dest_cport_id > (u16)U8_MAX) {
+               pr_err("dest_cport_id (%hd) is out of range for ES1\n",
+                       dest_cport_id);
                return -EINVAL;
        }
+       *buffer = dest_cport_id;
 
        /* Find a free urb */
        urb = next_free_urb(es1, gfp_mask);
index 103fc9746796b34c1ba72e24b4cafd8770f97791..b5cd9a234fb6ede6e6fb9f709463a17be4560a71 100644 (file)
@@ -241,12 +241,12 @@ static int gb_operation_message_init(struct gb_operation *operation,
        else
                dest_cport_id = CPORT_ID_BAD;
 
-       gbuf->hd = hd;
-       gbuf->dest_cport_id = dest_cport_id;
-       gbuf->status = -EBADR;  /* Initial value--means "never set" */
        ret = hd->driver->alloc_gbuf_data(gbuf, size, gfp_flags);
        if (ret)
                return ret;
+       gbuf->hd = hd;
+       gbuf->dest_cport_id = dest_cport_id;
+       gbuf->status = -EBADR;  /* Initial value--means "never set" */
 
        /* Fill in the header structure */
        header = (struct gb_operation_msg_hdr *)gbuf->transfer_buffer;