public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] USB: serial: fix memleak on error path in usb-serial
@ 2016-08-08  1:34 Alexey Klimov
  2016-08-08  1:41 ` Alan Stern
  2016-08-08 11:48 ` Johan Hovold
  0 siblings, 2 replies; 3+ messages in thread
From: Alexey Klimov @ 2016-08-08  1:34 UTC (permalink / raw)
  To: linux-usb; +Cc: johan, stern, gregkh, klimov.linux, linux-kernel

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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] USB: serial: fix memleak on error path in usb-serial
  2016-08-08  1:34 [PATCH] USB: serial: fix memleak on error path in usb-serial Alexey Klimov
@ 2016-08-08  1:41 ` Alan Stern
  2016-08-08 11:48 ` Johan Hovold
  1 sibling, 0 replies; 3+ messages in thread
From: Alan Stern @ 2016-08-08  1:41 UTC (permalink / raw)
  To: Alexey Klimov; +Cc: linux-usb, johan, gregkh, linux-kernel

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] USB: serial: fix memleak on error path in usb-serial
  2016-08-08  1:34 [PATCH] USB: serial: fix memleak on error path in usb-serial Alexey Klimov
  2016-08-08  1:41 ` Alan Stern
@ 2016-08-08 11:48 ` Johan Hovold
  1 sibling, 0 replies; 3+ messages in thread
From: Johan Hovold @ 2016-08-08 11:48 UTC (permalink / raw)
  To: Alexey Klimov; +Cc: linux-usb, johan, stern, gregkh, linux-kernel

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-08-08 11:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-08-08  1:34 [PATCH] USB: serial: fix memleak on error path in usb-serial Alexey Klimov
2016-08-08  1:41 ` Alan Stern
2016-08-08 11:48 ` Johan Hovold

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox