diff options
Diffstat (limited to 'drivers/usb/gadget/inode.c')
-rw-r--r-- | drivers/usb/gadget/inode.c | 62 |
1 files changed, 34 insertions, 28 deletions
diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c index 0eb010a3f5b..aef0722b8f1 100644 --- a/drivers/usb/gadget/inode.c +++ b/drivers/usb/gadget/inode.c | |||
@@ -528,7 +528,7 @@ struct kiocb_priv { | |||
528 | struct usb_request *req; | 528 | struct usb_request *req; |
529 | struct ep_data *epdata; | 529 | struct ep_data *epdata; |
530 | void *buf; | 530 | void *buf; |
531 | char __user *ubuf; | 531 | char __user *ubuf; /* NULL for writes */ |
532 | unsigned actual; | 532 | unsigned actual; |
533 | }; | 533 | }; |
534 | 534 | ||
@@ -566,7 +566,6 @@ static ssize_t ep_aio_read_retry(struct kiocb *iocb) | |||
566 | status = priv->actual; | 566 | status = priv->actual; |
567 | kfree(priv->buf); | 567 | kfree(priv->buf); |
568 | kfree(priv); | 568 | kfree(priv); |
569 | aio_put_req(iocb); | ||
570 | return status; | 569 | return status; |
571 | } | 570 | } |
572 | 571 | ||
@@ -580,8 +579,8 @@ static void ep_aio_complete(struct usb_ep *ep, struct usb_request *req) | |||
580 | spin_lock(&epdata->dev->lock); | 579 | spin_lock(&epdata->dev->lock); |
581 | priv->req = NULL; | 580 | priv->req = NULL; |
582 | priv->epdata = NULL; | 581 | priv->epdata = NULL; |
583 | if (NULL == iocb->ki_retry | 582 | if (priv->ubuf == NULL |
584 | || unlikely(0 == req->actual) | 583 | || unlikely(req->actual == 0) |
585 | || unlikely(kiocbIsCancelled(iocb))) { | 584 | || unlikely(kiocbIsCancelled(iocb))) { |
586 | kfree(req->buf); | 585 | kfree(req->buf); |
587 | kfree(priv); | 586 | kfree(priv); |
@@ -618,7 +617,7 @@ ep_aio_rwtail( | |||
618 | char __user *ubuf | 617 | char __user *ubuf |
619 | ) | 618 | ) |
620 | { | 619 | { |
621 | struct kiocb_priv *priv = (void *) &iocb->private; | 620 | struct kiocb_priv *priv; |
622 | struct usb_request *req; | 621 | struct usb_request *req; |
623 | ssize_t value; | 622 | ssize_t value; |
624 | 623 | ||
@@ -670,7 +669,7 @@ fail: | |||
670 | kfree(priv); | 669 | kfree(priv); |
671 | put_ep(epdata); | 670 | put_ep(epdata); |
672 | } else | 671 | } else |
673 | value = -EIOCBQUEUED; | 672 | value = (ubuf ? -EIOCBRETRY : -EIOCBQUEUED); |
674 | return value; | 673 | return value; |
675 | } | 674 | } |
676 | 675 | ||
@@ -1039,7 +1038,7 @@ scan: | |||
1039 | /* ep0 can't deliver events when STATE_SETUP */ | 1038 | /* ep0 can't deliver events when STATE_SETUP */ |
1040 | for (i = 0; i < n; i++) { | 1039 | for (i = 0; i < n; i++) { |
1041 | if (dev->event [i].type == GADGETFS_SETUP) { | 1040 | if (dev->event [i].type == GADGETFS_SETUP) { |
1042 | len = n = i + 1; | 1041 | len = i + 1; |
1043 | len *= sizeof (struct usb_gadgetfs_event); | 1042 | len *= sizeof (struct usb_gadgetfs_event); |
1044 | n = 0; | 1043 | n = 0; |
1045 | break; | 1044 | break; |
@@ -1587,13 +1586,13 @@ gadgetfs_create_file (struct super_block *sb, char const *name, | |||
1587 | static int activate_ep_files (struct dev_data *dev) | 1586 | static int activate_ep_files (struct dev_data *dev) |
1588 | { | 1587 | { |
1589 | struct usb_ep *ep; | 1588 | struct usb_ep *ep; |
1589 | struct ep_data *data; | ||
1590 | 1590 | ||
1591 | gadget_for_each_ep (ep, dev->gadget) { | 1591 | gadget_for_each_ep (ep, dev->gadget) { |
1592 | struct ep_data *data; | ||
1593 | 1592 | ||
1594 | data = kzalloc(sizeof(*data), GFP_KERNEL); | 1593 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
1595 | if (!data) | 1594 | if (!data) |
1596 | goto enomem; | 1595 | goto enomem0; |
1597 | data->state = STATE_EP_DISABLED; | 1596 | data->state = STATE_EP_DISABLED; |
1598 | init_MUTEX (&data->lock); | 1597 | init_MUTEX (&data->lock); |
1599 | init_waitqueue_head (&data->wait); | 1598 | init_waitqueue_head (&data->wait); |
@@ -1608,21 +1607,23 @@ static int activate_ep_files (struct dev_data *dev) | |||
1608 | 1607 | ||
1609 | data->req = usb_ep_alloc_request (ep, GFP_KERNEL); | 1608 | data->req = usb_ep_alloc_request (ep, GFP_KERNEL); |
1610 | if (!data->req) | 1609 | if (!data->req) |
1611 | goto enomem; | 1610 | goto enomem1; |
1612 | 1611 | ||
1613 | data->inode = gadgetfs_create_file (dev->sb, data->name, | 1612 | data->inode = gadgetfs_create_file (dev->sb, data->name, |
1614 | data, &ep_config_operations, | 1613 | data, &ep_config_operations, |
1615 | &data->dentry); | 1614 | &data->dentry); |
1616 | if (!data->inode) { | 1615 | if (!data->inode) |
1617 | usb_ep_free_request(ep, data->req); | 1616 | goto enomem2; |
1618 | kfree (data); | ||
1619 | goto enomem; | ||
1620 | } | ||
1621 | list_add_tail (&data->epfiles, &dev->epfiles); | 1617 | list_add_tail (&data->epfiles, &dev->epfiles); |
1622 | } | 1618 | } |
1623 | return 0; | 1619 | return 0; |
1624 | 1620 | ||
1625 | enomem: | 1621 | enomem2: |
1622 | usb_ep_free_request (ep, data->req); | ||
1623 | enomem1: | ||
1624 | put_dev (dev); | ||
1625 | kfree (data); | ||
1626 | enomem0: | ||
1626 | DBG (dev, "%s enomem\n", __FUNCTION__); | 1627 | DBG (dev, "%s enomem\n", __FUNCTION__); |
1627 | destroy_ep_files (dev); | 1628 | destroy_ep_files (dev); |
1628 | return -ENOMEM; | 1629 | return -ENOMEM; |
@@ -1793,7 +1794,7 @@ static struct usb_gadget_driver probe_driver = { | |||
1793 | * | 1794 | * |
1794 | * After initialization, the device stays active for as long as that | 1795 | * After initialization, the device stays active for as long as that |
1795 | * $CHIP file is open. Events may then be read from that descriptor, | 1796 | * $CHIP file is open. Events may then be read from that descriptor, |
1796 | * such configuration notifications. More complex drivers will handle | 1797 | * such as configuration notifications. More complex drivers will handle |
1797 | * some control requests in user space. | 1798 | * some control requests in user space. |
1798 | */ | 1799 | */ |
1799 | 1800 | ||
@@ -2033,12 +2034,10 @@ gadgetfs_fill_super (struct super_block *sb, void *opts, int silent) | |||
2033 | NULL, &simple_dir_operations, | 2034 | NULL, &simple_dir_operations, |
2034 | S_IFDIR | S_IRUGO | S_IXUGO); | 2035 | S_IFDIR | S_IRUGO | S_IXUGO); |
2035 | if (!inode) | 2036 | if (!inode) |
2036 | return -ENOMEM; | 2037 | goto enomem0; |
2037 | inode->i_op = &simple_dir_inode_operations; | 2038 | inode->i_op = &simple_dir_inode_operations; |
2038 | if (!(d = d_alloc_root (inode))) { | 2039 | if (!(d = d_alloc_root (inode))) |
2039 | iput (inode); | 2040 | goto enomem1; |
2040 | return -ENOMEM; | ||
2041 | } | ||
2042 | sb->s_root = d; | 2041 | sb->s_root = d; |
2043 | 2042 | ||
2044 | /* the ep0 file is named after the controller we expect; | 2043 | /* the ep0 file is named after the controller we expect; |
@@ -2046,21 +2045,28 @@ gadgetfs_fill_super (struct super_block *sb, void *opts, int silent) | |||
2046 | */ | 2045 | */ |
2047 | dev = dev_new (); | 2046 | dev = dev_new (); |
2048 | if (!dev) | 2047 | if (!dev) |
2049 | return -ENOMEM; | 2048 | goto enomem2; |
2050 | 2049 | ||
2051 | dev->sb = sb; | 2050 | dev->sb = sb; |
2052 | if (!(inode = gadgetfs_create_file (sb, CHIP, | 2051 | if (!gadgetfs_create_file (sb, CHIP, |
2053 | dev, &dev_init_operations, | 2052 | dev, &dev_init_operations, |
2054 | &dev->dentry))) { | 2053 | &dev->dentry)) |
2055 | put_dev(dev); | 2054 | goto enomem3; |
2056 | return -ENOMEM; | ||
2057 | } | ||
2058 | 2055 | ||
2059 | /* other endpoint files are available after hardware setup, | 2056 | /* other endpoint files are available after hardware setup, |
2060 | * from binding to a controller. | 2057 | * from binding to a controller. |
2061 | */ | 2058 | */ |
2062 | the_device = dev; | 2059 | the_device = dev; |
2063 | return 0; | 2060 | return 0; |
2061 | |||
2062 | enomem3: | ||
2063 | put_dev (dev); | ||
2064 | enomem2: | ||
2065 | dput (d); | ||
2066 | enomem1: | ||
2067 | iput (inode); | ||
2068 | enomem0: | ||
2069 | return -ENOMEM; | ||
2064 | } | 2070 | } |
2065 | 2071 | ||
2066 | /* "mount -t gadgetfs path /dev/gadget" ends up here */ | 2072 | /* "mount -t gadgetfs path /dev/gadget" ends up here */ |