Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1457508 > unrolled thread
| Started by | Alexey Klimov <klimov.linux@gmail.com> |
|---|---|
| First post | 2016-08-08 03:40 +0200 |
| Last post | 2016-08-08 13:50 +0200 |
| Articles | 3 — 3 participants |
Back to article view | Back to linux.kernel
[PATCH] USB: serial: fix memleak on error path in usb-serial Alexey Klimov <klimov.linux@gmail.com> - 2016-08-08 03:40 +0200
Re: [PATCH] USB: serial: fix memleak on error path in usb-serial Alan Stern <stern@rowland.harvard.edu> - 2016-08-08 03:50 +0200
Re: [PATCH] USB: serial: fix memleak on error path in usb-serial Johan Hovold <johan@kernel.org> - 2016-08-08 13:50 +0200
| From | Alexey Klimov <klimov.linux@gmail.com> |
|---|---|
| Date | 2016-08-08 03:40 +0200 |
| Subject | [PATCH] USB: serial: fix memleak on error path in usb-serial |
| Message-ID | <s3HHP-34Z-5@gated-at.bofh.it> |
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.
Cc: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Alexey Klimov <klimov.linux@gmail.com>
---
drivers/usb/serial/usb-serial.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index b1b9bac..d213cf4 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[]
rc = usb_register(udriver);
if (rc)
- return rc;
+ goto failed_usb_register;
for (sd = serial_drivers; *sd; ++sd) {
(*sd)->usb_driver = udriver;
@@ -1451,6 +1451,8 @@ int usb_serial_register_drivers(struct usb_serial_driver *const serial_drivers[]
while (sd-- > serial_drivers)
usb_serial_deregister(*sd);
usb_deregister(udriver);
+failed_usb_register:
+ kfree(udriver);
return rc;
}
EXPORT_SYMBOL_GPL(usb_serial_register_drivers);
--
2.5.0
[toc] | [next] | [standalone]
| From | Alan Stern <stern@rowland.harvard.edu> |
|---|---|
| Date | 2016-08-08 03:50 +0200 |
| Message-ID | <s3HRv-38T-1@gated-at.bofh.it> |
| In reply to | #1457508 |
On Mon, 8 Aug 2016, Alexey Klimov wrote:
> 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.
>
> Cc: Alan Stern <stern@rowland.harvard.edu>
> Signed-off-by: Alexey Klimov <klimov.linux@gmail.com>
> ---
> drivers/usb/serial/usb-serial.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
> index b1b9bac..d213cf4 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[]
>
> rc = usb_register(udriver);
> if (rc)
> - return rc;
> + goto failed_usb_register;
>
> for (sd = serial_drivers; *sd; ++sd) {
> (*sd)->usb_driver = udriver;
> @@ -1451,6 +1451,8 @@ int usb_serial_register_drivers(struct usb_serial_driver *const serial_drivers[]
> while (sd-- > serial_drivers)
> usb_serial_deregister(*sd);
> usb_deregister(udriver);
> +failed_usb_register:
> + kfree(udriver);
> return rc;
> }
> EXPORT_SYMBOL_GPL(usb_serial_register_drivers);
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Pretty careless of me... Thanks for fixing this.
Alan Stern
[toc] | [prev] | [next] | [standalone]
| From | Johan Hovold <johan@kernel.org> |
|---|---|
| Date | 2016-08-08 13:50 +0200 |
| Message-ID | <s3Re9-Tb-1@gated-at.bofh.it> |
| In reply to | #1457508 |
On Mon, Aug 08, 2016 at 02:34:46AM +0100, Alexey Klimov wrote: > 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. > > Cc: Alan Stern <stern@rowland.harvard.edu> > Signed-off-by: Alexey Klimov <klimov.linux@gmail.com> Now applied, thanks. Johan
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web