From: Alex Elder Date: Wed, 19 Nov 2014 18:27:13 +0000 (-0600) Subject: greybus: explicitly mark cookies as opaque X-Git-Tag: v5.15~12752^2~378^2~21^2~1864 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2292bac5e76846387152d1d20b10cb79f8c1b14b;p=platform%2Fkernel%2Flinux-starfive.git greybus: explicitly mark cookies as opaque Use simple macros to mark the conversion of an URB pointer into an opaque cookie value (and vice-versa). We scramble some bits, but the main point is to make it explicit where we're returning and using opaque values. Signed-off-by: Alex Elder Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/greybus/es1-ap-usb.c b/drivers/staging/greybus/es1-ap-usb.c index 3404dc5..658506d 100644 --- a/drivers/staging/greybus/es1-ap-usb.c +++ b/drivers/staging/greybus/es1-ap-usb.c @@ -16,6 +16,13 @@ #include "svc_msg.h" #include "kernel_ver.h" +/* + * Macros for making pointers explicitly opaque, such that the result + * isn't valid but also can't be mistaken for an ERR_PTR() value. + */ +#define conceal_urb(urb) ((void *)((uintptr_t)(urb) ^ 0xbad)) +#define reveal_urb(cookie) ((void *)((uintptr_t)(cookie) ^ 0xbad)) + /* Memory sizes for the buffers sent to/from the ES1 controller */ #define ES1_SVC_MSG_SIZE (sizeof(struct svc_msg) + SZ_64K) #define ES1_GBUF_MSG_SIZE PAGE_SIZE @@ -241,12 +248,12 @@ static void *buffer_send(struct greybus_host_device *hd, u16 dest_cport_id, return ERR_PTR(retval); } - return urb; + return conceal_urb(urb); } static void buffer_cancel(void *cookie) { - struct urb *urb = cookie; + struct urb *urb = reveal_urb(cookie); /* * We really should be defensive and track all outstanding