diff options
author | Alexey Klimov <klimov.linux@gmail.com> | 2016-08-07 21:34:46 -0400 |
---|---|---|
committer | Johan Hovold <johan@kernel.org> | 2016-08-08 07:41:17 -0400 |
commit | 647024a7df36014bbc4479d92d88e6b77c0afcf6 (patch) | |
tree | 62e8a15ea2e8180743bb43af45aedb0f6ed19693 /drivers/usb | |
parent | 01d7956b58e644ea0d2e8d9340c5727a8fc39d70 (diff) |
USB: serial: fix memleak in driver-registration error path
udriver struct allocated by kzalloc() will not be freed
if usb_register() and next calls fail. This patch fixes this
by adding one more step with kfree(udriver) in error path.
Signed-off-by: Alexey Klimov <klimov.linux@gmail.com>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Johan Hovold <johan@kernel.org>
Diffstat (limited to 'drivers/usb')
-rw-r--r-- | drivers/usb/serial/usb-serial.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c index b1b9bac44016..d213cf44a7e4 100644 --- a/drivers/usb/serial/usb-serial.c +++ b/drivers/usb/serial/usb-serial.c | |||
@@ -1433,7 +1433,7 @@ int usb_serial_register_drivers(struct usb_serial_driver *const serial_drivers[] | |||
1433 | 1433 | ||
1434 | rc = usb_register(udriver); | 1434 | rc = usb_register(udriver); |
1435 | if (rc) | 1435 | if (rc) |
1436 | return rc; | 1436 | goto failed_usb_register; |
1437 | 1437 | ||
1438 | for (sd = serial_drivers; *sd; ++sd) { | 1438 | for (sd = serial_drivers; *sd; ++sd) { |
1439 | (*sd)->usb_driver = udriver; | 1439 | (*sd)->usb_driver = udriver; |
@@ -1451,6 +1451,8 @@ int usb_serial_register_drivers(struct usb_serial_driver *const serial_drivers[] | |||
1451 | while (sd-- > serial_drivers) | 1451 | while (sd-- > serial_drivers) |
1452 | usb_serial_deregister(*sd); | 1452 | usb_serial_deregister(*sd); |
1453 | usb_deregister(udriver); | 1453 | usb_deregister(udriver); |
1454 | failed_usb_register: | ||
1455 | kfree(udriver); | ||
1454 | return rc; | 1456 | return rc; |
1455 | } | 1457 | } |
1456 | EXPORT_SYMBOL_GPL(usb_serial_register_drivers); | 1458 | EXPORT_SYMBOL_GPL(usb_serial_register_drivers); |