Commit 0ae4ea80 authored by Alan Stern's avatar Alan Stern Committed by Greg Kroah-Hartman

[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: default avatarAlan Stern <stern@rowland.harvard.edu>
Acked-by: default avatarDavid Brownell <david-b@pacbell.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 83196b52
...@@ -1038,7 +1038,7 @@ ep0_read (struct file *fd, char __user *buf, size_t len, loff_t *ptr) ...@@ -1038,7 +1038,7 @@ ep0_read (struct file *fd, char __user *buf, size_t len, loff_t *ptr)
/* ep0 can't deliver events when STATE_SETUP */ /* ep0 can't deliver events when STATE_SETUP */
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
if (dev->event [i].type == GADGETFS_SETUP) { if (dev->event [i].type == GADGETFS_SETUP) {
len = n = i + 1; len = i + 1;
len *= sizeof (struct usb_gadgetfs_event); len *= sizeof (struct usb_gadgetfs_event);
n = 0; n = 0;
break; break;
...@@ -1586,13 +1586,13 @@ gadgetfs_create_file (struct super_block *sb, char const *name, ...@@ -1586,13 +1586,13 @@ gadgetfs_create_file (struct super_block *sb, char const *name,
static int activate_ep_files (struct dev_data *dev) static int activate_ep_files (struct dev_data *dev)
{ {
struct usb_ep *ep; struct usb_ep *ep;
struct ep_data *data;
gadget_for_each_ep (ep, dev->gadget) { gadget_for_each_ep (ep, dev->gadget) {
struct ep_data *data;
data = kzalloc(sizeof(*data), GFP_KERNEL); data = kzalloc(sizeof(*data), GFP_KERNEL);
if (!data) if (!data)
goto enomem; goto enomem0;
data->state = STATE_EP_DISABLED; data->state = STATE_EP_DISABLED;
init_MUTEX (&data->lock); init_MUTEX (&data->lock);
init_waitqueue_head (&data->wait); init_waitqueue_head (&data->wait);
...@@ -1607,21 +1607,23 @@ static int activate_ep_files (struct dev_data *dev) ...@@ -1607,21 +1607,23 @@ static int activate_ep_files (struct dev_data *dev)
data->req = usb_ep_alloc_request (ep, GFP_KERNEL); data->req = usb_ep_alloc_request (ep, GFP_KERNEL);
if (!data->req) if (!data->req)
goto enomem; goto enomem1;
data->inode = gadgetfs_create_file (dev->sb, data->name, data->inode = gadgetfs_create_file (dev->sb, data->name,
data, &ep_config_operations, data, &ep_config_operations,
&data->dentry); &data->dentry);
if (!data->inode) { if (!data->inode)
usb_ep_free_request(ep, data->req); goto enomem2;
kfree (data);
goto enomem;
}
list_add_tail (&data->epfiles, &dev->epfiles); list_add_tail (&data->epfiles, &dev->epfiles);
} }
return 0; return 0;
enomem: enomem2:
usb_ep_free_request (ep, data->req);
enomem1:
put_dev (dev);
kfree (data);
enomem0:
DBG (dev, "%s enomem\n", __FUNCTION__); DBG (dev, "%s enomem\n", __FUNCTION__);
destroy_ep_files (dev); destroy_ep_files (dev);
return -ENOMEM; return -ENOMEM;
...@@ -1792,7 +1794,7 @@ static struct usb_gadget_driver probe_driver = { ...@@ -1792,7 +1794,7 @@ static struct usb_gadget_driver probe_driver = {
* *
* After initialization, the device stays active for as long as that * After initialization, the device stays active for as long as that
* $CHIP file is open. Events may then be read from that descriptor, * $CHIP file is open. Events may then be read from that descriptor,
* such configuration notifications. More complex drivers will handle * such as configuration notifications. More complex drivers will handle
* some control requests in user space. * some control requests in user space.
*/ */
...@@ -2032,12 +2034,10 @@ gadgetfs_fill_super (struct super_block *sb, void *opts, int silent) ...@@ -2032,12 +2034,10 @@ gadgetfs_fill_super (struct super_block *sb, void *opts, int silent)
NULL, &simple_dir_operations, NULL, &simple_dir_operations,
S_IFDIR | S_IRUGO | S_IXUGO); S_IFDIR | S_IRUGO | S_IXUGO);
if (!inode) if (!inode)
return -ENOMEM; goto enomem0;
inode->i_op = &simple_dir_inode_operations; inode->i_op = &simple_dir_inode_operations;
if (!(d = d_alloc_root (inode))) { if (!(d = d_alloc_root (inode)))
iput (inode); goto enomem1;
return -ENOMEM;
}
sb->s_root = d; sb->s_root = d;
/* the ep0 file is named after the controller we expect; /* 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,21 +2045,28 @@ gadgetfs_fill_super (struct super_block *sb, void *opts, int silent)
*/ */
dev = dev_new (); dev = dev_new ();
if (!dev) if (!dev)
return -ENOMEM; goto enomem2;
dev->sb = sb; dev->sb = sb;
if (!(inode = gadgetfs_create_file (sb, CHIP, if (!gadgetfs_create_file (sb, CHIP,
dev, &dev_init_operations, dev, &dev_init_operations,
&dev->dentry))) { &dev->dentry))
put_dev(dev); goto enomem3;
return -ENOMEM;
}
/* other endpoint files are available after hardware setup, /* other endpoint files are available after hardware setup,
* from binding to a controller. * from binding to a controller.
*/ */
the_device = dev; the_device = dev;
return 0; return 0;
enomem3:
put_dev (dev);
enomem2:
dput (d);
enomem1:
iput (inode);
enomem0:
return -ENOMEM;
} }
/* "mount -t gadgetfs path /dev/gadget" ends up here */ /* "mount -t gadgetfs path /dev/gadget" ends up here */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment