From: Marc Kleine-Budde <mkl@pengutronix.de>
To: Alexey Khoroshilov <khoroshilov@ispras.ru>
Cc: Wolfgang Grandegger <wg@grandegger.com>,
linux-can@vger.kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, ldv-project@linuxtesting.org,
"s.grosjean@peak-system.com" <s.grosjean@peak-system.com>
Subject: Re: [PATCH] can: pcan_usb_core: fix memory leak on failure paths in peak_usb_start()
Date: Thu, 05 Sep 2013 11:33:58 +0200 [thread overview]
Message-ID: <52285006.3080303@pengutronix.de> (raw)
In-Reply-To: <1378331169-26285-1-git-send-email-khoroshilov@ispras.ru>
[-- 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 --]
next prev parent reply other threads:[~2013-09-05 9:33 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=52285006.3080303@pengutronix.de \
--to=mkl@pengutronix.de \
--cc=khoroshilov@ispras.ru \
--cc=ldv-project@linuxtesting.org \
--cc=linux-can@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=s.grosjean@peak-system.com \
--cc=wg@grandegger.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).