netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] can: pcan_usb_core: fix memory leak on failure paths in peak_usb_start()
@ 2013-09-04 21:46 Alexey Khoroshilov
  2013-09-05  9:33 ` Marc Kleine-Budde
  0 siblings, 1 reply; 7+ messages in thread
From: Alexey Khoroshilov @ 2013-09-04 21:46 UTC (permalink / raw)
  To: Marc Kleine-Budde
  Cc: Alexey Khoroshilov, Wolfgang Grandegger, linux-can, netdev,
	linux-kernel, ldv-project

Tx and rx urbs are not deallocated if something goes wrong in peak_usb_start().
The patch fixes error handling to deallocate all the resources.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
---
 drivers/net/can/usb/peak_usb/pcan_usb_core.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_core.c b/drivers/net/can/usb/peak_usb/pcan_usb_core.c
index a0f647f..0b7a4c3 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb_core.c
+++ b/drivers/net/can/usb/peak_usb/pcan_usb_core.c
@@ -463,7 +463,7 @@ static int peak_usb_start(struct peak_usb_device *dev)
 	if (i < PCAN_USB_MAX_TX_URBS) {
 		if (i == 0) {
 			netdev_err(netdev, "couldn't setup any tx URB\n");
-			return err;
+			goto err_tx;
 		}
 
 		netdev_warn(netdev, "tx performance may be slow\n");
@@ -472,7 +472,7 @@ static int peak_usb_start(struct peak_usb_device *dev)
 	if (dev->adapter->dev_start) {
 		err = dev->adapter->dev_start(dev);
 		if (err)
-			goto failed;
+			goto err_adapter;
 	}
 
 	dev->state |= PCAN_USB_STATE_STARTED;
@@ -481,19 +481,26 @@ static int peak_usb_start(struct peak_usb_device *dev)
 	if (dev->adapter->dev_set_bus) {
 		err = dev->adapter->dev_set_bus(dev, 1);
 		if (err)
-			goto failed;
+			goto err_adapter;
 	}
 
 	dev->can.state = CAN_STATE_ERROR_ACTIVE;
 
 	return 0;
 
-failed:
+err_adapter:
 	if (err == -ENODEV)
 		netif_device_detach(dev->netdev);
 
 	netdev_warn(netdev, "couldn't submit control: %d\n", err);
 
+	for (i = 0; i < PCAN_USB_MAX_TX_URBS; i++) {
+		usb_free_urb(dev->tx_contexts[i].urb);
+		dev->tx_contexts[i].urb = NULL;
+	}
+err_tx:
+	usb_kill_anchored_urbs(&dev->rx_submitted);
+
 	return err;
 }
 
-- 
1.8.1.2


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

* Re: [PATCH] can: pcan_usb_core: fix memory leak on failure paths in peak_usb_start()
  2013-09-04 21:46 [PATCH] can: pcan_usb_core: fix memory leak on failure paths in peak_usb_start() Alexey Khoroshilov
@ 2013-09-05  9:33 ` Marc Kleine-Budde
  2013-09-06  9:03   ` Marc Kleine-Budde
  0 siblings, 1 reply; 7+ messages in thread
From: Marc Kleine-Budde @ 2013-09-05  9:33 UTC (permalink / raw)
  To: Alexey Khoroshilov
  Cc: Wolfgang Grandegger, linux-can, netdev, linux-kernel, ldv-project,
	s.grosjean@peak-system.com

[-- Attachment #1: Type: text/plain, Size: 2417 bytes --]

Added Stephane to Cc.

On 09/04/2013 11:46 PM, Alexey Khoroshilov wrote:
> Tx and rx urbs are not deallocated if something goes wrong in peak_usb_start().
> The patch fixes error handling to deallocate all the resources.
> 
> Found by Linux Driver Verification project (linuxtesting.org).
> 
> Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>

Stephane, can you have a look at the patch and give your Acked-by.

Looks good to me.

tnx,
Marc
> ---
>  drivers/net/can/usb/peak_usb/pcan_usb_core.c | 15 +++++++++++----
>  1 file changed, 11 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_core.c b/drivers/net/can/usb/peak_usb/pcan_usb_core.c
> index a0f647f..0b7a4c3 100644
> --- a/drivers/net/can/usb/peak_usb/pcan_usb_core.c
> +++ b/drivers/net/can/usb/peak_usb/pcan_usb_core.c
> @@ -463,7 +463,7 @@ static int peak_usb_start(struct peak_usb_device *dev)
>  	if (i < PCAN_USB_MAX_TX_URBS) {
>  		if (i == 0) {
>  			netdev_err(netdev, "couldn't setup any tx URB\n");
> -			return err;
> +			goto err_tx;
>  		}
>  
>  		netdev_warn(netdev, "tx performance may be slow\n");
> @@ -472,7 +472,7 @@ static int peak_usb_start(struct peak_usb_device *dev)
>  	if (dev->adapter->dev_start) {
>  		err = dev->adapter->dev_start(dev);
>  		if (err)
> -			goto failed;
> +			goto err_adapter;
>  	}
>  
>  	dev->state |= PCAN_USB_STATE_STARTED;
> @@ -481,19 +481,26 @@ static int peak_usb_start(struct peak_usb_device *dev)
>  	if (dev->adapter->dev_set_bus) {
>  		err = dev->adapter->dev_set_bus(dev, 1);
>  		if (err)
> -			goto failed;
> +			goto err_adapter;
>  	}
>  
>  	dev->can.state = CAN_STATE_ERROR_ACTIVE;
>  
>  	return 0;
>  
> -failed:
> +err_adapter:
>  	if (err == -ENODEV)
>  		netif_device_detach(dev->netdev);
>  
>  	netdev_warn(netdev, "couldn't submit control: %d\n", err);
>  
> +	for (i = 0; i < PCAN_USB_MAX_TX_URBS; i++) {
> +		usb_free_urb(dev->tx_contexts[i].urb);
> +		dev->tx_contexts[i].urb = NULL;
> +	}
> +err_tx:
> +	usb_kill_anchored_urbs(&dev->rx_submitted);
> +
>  	return err;
>  }
>  
> 


-- 
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 259 bytes --]

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

* [PATCH] can: pcan_usb_core: fix memory leak on failure paths in peak_usb_start()
@ 2013-09-06  6:52 Stephane Grosjean
  2013-09-06  6:56 ` Marc Kleine-Budde
  0 siblings, 1 reply; 7+ messages in thread
From: Stephane Grosjean @ 2013-09-06  6:52 UTC (permalink / raw)
  To: Marc Kleine-Budde
  Cc: Alexey Khoroshilov, Wolfgang Grandegger, linux-can, netdev,
	linux-kernel, ldv-project

Tx and rx urbs are not deallocated if something goes wrong in peak_usb_start().
The patch fixes error handling to deallocate all the resources.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
Acked-by: Stephane Grosjean <s.grosjean@peak-system.com>
---
 drivers/net/can/usb/peak_usb/pcan_usb_core.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_core.c b/drivers/net/can/usb/peak_usb/pcan_usb_core.c
index a0f647f..0b7a4c3 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb_core.c
+++ b/drivers/net/can/usb/peak_usb/pcan_usb_core.c
@@ -463,7 +463,7 @@ static int peak_usb_start(struct peak_usb_device *dev)
     if (i < PCAN_USB_MAX_TX_URBS) {
         if (i == 0) {
             netdev_err(netdev, "couldn't setup any tx URB\n");
-            return err;
+            goto err_tx;
         }
 
         netdev_warn(netdev, "tx performance may be slow\n");
@@ -472,7 +472,7 @@ static int peak_usb_start(struct peak_usb_device *dev)
     if (dev->adapter->dev_start) {
         err = dev->adapter->dev_start(dev);
         if (err)
-            goto failed;
+            goto err_adapter;
     }
 
     dev->state |= PCAN_USB_STATE_STARTED;
@@ -481,19 +481,26 @@ static int peak_usb_start(struct peak_usb_device *dev)
     if (dev->adapter->dev_set_bus) {
         err = dev->adapter->dev_set_bus(dev, 1);
         if (err)
-            goto failed;
+            goto err_adapter;
     }
 
     dev->can.state = CAN_STATE_ERROR_ACTIVE;
 
     return 0;
 
-failed:
+err_adapter:
     if (err == -ENODEV)
         netif_device_detach(dev->netdev);
 
     netdev_warn(netdev, "couldn't submit control: %d\n", err);
 
+    for (i = 0; i < PCAN_USB_MAX_TX_URBS; i++) {
+        usb_free_urb(dev->tx_contexts[i].urb);
+        dev->tx_contexts[i].urb = NULL;
+    }
+err_tx:
+    usb_kill_anchored_urbs(&dev->rx_submitted);
+
     return err;
 }
 
--
1.8.1.2

--
To unsubscribe from this list: send the line "unsubscribe linux-can" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
PEAK-System Technik GmbH, Otto-Roehm-Strasse 69, D-64293 Darmstadt 
Geschaeftsleitung: A.Gach/U.Wilhelm,St.Nr.:007/241/13586 FA Darmstadt 
HRB-9183 Darmstadt, Ust.IdNr.:DE 202220078, WEE-Reg.-Nr.: DE39305391 
Tel.+49 (0)6151-817320 / Fax:+49 (0)6151-817329, info@peak-system.com

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

* Re: [PATCH] can: pcan_usb_core: fix memory leak on failure paths in peak_usb_start()
  2013-09-06  6:52 Stephane Grosjean
@ 2013-09-06  6:56 ` Marc Kleine-Budde
  2013-09-06  6:58   ` Stephane Grosjean
  0 siblings, 1 reply; 7+ messages in thread
From: Marc Kleine-Budde @ 2013-09-06  6:56 UTC (permalink / raw)
  To: Stephane Grosjean
  Cc: Alexey Khoroshilov, Wolfgang Grandegger, linux-can, netdev,
	linux-kernel, ldv-project

[-- Attachment #1: Type: text/plain, Size: 765 bytes --]

On 09/06/2013 08:52 AM, Stephane Grosjean wrote:
> Tx and rx urbs are not deallocated if something goes wrong in peak_usb_start().
> The patch fixes error handling to deallocate all the resources.
> 
> Found by Linux Driver Verification project (linuxtesting.org).
> 
> Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
> Acked-by: Stephane Grosjean <s.grosjean@peak-system.com>

Tnx,
Marc

BTW: A simply reply to the original patch with your Acked-by is sufficient.

-- 
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 259 bytes --]

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

* Re: [PATCH] can: pcan_usb_core: fix memory leak on failure paths in peak_usb_start()
  2013-09-06  6:56 ` Marc Kleine-Budde
@ 2013-09-06  6:58   ` Stephane Grosjean
  0 siblings, 0 replies; 7+ messages in thread
From: Stephane Grosjean @ 2013-09-06  6:58 UTC (permalink / raw)
  To: Marc Kleine-Budde
  Cc: Alexey Khoroshilov, Wolfgang Grandegger, linux-can, netdev,
	linux-kernel, ldv-project


Le 06/09/2013 08:56, Marc Kleine-Budde a écrit :
> On 09/06/2013 08:52 AM, Stephane Grosjean wrote:
>> Tx and rx urbs are not deallocated if something goes wrong in peak_usb_start().
>> The patch fixes error handling to deallocate all the resources.
>>
>> Found by Linux Driver Verification project (linuxtesting.org).
>>
>> Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
>> Acked-by: Stephane Grosjean <s.grosjean@peak-system.com>
> Tnx,
> Marc
>
> BTW: A simply reply to the original patch with your Acked-by is sufficient.
>

Ok, thx Marc. I keep it in mind for the next time (if any ;-))

Stéphane
--
PEAK-System Technik GmbH, Otto-Roehm-Strasse 69, D-64293 Darmstadt 
Geschaeftsleitung: A.Gach/U.Wilhelm,St.Nr.:007/241/13586 FA Darmstadt 
HRB-9183 Darmstadt, Ust.IdNr.:DE 202220078, WEE-Reg.-Nr.: DE39305391 
Tel.+49 (0)6151-817320 / Fax:+49 (0)6151-817329, info@peak-system.com

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

* Re: [PATCH] can: pcan_usb_core: fix memory leak on failure paths in peak_usb_start()
  2013-09-05  9:33 ` Marc Kleine-Budde
@ 2013-09-06  9:03   ` Marc Kleine-Budde
  0 siblings, 0 replies; 7+ messages in thread
From: Marc Kleine-Budde @ 2013-09-06  9:03 UTC (permalink / raw)
  To: Alexey Khoroshilov
  Cc: Wolfgang Grandegger, linux-can, netdev, linux-kernel, ldv-project,
	s.grosjean@peak-system.com

[-- Attachment #1: Type: text/plain, Size: 868 bytes --]

On 09/05/2013 11:33 AM, Marc Kleine-Budde wrote:
> Added Stephane to Cc.
> 
> On 09/04/2013 11:46 PM, Alexey Khoroshilov wrote:
>> Tx and rx urbs are not deallocated if something goes wrong in peak_usb_start().
>> The patch fixes error handling to deallocate all the resources.
>>
>> Found by Linux Driver Verification project (linuxtesting.org).
>>
>> Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
> 
> Stephane, can you have a look at the patch and give your Acked-by.
> 
> Looks good to me.

Applied with Stephane's Acked-by to can/fixes-for-3.12.

Tnx,
Marc
-- 
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 259 bytes --]

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

* [PATCH] can: pcan_usb_core: fix memory leak on failure paths in peak_usb_start()
  2013-09-21 14:08 pull-request: can 2013-09-21 Marc Kleine-Budde
@ 2013-09-21 14:08 ` Marc Kleine-Budde
  0 siblings, 0 replies; 7+ messages in thread
From: Marc Kleine-Budde @ 2013-09-21 14:08 UTC (permalink / raw)
  To: netdev; +Cc: davem, linux-can, kernel, Alexey Khoroshilov, Marc Kleine-Budde

From: Alexey Khoroshilov <khoroshilov@ispras.ru>

Tx and rx urbs are not deallocated if something goes wrong in peak_usb_start().
The patch fixes error handling to deallocate all the resources.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
Acked-by: Stephane Grosjean <s.grosjean@peak-system.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/usb/peak_usb/pcan_usb_core.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_core.c b/drivers/net/can/usb/peak_usb/pcan_usb_core.c
index a0f647f..0b7a4c3 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb_core.c
+++ b/drivers/net/can/usb/peak_usb/pcan_usb_core.c
@@ -463,7 +463,7 @@ static int peak_usb_start(struct peak_usb_device *dev)
 	if (i < PCAN_USB_MAX_TX_URBS) {
 		if (i == 0) {
 			netdev_err(netdev, "couldn't setup any tx URB\n");
-			return err;
+			goto err_tx;
 		}
 
 		netdev_warn(netdev, "tx performance may be slow\n");
@@ -472,7 +472,7 @@ static int peak_usb_start(struct peak_usb_device *dev)
 	if (dev->adapter->dev_start) {
 		err = dev->adapter->dev_start(dev);
 		if (err)
-			goto failed;
+			goto err_adapter;
 	}
 
 	dev->state |= PCAN_USB_STATE_STARTED;
@@ -481,19 +481,26 @@ static int peak_usb_start(struct peak_usb_device *dev)
 	if (dev->adapter->dev_set_bus) {
 		err = dev->adapter->dev_set_bus(dev, 1);
 		if (err)
-			goto failed;
+			goto err_adapter;
 	}
 
 	dev->can.state = CAN_STATE_ERROR_ACTIVE;
 
 	return 0;
 
-failed:
+err_adapter:
 	if (err == -ENODEV)
 		netif_device_detach(dev->netdev);
 
 	netdev_warn(netdev, "couldn't submit control: %d\n", err);
 
+	for (i = 0; i < PCAN_USB_MAX_TX_URBS; i++) {
+		usb_free_urb(dev->tx_contexts[i].urb);
+		dev->tx_contexts[i].urb = NULL;
+	}
+err_tx:
+	usb_kill_anchored_urbs(&dev->rx_submitted);
+
 	return err;
 }
 
-- 
1.8.4.rc3

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

end of thread, other threads:[~2013-09-21 14:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-04 21:46 [PATCH] can: pcan_usb_core: fix memory leak on failure paths in peak_usb_start() Alexey Khoroshilov
2013-09-05  9:33 ` Marc Kleine-Budde
2013-09-06  9:03   ` Marc Kleine-Budde
  -- strict thread matches above, loose matches on Subject: below --
2013-09-06  6:52 Stephane Grosjean
2013-09-06  6:56 ` Marc Kleine-Budde
2013-09-06  6:58   ` Stephane Grosjean
2013-09-21 14:08 pull-request: can 2013-09-21 Marc Kleine-Budde
2013-09-21 14:08 ` [PATCH] can: pcan_usb_core: fix memory leak on failure paths in peak_usb_start() Marc Kleine-Budde

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).