[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <5416A65D.6010500@pengutronix.de>
Date: Mon, 15 Sep 2014 10:42:05 +0200
From: Marc Kleine-Budde <mkl@...gutronix.de>
To: David Laight <David.Laight@...LAB.COM>,
'Rickard Strandqvist' <rickard_strandqvist@...ctrumdigital.se>,
Wolfgang Grandegger <wg@...ndegger.com>
CC: Oliver Hartkopp <socketcan@...tkopp.net>,
Stephane Grosjean <s.grosjean@...k-system.com>,
Alexey Khoroshilov <khoroshilov@...ras.ru>,
"Christopher R. Baker" <cbaker@....ri.cmu.edu>,
"linux-can@...r.kernel.org" <linux-can@...r.kernel.org>,
"netdev@...r.kernel.org" <netdev@...r.kernel.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] net: can: usb: peak_usb: pcan_usb_core.c: Cleaning up
missing null-terminate in conjunction with strncpy
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 |
Download attachment "signature.asc" of type "application/pgp-signature" (182 bytes)
Powered by blists - more mailing lists