From a9163b2c30c9e110530ed5f56bc5296bb152aa98 Mon Sep 17 00:00:00 2001 From: Alex Elder Date: Tue, 18 Nov 2014 13:26:44 -0600 Subject: [PATCH] greybus: cancel buffers via magic cookie Change the interface for canceling in-flight buffers to take a magic cookie value as argument rather than a gbuf. Right now we pass the gbuf->hcd_data pointer that's assumed to have been set by the submit routine. But the next patch will change the submit routine to return the cookie to be used, and the caller will be responsible for keeping track of it. Signed-off-by: Alex Elder Signed-off-by: Greg Kroah-Hartman --- drivers/staging/greybus/core.c | 4 ++-- drivers/staging/greybus/es1-ap-usb.c | 16 +++++++++------- drivers/staging/greybus/greybus.h | 4 ++-- drivers/staging/greybus/operation.c | 3 ++- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/drivers/staging/greybus/core.c b/drivers/staging/greybus/core.c index 0f03521c53f9..39f8c4a5c2d2 100644 --- a/drivers/staging/greybus/core.c +++ b/drivers/staging/greybus/core.c @@ -170,9 +170,9 @@ struct greybus_host_device *greybus_create_hd(struct greybus_host_driver *driver * so that we don't have to every time we make them. */ if ((!driver->buffer_alloc) || (!driver->buffer_free) || - (!driver->submit_svc) || (!driver->submit_gbuf) || - (!driver->kill_gbuf)) { + (!driver->buffer_cancel) || + (!driver->submit_svc)) { pr_err("Must implement all greybus_host_driver callbacks!\n"); return NULL; } diff --git a/drivers/staging/greybus/es1-ap-usb.c b/drivers/staging/greybus/es1-ap-usb.c index 660c36367cbd..c4a7def1dda7 100644 --- a/drivers/staging/greybus/es1-ap-usb.c +++ b/drivers/staging/greybus/es1-ap-usb.c @@ -226,13 +226,15 @@ static int submit_gbuf(struct gbuf *gbuf, gfp_t gfp_mask) return retval; } -static void kill_gbuf(struct gbuf *gbuf) +static void buffer_cancel(void *cookie) { - struct urb *urb = gbuf->hcd_data; - - if (!urb) - return; + struct urb *urb = cookie; + /* + * We really should be defensive and track all outstanding + * (sent) buffers rather than trusting the cookie provided + * is valid. For the time being, this will do. + */ usb_kill_urb(urb); } @@ -240,9 +242,9 @@ static struct greybus_host_driver es1_driver = { .hd_priv_size = sizeof(struct es1_ap_dev), .buffer_alloc = buffer_alloc, .buffer_free = buffer_free, - .submit_svc = submit_svc, .submit_gbuf = submit_gbuf, - .kill_gbuf = kill_gbuf, + .buffer_cancel = buffer_cancel, + .submit_svc = submit_svc, }; /* Common function to report consistent warnings based on URB status */ diff --git a/drivers/staging/greybus/greybus.h b/drivers/staging/greybus/greybus.h index f27dcaf067ca..a9b2b459d7ad 100644 --- a/drivers/staging/greybus/greybus.h +++ b/drivers/staging/greybus/greybus.h @@ -81,10 +81,10 @@ struct greybus_host_driver { void *(*buffer_alloc)(unsigned int size, gfp_t gfp_mask); void (*buffer_free)(void *buffer); + int (*submit_gbuf)(struct gbuf *gbuf, gfp_t gfp_mask); + void (*buffer_cancel)(void *cookie); int (*submit_svc)(struct svc_msg *svc_msg, struct greybus_host_device *hd); - int (*submit_gbuf)(struct gbuf *gbuf, gfp_t gfp_mask); - void (*kill_gbuf)(struct gbuf *gbuf); }; struct greybus_host_device { diff --git a/drivers/staging/greybus/operation.c b/drivers/staging/greybus/operation.c index c04aced63204..26c9dd688cc3 100644 --- a/drivers/staging/greybus/operation.c +++ b/drivers/staging/greybus/operation.c @@ -115,8 +115,9 @@ static void greybus_kill_gbuf(struct gbuf *gbuf) if (gbuf->status != -EINPROGRESS) return; - gbuf->hd->driver->kill_gbuf(gbuf); + gbuf->hd->driver->buffer_cancel(gbuf->hcd_data); } + /* * An operations's response message has arrived. If no callback was * supplied it was submitted for asynchronous completion, so we notify -- 2.20.1