LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Marc Kleine-Budde <mkl@pengutronix.de>
To: "Ahmed S. Darwish" <darwish.07@gmail.com>
Cc: Olivier Sobrie <olivier@sobrie.be>,
Oliver Hartkopp <socketcan@hartkopp.net>,
Wolfgang Grandegger <wg@grandegger.com>,
Andri Yngvason <andri.yngvason@marel.com>,
Linux-CAN <linux-can@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v3 2/3] can: kvaser_usb: Utilize all possible tx URBs
Date: Thu, 12 Mar 2015 12:29:58 +0100 [thread overview]
Message-ID: <550178B6.4090503@pengutronix.de> (raw)
In-Reply-To: <20150312105211.GA21639@linux>
[-- Attachment #1: Type: text/plain, Size: 2207 bytes --]
On 03/12/2015 11:52 AM, Ahmed S. Darwish wrote:
>>> @@ -1881,7 +1891,7 @@ static int kvaser_usb_init_one(struct usb_interface *intf,
>>> if (err)
>>> return err;
>>>
>>> - netdev = alloc_candev(sizeof(*priv), MAX_TX_URBS);
>>> + netdev = alloc_candev(sizeof(*priv), dev->max_tx_urbs);
>>> if (!netdev) {
>>> dev_err(&intf->dev, "Cannot alloc candev\n");
>>> return -ENOMEM;
>>> @@ -1889,6 +1899,13 @@ static int kvaser_usb_init_one(struct usb_interface *intf,
>>>
>>> priv = netdev_priv(netdev);
>>>
>>> + priv->tx_contexts = kzalloc(dev->max_tx_urbs *
>>> + sizeof(*priv->tx_contexts), GFP_KERNEL);
>>> + if (!priv->tx_contexts) {
>>> + free_candev(netdev);
>>> + return -ENOMEM;
>>> + }
>>
>> I'm missing a free for the priv->tx_contexts. I see two options:
>>
>
> Correct. Should not have missed that.
>
>> 1) use devm_kzalloc(), or
>> 2) move struct kvaser_usb_tx_urb_context tx_contexts[]; to the end of
>> struct kvaser_usb_net_priv, see [1] for an example.
>>
>> Without further testing, I think the correct alloc for that case
>> would be:
>> alloc_candev(sizeof(*priv + dev->max_tx_urbs *
>> sizeof(struct kvaser_usb_tx_urb_context))
>>
>
> The first option looks better I guess. I'll have to check though
> if the resource handling done by devm_kmalloc() will work even
> if the probe() method fails with -ENODEV and the like...
devm does handle failing probe functions by design, while calling a
manual free() on devm allocated mem is a bug, which will cause a double
free or worse.
YMMV: for option 2 saves a mem allocation and a pointer deref for each
access of the context.
>> [1] http://stackoverflow.com/questions/2060974/dynamic-array-in-struct-c
> Thanks for the link. Didn't know that such a "hack" has gained
> official status by C99 :-)
:D and I think it's used in the kernel.
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: 819 bytes --]
next prev parent reply other threads:[~2015-03-12 11:30 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-26 15:20 [PATCH 1/5] can: kvaser_usb: Avoid double free on URB submission failures Ahmed S. Darwish
2015-02-26 15:22 ` [PATCH 2/5] can: kvaser_usb: Read all messages in a bulk-in URB buffer Ahmed S. Darwish
2015-02-26 15:24 ` [PATCH 3/5] can: kvaser_usb: Utilize all possible tx URBs Ahmed S. Darwish
2015-02-26 15:25 ` [PATCH 4/5] can: kvaser_usb: Use can-dev unregistration mechanism Ahmed S. Darwish
2015-02-26 15:29 ` [PATCH 5/5] can: kvaser_usb: Fix tx queue start/stop race conditions Ahmed S. Darwish
2015-03-14 14:26 ` [PATCH 2/5] can: kvaser_usb: Read all messages in a bulk-in URB buffer Marc Kleine-Budde
2015-03-04 9:15 ` [PATCH 1/5] can: kvaser_usb: Avoid double free on URB submission failures Marc Kleine-Budde
2015-03-09 12:32 ` Ahmed S. Darwish
2015-03-09 12:56 ` Marc Kleine-Budde
2015-03-11 15:23 ` [PATCH v2 1/3] can: kvaser_usb: Fix tx queue start/stop race conditions Ahmed S. Darwish
2015-03-11 15:28 ` [PATCH v2 2/3] can: kvaser_usb: Utilize all possible tx URBs Ahmed S. Darwish
2015-03-11 15:30 ` [PATCH v2 3/3] can: kvaser_usb: Use can-dev unregistration mechanism Ahmed S. Darwish
2015-03-11 15:36 ` [PATCH v2 1/3] can: kvaser_usb: Fix tx queue start/stop race conditions Marc Kleine-Budde
2015-03-11 15:57 ` Ahmed S. Darwish
2015-03-11 17:37 ` [PATCH v3 " Ahmed S. Darwish
2015-03-11 17:39 ` [PATCH v3 2/3] can: kvaser_usb: Utilize all possible tx URBs Ahmed S. Darwish
2015-03-11 17:39 ` [PATCH v3 3/3] can: kvaser_usb: Use can-dev unregistration mechanism Ahmed S. Darwish
2015-03-11 21:53 ` [PATCH v3 2/3] can: kvaser_usb: Utilize all possible tx URBs Marc Kleine-Budde
2015-03-12 10:52 ` Ahmed S. Darwish
2015-03-12 11:29 ` Marc Kleine-Budde [this message]
2015-03-11 21:43 ` [PATCH v3 1/3] can: kvaser_usb: Fix tx queue start/stop race conditions Marc Kleine-Budde
2015-03-12 19:30 ` Ahmed S. Darwish
2015-03-14 13:02 ` [PATCH v4 " Ahmed S. Darwish
2015-03-14 13:09 ` [PATCH v4 2/3] can: kvaser_usb: Utilize all possible tx URBs Ahmed S. Darwish
2015-03-14 13:11 ` [PATCH v4 3/3] can: kvaser_usb: Use can-dev unregistration mechanism Ahmed S. Darwish
2015-03-14 15:26 ` Marc Kleine-Budde
2015-03-14 15:41 ` Ahmed S. Darwish
2015-03-14 15:55 ` Marc Kleine-Budde
2015-03-14 16:06 ` Ahmed S. Darwish
2015-03-14 13:41 ` [PATCH v4 1/3] can: kvaser_usb: Fix tx queue start/stop race conditions Marc Kleine-Budde
2015-03-14 14:38 ` Ahmed S. Darwish
2015-03-14 14:58 ` Marc Kleine-Budde
2015-03-14 15:19 ` Ahmed S. Darwish
2015-03-15 15:03 ` [PATCH v5 1/2] can: kvaser_usb: Comply with firmware max tx URBs value Ahmed S. Darwish
2015-03-15 15:10 ` [PATCH v5 2/2] can: kvaser_usb: Fix sparse warning __le16 degrades to integer Ahmed S. Darwish
2015-03-15 18:08 ` [PATCH v5 1/2] can: kvaser_usb: Comply with firmware max tx URBs value Marc Kleine-Budde
2015-03-16 12:16 ` Ahmed S. Darwish
2015-03-16 12:56 ` 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=550178B6.4090503@pengutronix.de \
--to=mkl@pengutronix.de \
--cc=andri.yngvason@marel.com \
--cc=darwish.07@gmail.com \
--cc=linux-can@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=olivier@sobrie.be \
--cc=socketcan@hartkopp.net \
--cc=wg@grandegger.com \
--subject='Re: [PATCH v3 2/3] can: kvaser_usb: Utilize all possible tx URBs' \
/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
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).