This patch (as837) fixes several mistakes in the AIO interface of the
gadgetfs driver:

        The ki_retry method is not supposed to do a put on the kiocb.
        The extra call to aio_put_req() causes memory corruption.
        (Note: This call was removed before, by patch as691, and then
        mysteriously re-introduced later.)

        Even if a read transfer is cancelled, we should still send
        to the user all the data that did manage to get transferred.

        Testing for AIO cancellation in the I/O completion handler
        is both racy and unnecessary.  aio_complete() does its own
        checking, in a safe manner.

Signed-off-by: Alan Stern <[EMAIL PROTECTED]>

---

This is meant to apply on top of David's recent whitespace fixup for 
gadgetfs.


Index: usb-2.6/drivers/usb/gadget/inode.c
===================================================================
--- usb-2.6.orig/drivers/usb/gadget/inode.c
+++ usb-2.6/drivers/usb/gadget/inode.c
@@ -586,7 +586,6 @@ static ssize_t ep_aio_read_retry(struct 
        }
        kfree(priv->buf);
        kfree(priv);
-       aio_put_req(iocb);
        return len;
 }
 
@@ -600,18 +599,16 @@ static void ep_aio_complete(struct usb_e
        spin_lock(&epdata->dev->lock);
        priv->req = NULL;
        priv->epdata = NULL;
-       if (priv->iv == NULL
-                       || unlikely(req->actual == 0)
-                       || unlikely(kiocbIsCancelled(iocb))) {
+
+       /* if this was a write or a read returning no data then we
+        * don't need to copy anything to userspace, so we can
+        * complete the aio request immediately. */
+       if (priv->iv == NULL || unlikely(req->actual == 0)) {
                kfree(req->buf);
                kfree(priv);
                iocb->private = NULL;
                /* aio_complete() reports bytes-transferred _and_ faults */
-               if (unlikely(kiocbIsCancelled(iocb)))
-                       aio_put_req(iocb);
-               else
-                       aio_complete(iocb,
-                               req->actual ? req->actual : req->status,
+               aio_complete(iocb, req->actual ? req->actual : req->status,
                                req->status);
        } else {
                /* retry() won't report both; so we hide some faults */


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
[email protected]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to