greybus: cancel buffers via magic cookie
authorAlex Elder <elder@linaro.org>
Tue, 18 Nov 2014 19:26:44 +0000 (13:26 -0600)
committerGreg Kroah-Hartman <greg@kroah.com>
Tue, 18 Nov 2014 20:48:53 +0000 (12:48 -0800)
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 <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
drivers/staging/greybus/core.c
drivers/staging/greybus/es1-ap-usb.c
drivers/staging/greybus/greybus.h
drivers/staging/greybus/operation.c

index 0f03521c53f96ab7bdbe44af44d3f692b2d56da6..39f8c4a5c2d24b5950d120b353e2c5c0c0e05457 100644 (file)
@@ -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;
        }
index 660c36367cbd8af27678016cc4a36c1031e447bb..c4a7def1dda75182ad9e4dc0fd1c3d3a1bb186cc 100644 (file)
@@ -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 */
index f27dcaf067ca2231a3dcab34cde5b75b13ca6957..a9b2b459d7ad67c39c3f626cb8d749692677525e 100644 (file)
@@ -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 {
index c04aced63204d33cd6c4419a8f1934f29df536ba..26c9dd688cc3264413a546c466d5271c6c5048d9 100644 (file)
@@ -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