]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
greybus: core: add lower-limit for host-device buffers
authorJohan Hovold <johan@hovoldconsulting.com>
Tue, 19 May 2015 09:22:45 +0000 (11:22 +0200)
committerGreg Kroah-Hartman <gregkh@google.com>
Thu, 21 May 2015 05:52:03 +0000 (22:52 -0700)
Make sure we never end up with a host device with maximum buffer size
smaller than the shortest Greybus message.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
drivers/staging/greybus/core.c
drivers/staging/greybus/operation.h

index e32d6c41e87e87cd17991fa03b97175238aae145..91dcc5bb158c0a60b25c88c95819f61937433af0 100644 (file)
@@ -188,6 +188,11 @@ struct greybus_host_device *greybus_create_hd(struct greybus_host_driver *driver
                return NULL;
        }
 
+       if (buffer_size_max < GB_OPERATION_MESSAGE_SIZE_MIN) {
+               dev_err(parent, "greybus host-device buffers too small\n");
+               return NULL;
+       }
+
        /*
         * Make sure to never allocate messages larger than what the Greybus
         * protocol supports.
index 1edd512d9a76774adb3fc798e810d836c4400e9b..740aacc3a3db4151b94998bf0c9ae11e53b4e4c3 100644 (file)
@@ -69,6 +69,7 @@ struct gb_operation_msg_hdr {
        __u8    pad[2];         /* must be zero (ignore when read) */
 } __aligned(sizeof(u64));
 
+#define GB_OPERATION_MESSAGE_SIZE_MIN  sizeof(struct gb_operation_msg_hdr)
 #define GB_OPERATION_MESSAGE_SIZE_MAX  U16_MAX
 
 /*