diff options
author | Johan Hovold <jhovold@gmail.com> | 2012-10-25 10:29:17 +0200 |
---|---|---|
committer | Ben Hutchings <ben@decadent.org.uk> | 2012-10-30 23:27:02 +0000 |
commit | 05d84306250bff450f5f4b9da3f46125ba46c9d1 (patch) | |
tree | f265f1cdc6234a3840673842ac122141d320cfca | |
parent | ce834659bc2bbf9a89159bdd8a5a99f21e8f15a3 (diff) | |
download | lwn-05d84306250bff450f5f4b9da3f46125ba46c9d1.tar.gz lwn-05d84306250bff450f5f4b9da3f46125ba46c9d1.zip |
USB: sierra: fix memory leak in attach error path
commit 7e41f9bcdd2e813ea2a3c40db291d87ea06b559f upstream.
Make sure port private data is deallocated on errors in attach.
Signed-off-by: Johan Hovold <jhovold@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
-rw-r--r-- | drivers/usb/serial/sierra.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/drivers/usb/serial/sierra.c b/drivers/usb/serial/sierra.c index 7041d77f49b5..ade43976da18 100644 --- a/drivers/usb/serial/sierra.c +++ b/drivers/usb/serial/sierra.c @@ -937,7 +937,7 @@ static int sierra_startup(struct usb_serial *serial) dev_dbg(&port->dev, "%s: kmalloc for " "sierra_port_private (%d) failed!\n", __func__, i); - return -ENOMEM; + goto err; } spin_lock_init(&portdata->lock); init_usb_anchor(&portdata->active); @@ -974,6 +974,13 @@ static int sierra_startup(struct usb_serial *serial) } return 0; +err: + for (--i; i >= 0; --i) { + portdata = usb_get_serial_port_data(serial->port[i]); + kfree(portdata); + } + + return -ENOMEM; } static void sierra_release(struct usb_serial *serial) |