summaryrefslogtreecommitdiffstats
path: root/drivers/staging/greybus/operation.c
diff options
context:
space:
mode:
authorAlex Elder2014-12-02 15:30:31 +0100
committerGreg Kroah-Hartman2014-12-02 23:35:33 +0100
commit55f66a88dbd718c2133ac759eee4ff51f516bf45 (patch)
treeedfc7885c7f61c84dadadcb2c988e498fb48dd35 /drivers/staging/greybus/operation.c
parentgreybus: pass result in gb_connection_recv_response() (diff)
downloadkernel-qcow2-linux-55f66a88dbd718c2133ac759eee4ff51f516bf45.tar.gz
kernel-qcow2-linux-55f66a88dbd718c2133ac759eee4ff51f516bf45.tar.xz
kernel-qcow2-linux-55f66a88dbd718c2133ac759eee4ff51f516bf45.zip
greybus: enforce non-zero operation type requirement
The operation type 0x00 is reserved as an explicitly invalid operation type in all protocols. Enforce this. Add a check for callers who erroneously have the RESPONSE message type flag set in the operation type passed in gb_operation_create(). Signed-off-by: Alex Elder <elder@linaro.org> Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Diffstat (limited to 'drivers/staging/greybus/operation.c')
-rw-r--r--drivers/staging/greybus/operation.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/drivers/staging/greybus/operation.c b/drivers/staging/greybus/operation.c
index c4898f61b1f7..53fffb190dbf 100644
--- a/drivers/staging/greybus/operation.c
+++ b/drivers/staging/greybus/operation.c
@@ -455,10 +455,23 @@ err_cache:
return NULL;
}
+/*
+ * Create a new operation associated with the given connection. The
+ * request and response sizes provided are the number of bytes
+ * required to hold the request/response payload only. Both of
+ * these are allowed to be 0. Note that 0x00 is reserved as an
+ * invalid operation type for all protocols, and this is enforced
+ * here.
+ */
struct gb_operation *gb_operation_create(struct gb_connection *connection,
u8 type, size_t request_size,
size_t response_size)
{
+ if (WARN_ON_ONCE(!type))
+ return NULL;
+ if (WARN_ON_ONCE(type & GB_OPERATION_TYPE_RESPONSE))
+ type &= ~GB_OPERATION_TYPE_RESPONSE;
+
return gb_operation_create_common(connection, true, type,
request_size, response_size);
}