From 835fb5e4985de46aafb7fbcf975663d375e7b4b4 Mon Sep 17 00:00:00 2001 From: Alex Elder Date: Tue, 2 Dec 2014 08:30:34 -0600 Subject: [PATCH] greybus: enforce a buffer headroom maximum size Define a maximum size that a host device can use for its private area ahead of the payload space used by Greybus in a message buffer. Signed-off-by: Alex Elder Signed-off-by: Greg Kroah-Hartman --- drivers/staging/greybus/es1-ap-usb.c | 1 + drivers/staging/greybus/greybus.h | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/drivers/staging/greybus/es1-ap-usb.c b/drivers/staging/greybus/es1-ap-usb.c index 1832d0f41b8a..f551907ced2d 100644 --- a/drivers/staging/greybus/es1-ap-usb.c +++ b/drivers/staging/greybus/es1-ap-usb.c @@ -127,6 +127,7 @@ static void hd_buffer_constraints(struct greybus_host_device *hd) */ hd->buffer_headroom = sizeof(u32); /* For cport id */ hd->buffer_size_max = ES1_GBUF_MSG_SIZE_MAX; + BUILD_BUG_ON(hd->buffer_headroom > GB_BUFFER_HEADROOM_MAX); } #define ES1_TIMEOUT 500 /* 500 ms for the SVC to do something */ diff --git a/drivers/staging/greybus/greybus.h b/drivers/staging/greybus/greybus.h index 8fda37c42a0c..11f4e5529d9a 100644 --- a/drivers/staging/greybus/greybus.h +++ b/drivers/staging/greybus/greybus.h @@ -69,6 +69,14 @@ struct greybus_host_device; struct svc_msg; +/* + * When the Greybus code allocates a buffer it sets aside bytes + * prior to the beginning of the payload area for the host device's + * exclusive use. The size is specified by hd->buffer_headroom, and + * which can't be greater than GB_BUFFER_HEADROOM_MAX. + */ +#define GB_BUFFER_HEADROOM_MAX sizeof(u64) + /* Buffers allocated from the host driver will be aligned to this multiple */ #define GB_BUFFER_ALIGN sizeof(u32) -- 2.39.5