diff options
author | Alan Stern <stern@rowland.harvard.edu> | 2006-05-22 12:27:38 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2006-06-21 18:04:13 -0400 |
commit | 0ae4ea8092e1277cfca07cade7eaba5f594076c1 (patch) | |
tree | 79c822a07fe4e79587460d723e32a29d70b6dab1 /drivers/usb/gadget/inode.c | |
parent | 83196b52053068f0240371ad2efd9d6ad685bbeb (diff) |
[PATCH] gadgetfs: fix memory leaks
This patch (as692) fixes a few memory leaks in some unimportant error
pathways of the gadgetfs driver.
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Acked-by: David Brownell <david-b@pacbell.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/gadget/inode.c')
-rw-r--r-- | drivers/usb/gadget/inode.c | 51 |
1 files changed, 29 insertions, 22 deletions
diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c index 57bf24810f9b..aef0722b8f17 100644 --- a/drivers/usb/gadget/inode.c +++ b/drivers/usb/gadget/inode.c | |||
@@ -1038,7 +1038,7 @@ scan: | |||
1038 | /* ep0 can't deliver events when STATE_SETUP */ | 1038 | /* ep0 can't deliver events when STATE_SETUP */ |
1039 | for (i = 0; i < n; i++) { | 1039 | for (i = 0; i < n; i++) { |
1040 | if (dev->event [i].type == GADGETFS_SETUP) { | 1040 | if (dev->event [i].type == GADGETFS_SETUP) { |
1041 | len = n = i + 1; | 1041 | len = i + 1; |
1042 | len *= sizeof (struct usb_gadgetfs_event); | 1042 | len *= sizeof (struct usb_gadgetfs_event); |
1043 | n = 0; | 1043 | n = 0; |
1044 | break; | 1044 | break; |
@@ -1586,13 +1586,13 @@ gadgetfs_create_file (struct super_block *sb, char const *name, | |||
1586 | static int activate_ep_files (struct dev_data *dev) | 1586 | static int activate_ep_files (struct dev_data *dev) |
1587 | { | 1587 | { |
1588 | struct usb_ep *ep; | 1588 | struct usb_ep *ep; |
1589 | struct ep_data *data; | ||
1589 | 1590 | ||
1590 | gadget_for_each_ep (ep, dev->gadget) { | 1591 | gadget_for_each_ep (ep, dev->gadget) { |
1591 | struct ep_data *data; | ||
1592 | 1592 | ||
1593 | data = kzalloc(sizeof(*data), GFP_KERNEL); | 1593 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
1594 | if (!data) | 1594 | if (!data) |
1595 | goto enomem; | 1595 | goto enomem0; |
1596 | data->state = STATE_EP_DISABLED; | 1596 | data->state = STATE_EP_DISABLED; |
1597 | init_MUTEX (&data->lock); | 1597 | init_MUTEX (&data->lock); |
1598 | init_waitqueue_head (&data->wait); | 1598 | init_waitqueue_head (&data->wait); |
@@ -1607,21 +1607,23 @@ static int activate_ep_files (struct dev_data *dev) | |||
1607 | 1607 | ||
1608 | data->req = usb_ep_alloc_request (ep, GFP_KERNEL); | 1608 | data->req = usb_ep_alloc_request (ep, GFP_KERNEL); |
1609 | if (!data->req) | 1609 | if (!data->req) |
1610 | goto enomem; | 1610 | goto enomem1; |
1611 | 1611 | ||
1612 | data->inode = gadgetfs_create_file (dev->sb, data->name, | 1612 | data->inode = gadgetfs_create_file (dev->sb, data->name, |
1613 | data, &ep_config_operations, | 1613 | data, &ep_config_operations, |
1614 | &data->dentry); | 1614 | &data->dentry); |
1615 | if (!data->inode) { | 1615 | if (!data->inode) |
1616 | usb_ep_free_request(ep, data->req); | 1616 | goto enomem2; |
1617 | kfree (data); | ||
1618 | goto enomem; | ||
1619 | } | ||
1620 | list_add_tail (&data->epfiles, &dev->epfiles); | 1617 | list_add_tail (&data->epfiles, &dev->epfiles); |
1621 | } | 1618 | } |
1622 | return 0; | 1619 | return 0; |
1623 | 1620 | ||
1624 | enomem: | 1621 | enomem2: |
1622 | usb_ep_free_request (ep, data->req); | ||
1623 | enomem1: | ||
1624 | put_dev (dev); | ||
1625 | kfree (data); | ||
1626 | enomem0: | ||
1625 | DBG (dev, "%s enomem\n", __FUNCTION__); | 1627 | DBG (dev, "%s enomem\n", __FUNCTION__); |
1626 | destroy_ep_files (dev); | 1628 | destroy_ep_files (dev); |
1627 | return -ENOMEM; | 1629 | return -ENOMEM; |
@@ -1792,7 +1794,7 @@ static struct usb_gadget_driver probe_driver = { | |||
1792 | * | 1794 | * |
1793 | * After initialization, the device stays active for as long as that | 1795 | * After initialization, the device stays active for as long as that |
1794 | * $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, |
1795 | * such configuration notifications. More complex drivers will handle | 1797 | * such as configuration notifications. More complex drivers will handle |
1796 | * some control requests in user space. | 1798 | * some control requests in user space. |
1797 | */ | 1799 | */ |
1798 | 1800 | ||
@@ -2032,12 +2034,10 @@ gadgetfs_fill_super (struct super_block *sb, void *opts, int silent) | |||
2032 | NULL, &simple_dir_operations, | 2034 | NULL, &simple_dir_operations, |
2033 | S_IFDIR | S_IRUGO | S_IXUGO); | 2035 | S_IFDIR | S_IRUGO | S_IXUGO); |
2034 | if (!inode) | 2036 | if (!inode) |
2035 | return -ENOMEM; | 2037 | goto enomem0; |
2036 | inode->i_op = &simple_dir_inode_operations; | 2038 | inode->i_op = &simple_dir_inode_operations; |
2037 | if (!(d = d_alloc_root (inode))) { | 2039 | if (!(d = d_alloc_root (inode))) |
2038 | iput (inode); | 2040 | goto enomem1; |
2039 | return -ENOMEM; | ||
2040 | } | ||
2041 | sb->s_root = d; | 2041 | sb->s_root = d; |
2042 | 2042 | ||
2043 | /* the ep0 file is named after the controller we expect; | 2043 | /* the ep0 file is named after the controller we expect; |
@@ -2045,21 +2045,28 @@ gadgetfs_fill_super (struct super_block *sb, void *opts, int silent) | |||
2045 | */ | 2045 | */ |
2046 | dev = dev_new (); | 2046 | dev = dev_new (); |
2047 | if (!dev) | 2047 | if (!dev) |
2048 | return -ENOMEM; | 2048 | goto enomem2; |
2049 | 2049 | ||
2050 | dev->sb = sb; | 2050 | dev->sb = sb; |
2051 | if (!(inode = gadgetfs_create_file (sb, CHIP, | 2051 | if (!gadgetfs_create_file (sb, CHIP, |
2052 | dev, &dev_init_operations, | 2052 | dev, &dev_init_operations, |
2053 | &dev->dentry))) { | 2053 | &dev->dentry)) |
2054 | put_dev(dev); | 2054 | goto enomem3; |
2055 | return -ENOMEM; | ||
2056 | } | ||
2057 | 2055 | ||
2058 | /* other endpoint files are available after hardware setup, | 2056 | /* other endpoint files are available after hardware setup, |
2059 | * from binding to a controller. | 2057 | * from binding to a controller. |
2060 | */ | 2058 | */ |
2061 | the_device = dev; | 2059 | the_device = dev; |
2062 | 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; | ||
2063 | } | 2070 | } |
2064 | 2071 | ||
2065 | /* "mount -t gadgetfs path /dev/gadget" ends up here */ | 2072 | /* "mount -t gadgetfs path /dev/gadget" ends up here */ |