greybus: loopback: allocate a response even for a 0-byte request
authorBartosz Golaszewski <bgolaszewski@baylibre.com>
Thu, 19 Nov 2015 12:46:43 +0000 (13:46 +0100)
committerGreg Kroah-Hartman <gregkh@google.com>
Fri, 20 Nov 2015 00:02:41 +0000 (16:02 -0800)
If payload length of a transfer packet is 0, no response is allocated.
Send a well-formed response even in that case.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
drivers/staging/greybus/loopback.c

index ec68247f5bdb99e056d23c71aa96d84c14cfcf2a..0c38414a3e06841d2870b02aeb84a2fdc2f90854 100644 (file)
@@ -533,16 +533,16 @@ static int gb_loopback_request_recv(u8 type, struct gb_operation *operation)
                        return -EINVAL;
                }
 
-               if (len) {
-                       if (!gb_operation_response_alloc(operation,
-                                       len + sizeof(*response), GFP_KERNEL)) {
-                               dev_err(dev, "error allocating response\n");
-                               return -ENOMEM;
-                       }
-                       response = operation->response->payload;
-                       response->len = cpu_to_le32(len);
-                       memcpy(response->data, request->data, len);
+               if (!gb_operation_response_alloc(operation,
+                               len + sizeof(*response), GFP_KERNEL)) {
+                       dev_err(dev, "error allocating response\n");
+                       return -ENOMEM;
                }
+               response = operation->response->payload;
+               response->len = cpu_to_le32(len);
+               if (len)
+                       memcpy(response->data, request->data, len);
+
                return 0;
        default:
                dev_err(dev, "unsupported request: %hhu\n", type);