From: Johan Hovold Date: Tue, 19 May 2015 09:22:45 +0000 (+0200) Subject: greybus: core: add lower-limit for host-device buffers X-Git-Tag: v4.9-rc1~119^2~378^2~21^2~1523 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=8e929a8230794c4b034d0f4b658aa03702f3800d;p=karo-tx-linux.git greybus: core: add lower-limit for host-device buffers 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 Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/greybus/core.c b/drivers/staging/greybus/core.c index e32d6c41e87e..91dcc5bb158c 100644 --- a/drivers/staging/greybus/core.c +++ b/drivers/staging/greybus/core.c @@ -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. diff --git a/drivers/staging/greybus/operation.h b/drivers/staging/greybus/operation.h index 1edd512d9a76..740aacc3a3db 100644 --- a/drivers/staging/greybus/operation.h +++ b/drivers/staging/greybus/operation.h @@ -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 /*