Commit 9269db2d authored by Alexey Klimov's avatar Alexey Klimov Committed by Ben Hutchings

USB: serial: fix memleak in driver-registration error path

commit 647024a7 upstream.

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: default avatarAlexey Klimov <klimov.linux@gmail.com>
Acked-by: default avatarAlan Stern <stern@rowland.harvard.edu>
Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
parent ab65fc77
...@@ -1416,7 +1416,7 @@ int usb_serial_register_drivers(struct usb_serial_driver *const serial_drivers[] ...@@ -1416,7 +1416,7 @@ int usb_serial_register_drivers(struct usb_serial_driver *const serial_drivers[]
rc = usb_register(udriver); rc = usb_register(udriver);
if (rc) if (rc)
return rc; goto failed_usb_register;
for (sd = serial_drivers; *sd; ++sd) { for (sd = serial_drivers; *sd; ++sd) {
(*sd)->usb_driver = udriver; (*sd)->usb_driver = udriver;
...@@ -1434,6 +1434,8 @@ int usb_serial_register_drivers(struct usb_serial_driver *const serial_drivers[] ...@@ -1434,6 +1434,8 @@ int usb_serial_register_drivers(struct usb_serial_driver *const serial_drivers[]
while (sd-- > serial_drivers) while (sd-- > serial_drivers)
usb_serial_deregister(*sd); usb_serial_deregister(*sd);
usb_deregister(udriver); usb_deregister(udriver);
failed_usb_register:
kfree(udriver);
return rc; return rc;
} }
EXPORT_SYMBOL_GPL(usb_serial_register_drivers); EXPORT_SYMBOL_GPL(usb_serial_register_drivers);
......
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