From: Marc Kleine-Budde <mkl@pengutronix.de>
To: David Laight <David.Laight@ACULAB.COM>,
'Rickard Strandqvist' <rickard_strandqvist@spectrumdigital.se>,
Wolfgang Grandegger <wg@grandegger.com>
Cc: Oliver Hartkopp <socketcan@hartkopp.net>,
Stephane Grosjean <s.grosjean@peak-system.com>,
Alexey Khoroshilov <khoroshilov@ispras.ru>,
"Christopher R. Baker" <cbaker@rec.ri.cmu.edu>,
"linux-can@vger.kernel.org" <linux-can@vger.kernel.org>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] net: can: usb: peak_usb: pcan_usb_core.c: Cleaning up missing null-terminate in conjunction with strncpy
Date: Mon, 15 Sep 2014 10:42:05 +0200 [thread overview]
Message-ID: <5416A65D.6010500@pengutronix.de> (raw)
In-Reply-To: <063D6719AE5E284EB5DD2968C1650D6D17491F2B@AcuExch.aculab.com>
[-- Attachment #1: Type: text/plain, Size: 2053 bytes --]
On 09/15/2014 10:28 AM, David Laight wrote:
> From: Rickard Strandqvist
> ...
>> Replacing strncpy with strlcpy to avoid strings that lacks null terminate.
> ...
>> 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 644e6ab..d4fe8ac 100644
>> --- a/drivers/net/can/usb/peak_usb/pcan_usb_core.c
>> +++ b/drivers/net/can/usb/peak_usb/pcan_usb_core.c
>> @@ -830,7 +830,7 @@ static void peak_usb_disconnect(struct usb_interface *intf)
>> char name[IFNAMSIZ];
>>
>> dev->state &= ~PCAN_USB_STATE_CONNECTED;
>> - strncpy(name, netdev->name, IFNAMSIZ);
>> + strlcpy(name, netdev->name, IFNAMSIZ);
>>
>> unregister_netdev(netdev);
>> free_candev(netdev);
>
> Or:
> char name[sizeof netdev->name];
> memcpy(name, netdev->name, sizeof netdev->name);
I would be "sizeof(foo)" in kernel coding style, but let's have a look
at the original code:
struct net_device *netdev = dev->netdev;
char name[IFNAMSIZ];
dev->state &= ~PCAN_USB_STATE_CONNECTED;
strncpy(name, netdev->name, IFNAMSIZ);
unregister_netdev(netdev);
free_candev(netdev);
kfree(dev->cmd_buf);
dev->next_siblings = NULL;
if (dev->adapter->dev_free)
dev->adapter->dev_free(dev);
dev_info(&intf->dev, "%s removed\n", name);
I think it's save to use:
dev_info(&intf->dev, "%s removed\n", netdev_name(dev->netdev));
instead of doing the str?cpy() in the first place. But why not use:
netdev_info(dev->netdev, "removed\n");
Is the USB device information lost when using netdev_info()?
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: 181 bytes --]
next prev parent reply other threads:[~2014-09-15 8:42 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-14 17:31 [PATCH] net: can: usb: peak_usb: pcan_usb_core.c: Cleaning up missing null-terminate in conjunction with strncpy Rickard Strandqvist
2014-09-15 8:01 ` Stephane Grosjean
2014-09-15 8:28 ` David Laight
2014-09-15 8:42 ` Marc Kleine-Budde [this message]
2014-09-15 8:47 ` David Laight
2014-09-15 21:47 ` Rickard Strandqvist
2014-09-16 8:40 ` David Laight
2014-09-16 14:09 ` 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=5416A65D.6010500@pengutronix.de \
--to=mkl@pengutronix.de \
--cc=David.Laight@ACULAB.COM \
--cc=cbaker@rec.ri.cmu.edu \
--cc=khoroshilov@ispras.ru \
--cc=linux-can@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=rickard_strandqvist@spectrumdigital.se \
--cc=s.grosjean@peak-system.com \
--cc=socketcan@hartkopp.net \
--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).