diff mbox series

usb: move from strlcpy with unused retval to strscpy

Message ID 20220818210116.7517-1-wsa+renesas@sang-engineering.com (mailing list archive)
State Accepted
Commit b7db5733a5ace9acc1f3104c9050c5aa1363f13b
Headers show
Series usb: move from strlcpy with unused retval to strscpy | expand

Commit Message

Wolfram Sang Aug. 18, 2022, 9:01 p.m. UTC
Follow the advice of the below link and prefer 'strscpy' in this
subsystem. Conversion is 1:1 because the return value is not used.
Generated by a coccinelle script.

Link: https://lore.kernel.org/r/CAHk-=wgfRnXz0W3D37d01q3JFkr_i_uTL=V6A6G1oUZcprmknw@mail.gmail.com/
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
 drivers/usb/atm/usbatm.c               | 2 +-
 drivers/usb/core/devio.c               | 2 +-
 drivers/usb/gadget/function/f_fs.c     | 2 +-
 drivers/usb/gadget/function/f_uvc.c    | 2 +-
 drivers/usb/gadget/function/u_ether.c  | 8 ++++----
 drivers/usb/gadget/function/uvc_v4l2.c | 6 +++---
 drivers/usb/gadget/udc/omap_udc.c      | 2 +-
 drivers/usb/misc/usb251xb.c            | 6 +++---
 drivers/usb/storage/onetouch.c         | 2 +-
 drivers/usb/typec/tcpm/fusb302.c       | 2 +-
 drivers/usb/usbip/stub_main.c          | 2 +-
 11 files changed, 18 insertions(+), 18 deletions(-)

Comments

Shuah Khan Aug. 18, 2022, 9:17 p.m. UTC | #1
On 8/18/22 3:01 PM, Wolfram Sang wrote:
> Follow the advice of the below link and prefer 'strscpy' in this
> subsystem. Conversion is 1:1 because the return value is not used.
> Generated by a coccinelle script.
> 

Please elaborate and summarize why this change makses sense in the
commit log? It will be easier for reviewers - saves time checking
the link.

> Link: https://lore.kernel.org/r/CAHk-=wgfRnXz0W3D37d01q3JFkr_i_uTL=V6A6G1oUZcprmknw@mail.gmail.com/
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> ---
>   drivers/usb/atm/usbatm.c               | 2 +-
>   drivers/usb/core/devio.c               | 2 +-
>   drivers/usb/gadget/function/f_fs.c     | 2 +-
>   drivers/usb/gadget/function/f_uvc.c    | 2 +-
>   drivers/usb/gadget/function/u_ether.c  | 8 ++++----
>   drivers/usb/gadget/function/uvc_v4l2.c | 6 +++---
>   drivers/usb/gadget/udc/omap_udc.c      | 2 +-
>   drivers/usb/misc/usb251xb.c            | 6 +++---
>   drivers/usb/storage/onetouch.c         | 2 +-
>   drivers/usb/typec/tcpm/fusb302.c       | 2 +-
>   drivers/usb/usbip/stub_main.c          | 2 +-

I don't have any problems with the change itself. I would ike to
see the commit log clealrly state why this change is good. With
that for usbip change:

Acked-by: Shuah Khan <skhan@linuxfoundation.org>

thanks,
-- Shuah
Laurent Pinchart Aug. 18, 2022, 10:08 p.m. UTC | #2
Hi Wolfram,

Thank you for the patch.

On Thu, Aug 18, 2022 at 11:01:15PM +0200, Wolfram Sang wrote:
> Follow the advice of the below link and prefer 'strscpy' in this
> subsystem. Conversion is 1:1 because the return value is not used.
> Generated by a coccinelle script.
> 
> Link: https://lore.kernel.org/r/CAHk-=wgfRnXz0W3D37d01q3JFkr_i_uTL=V6A6G1oUZcprmknw@mail.gmail.com/
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>

> ---
>  drivers/usb/atm/usbatm.c               | 2 +-
>  drivers/usb/core/devio.c               | 2 +-
>  drivers/usb/gadget/function/f_fs.c     | 2 +-
>  drivers/usb/gadget/function/f_uvc.c    | 2 +-
>  drivers/usb/gadget/function/u_ether.c  | 8 ++++----
>  drivers/usb/gadget/function/uvc_v4l2.c | 6 +++---
>  drivers/usb/gadget/udc/omap_udc.c      | 2 +-
>  drivers/usb/misc/usb251xb.c            | 6 +++---
>  drivers/usb/storage/onetouch.c         | 2 +-
>  drivers/usb/typec/tcpm/fusb302.c       | 2 +-
>  drivers/usb/usbip/stub_main.c          | 2 +-
>  11 files changed, 18 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
> index 362217189ef3..1cdb8758ae01 100644
> --- a/drivers/usb/atm/usbatm.c
> +++ b/drivers/usb/atm/usbatm.c
> @@ -1026,7 +1026,7 @@ int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
>  	/* public fields */
>  
>  	instance->driver = driver;
> -	strlcpy(instance->driver_name, driver->driver_name,
> +	strscpy(instance->driver_name, driver->driver_name,
>  		sizeof(instance->driver_name));
>  
>  	instance->usb_dev = usb_dev;
> diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
> index b5b85bf80329..837f3e57f580 100644
> --- a/drivers/usb/core/devio.c
> +++ b/drivers/usb/core/devio.c
> @@ -1434,7 +1434,7 @@ static int proc_getdriver(struct usb_dev_state *ps, void __user *arg)
>  	if (!intf || !intf->dev.driver)
>  		ret = -ENODATA;
>  	else {
> -		strlcpy(gd.driver, intf->dev.driver->name,
> +		strscpy(gd.driver, intf->dev.driver->name,
>  				sizeof(gd.driver));
>  		ret = (copy_to_user(arg, &gd, sizeof(gd)) ? -EFAULT : 0);
>  	}
> diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
> index e0fa4b186ec6..98dc2291e9a1 100644
> --- a/drivers/usb/gadget/function/f_fs.c
> +++ b/drivers/usb/gadget/function/f_fs.c
> @@ -3700,7 +3700,7 @@ int ffs_name_dev(struct ffs_dev *dev, const char *name)
>  
>  	existing = _ffs_do_find_dev(name);
>  	if (!existing)
> -		strlcpy(dev->name, name, ARRAY_SIZE(dev->name));
> +		strscpy(dev->name, name, ARRAY_SIZE(dev->name));
>  	else if (existing != dev)
>  		ret = -EBUSY;
>  
> diff --git a/drivers/usb/gadget/function/f_uvc.c b/drivers/usb/gadget/function/f_uvc.c
> index 71669e0e4d00..f4f6cf75930b 100644
> --- a/drivers/usb/gadget/function/f_uvc.c
> +++ b/drivers/usb/gadget/function/f_uvc.c
> @@ -430,7 +430,7 @@ uvc_register_video(struct uvc_device *uvc)
>  	uvc->vdev.vfl_dir = VFL_DIR_TX;
>  	uvc->vdev.lock = &uvc->video.mutex;
>  	uvc->vdev.device_caps = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING;
> -	strlcpy(uvc->vdev.name, cdev->gadget->name, sizeof(uvc->vdev.name));
> +	strscpy(uvc->vdev.name, cdev->gadget->name, sizeof(uvc->vdev.name));
>  
>  	video_set_drvdata(&uvc->vdev, uvc);
>  
> diff --git a/drivers/usb/gadget/function/u_ether.c b/drivers/usb/gadget/function/u_ether.c
> index 7887def05dc2..e06022873df1 100644
> --- a/drivers/usb/gadget/function/u_ether.c
> +++ b/drivers/usb/gadget/function/u_ether.c
> @@ -144,10 +144,10 @@ static void eth_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *p)
>  {
>  	struct eth_dev *dev = netdev_priv(net);
>  
> -	strlcpy(p->driver, "g_ether", sizeof(p->driver));
> -	strlcpy(p->version, UETH__VERSION, sizeof(p->version));
> -	strlcpy(p->fw_version, dev->gadget->name, sizeof(p->fw_version));
> -	strlcpy(p->bus_info, dev_name(&dev->gadget->dev), sizeof(p->bus_info));
> +	strscpy(p->driver, "g_ether", sizeof(p->driver));
> +	strscpy(p->version, UETH__VERSION, sizeof(p->version));
> +	strscpy(p->fw_version, dev->gadget->name, sizeof(p->fw_version));
> +	strscpy(p->bus_info, dev_name(&dev->gadget->dev), sizeof(p->bus_info));
>  }
>  
>  /* REVISIT can also support:
> diff --git a/drivers/usb/gadget/function/uvc_v4l2.c b/drivers/usb/gadget/function/uvc_v4l2.c
> index fd8f73bb726d..511f106f9843 100644
> --- a/drivers/usb/gadget/function/uvc_v4l2.c
> +++ b/drivers/usb/gadget/function/uvc_v4l2.c
> @@ -67,9 +67,9 @@ uvc_v4l2_querycap(struct file *file, void *fh, struct v4l2_capability *cap)
>  	struct uvc_device *uvc = video_get_drvdata(vdev);
>  	struct usb_composite_dev *cdev = uvc->func.config->cdev;
>  
> -	strlcpy(cap->driver, "g_uvc", sizeof(cap->driver));
> -	strlcpy(cap->card, cdev->gadget->name, sizeof(cap->card));
> -	strlcpy(cap->bus_info, dev_name(&cdev->gadget->dev),
> +	strscpy(cap->driver, "g_uvc", sizeof(cap->driver));
> +	strscpy(cap->card, cdev->gadget->name, sizeof(cap->card));
> +	strscpy(cap->bus_info, dev_name(&cdev->gadget->dev),
>  		sizeof(cap->bus_info));
>  	return 0;
>  }
> diff --git a/drivers/usb/gadget/udc/omap_udc.c b/drivers/usb/gadget/udc/omap_udc.c
> index 61cabb9de6ae..b0567c63d754 100644
> --- a/drivers/usb/gadget/udc/omap_udc.c
> +++ b/drivers/usb/gadget/udc/omap_udc.c
> @@ -2558,7 +2558,7 @@ omap_ep_setup(char *name, u8 addr, u8 type,
>  
>  	/* set up driver data structures */
>  	BUG_ON(strlen(name) >= sizeof ep->name);
> -	strlcpy(ep->name, name, sizeof ep->name);
> +	strscpy(ep->name, name, sizeof(ep->name));
>  	INIT_LIST_HEAD(&ep->queue);
>  	INIT_LIST_HEAD(&ep->iso);
>  	ep->bEndpointAddress = addr;
> diff --git a/drivers/usb/misc/usb251xb.c b/drivers/usb/misc/usb251xb.c
> index 04c4e3fed094..87035ac09834 100644
> --- a/drivers/usb/misc/usb251xb.c
> +++ b/drivers/usb/misc/usb251xb.c
> @@ -547,7 +547,7 @@ static int usb251xb_get_ofdata(struct usb251xb *hub,
>  		hub->boost_up = USB251XB_DEF_BOOST_UP;
>  
>  	cproperty_char = of_get_property(np, "manufacturer", NULL);
> -	strlcpy(str, cproperty_char ? : USB251XB_DEF_MANUFACTURER_STRING,
> +	strscpy(str, cproperty_char ? : USB251XB_DEF_MANUFACTURER_STRING,
>  		sizeof(str));
>  	hub->manufacturer_len = strlen(str) & 0xFF;
>  	memset(hub->manufacturer, 0, USB251XB_STRING_BUFSIZE);
> @@ -557,7 +557,7 @@ static int usb251xb_get_ofdata(struct usb251xb *hub,
>  			      USB251XB_STRING_BUFSIZE);
>  
>  	cproperty_char = of_get_property(np, "product", NULL);
> -	strlcpy(str, cproperty_char ? : data->product_str, sizeof(str));
> +	strscpy(str, cproperty_char ? : data->product_str, sizeof(str));
>  	hub->product_len = strlen(str) & 0xFF;
>  	memset(hub->product, 0, USB251XB_STRING_BUFSIZE);
>  	len = min_t(size_t, USB251XB_STRING_BUFSIZE / 2, strlen(str));
> @@ -566,7 +566,7 @@ static int usb251xb_get_ofdata(struct usb251xb *hub,
>  			      USB251XB_STRING_BUFSIZE);
>  
>  	cproperty_char = of_get_property(np, "serial", NULL);
> -	strlcpy(str, cproperty_char ? : USB251XB_DEF_SERIAL_STRING,
> +	strscpy(str, cproperty_char ? : USB251XB_DEF_SERIAL_STRING,
>  		sizeof(str));
>  	hub->serial_len = strlen(str) & 0xFF;
>  	memset(hub->serial, 0, USB251XB_STRING_BUFSIZE);
> diff --git a/drivers/usb/storage/onetouch.c b/drivers/usb/storage/onetouch.c
> index 1db2eefeea22..01f3c2779ccf 100644
> --- a/drivers/usb/storage/onetouch.c
> +++ b/drivers/usb/storage/onetouch.c
> @@ -201,7 +201,7 @@ static int onetouch_connect_input(struct us_data *ss)
>  	onetouch->dev = input_dev;
>  
>  	if (udev->manufacturer)
> -		strlcpy(onetouch->name, udev->manufacturer,
> +		strscpy(onetouch->name, udev->manufacturer,
>  			sizeof(onetouch->name));
>  	if (udev->product) {
>  		if (udev->manufacturer)
> diff --git a/drivers/usb/typec/tcpm/fusb302.c b/drivers/usb/typec/tcpm/fusb302.c
> index 96c55eaf3f80..ab89c014606e 100644
> --- a/drivers/usb/typec/tcpm/fusb302.c
> +++ b/drivers/usb/typec/tcpm/fusb302.c
> @@ -151,7 +151,7 @@ static void _fusb302_log(struct fusb302_chip *chip, const char *fmt,
>  
>  	if (fusb302_log_full(chip)) {
>  		chip->logbuffer_head = max(chip->logbuffer_head - 1, 0);
> -		strlcpy(tmpbuffer, "overflow", sizeof(tmpbuffer));
> +		strscpy(tmpbuffer, "overflow", sizeof(tmpbuffer));
>  	}
>  
>  	if (chip->logbuffer_head < 0 ||
> diff --git a/drivers/usb/usbip/stub_main.c b/drivers/usb/usbip/stub_main.c
> index 77a5b3f8736a..e8c3131a8543 100644
> --- a/drivers/usb/usbip/stub_main.c
> +++ b/drivers/usb/usbip/stub_main.c
> @@ -100,7 +100,7 @@ static int add_match_busid(char *busid)
>  	for (i = 0; i < MAX_BUSID; i++) {
>  		spin_lock(&busid_table[i].busid_lock);
>  		if (!busid_table[i].name[0]) {
> -			strlcpy(busid_table[i].name, busid, BUSID_SIZE);
> +			strscpy(busid_table[i].name, busid, BUSID_SIZE);
>  			if ((busid_table[i].status != STUB_BUSID_ALLOC) &&
>  			    (busid_table[i].status != STUB_BUSID_REMOV))
>  				busid_table[i].status = STUB_BUSID_ADDED;
Richard Leitner Aug. 19, 2022, 5:31 a.m. UTC | #3
Hi Wolfram,

On Thu, Aug 18, 2022 at 11:01:15PM +0200, Wolfram Sang wrote:
> Follow the advice of the below link and prefer 'strscpy' in this
> subsystem. Conversion is 1:1 because the return value is not used.
> Generated by a coccinelle script.
> 
> Link: https://lore.kernel.org/r/CAHk-=wgfRnXz0W3D37d01q3JFkr_i_uTL=V6A6G1oUZcprmknw@mail.gmail.com/
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> ---
>  drivers/usb/atm/usbatm.c               | 2 +-
>  drivers/usb/core/devio.c               | 2 +-
>  drivers/usb/gadget/function/f_fs.c     | 2 +-
>  drivers/usb/gadget/function/f_uvc.c    | 2 +-
>  drivers/usb/gadget/function/u_ether.c  | 8 ++++----
>  drivers/usb/gadget/function/uvc_v4l2.c | 6 +++---
>  drivers/usb/gadget/udc/omap_udc.c      | 2 +-
>  drivers/usb/misc/usb251xb.c            | 6 +++---

Thanks for taking usb251xb into account.

Please feel free to add

Reviewed-by: Richard Leitner <richard.leitner@skidata.com>

>  drivers/usb/storage/onetouch.c         | 2 +-
>  drivers/usb/typec/tcpm/fusb302.c       | 2 +-
>  drivers/usb/usbip/stub_main.c          | 2 +-
>  11 files changed, 18 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
> index 362217189ef3..1cdb8758ae01 100644
> --- a/drivers/usb/atm/usbatm.c
> +++ b/drivers/usb/atm/usbatm.c
> @@ -1026,7 +1026,7 @@ int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
>  	/* public fields */
>  
>  	instance->driver = driver;
> -	strlcpy(instance->driver_name, driver->driver_name,
> +	strscpy(instance->driver_name, driver->driver_name,
>  		sizeof(instance->driver_name));
>  
>  	instance->usb_dev = usb_dev;
> diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
> index b5b85bf80329..837f3e57f580 100644
> --- a/drivers/usb/core/devio.c
> +++ b/drivers/usb/core/devio.c
> @@ -1434,7 +1434,7 @@ static int proc_getdriver(struct usb_dev_state *ps, void __user *arg)
>  	if (!intf || !intf->dev.driver)
>  		ret = -ENODATA;
>  	else {
> -		strlcpy(gd.driver, intf->dev.driver->name,
> +		strscpy(gd.driver, intf->dev.driver->name,
>  				sizeof(gd.driver));
>  		ret = (copy_to_user(arg, &gd, sizeof(gd)) ? -EFAULT : 0);
>  	}
> diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
> index e0fa4b186ec6..98dc2291e9a1 100644
> --- a/drivers/usb/gadget/function/f_fs.c
> +++ b/drivers/usb/gadget/function/f_fs.c
> @@ -3700,7 +3700,7 @@ int ffs_name_dev(struct ffs_dev *dev, const char *name)
>  
>  	existing = _ffs_do_find_dev(name);
>  	if (!existing)
> -		strlcpy(dev->name, name, ARRAY_SIZE(dev->name));
> +		strscpy(dev->name, name, ARRAY_SIZE(dev->name));
>  	else if (existing != dev)
>  		ret = -EBUSY;
>  
> diff --git a/drivers/usb/gadget/function/f_uvc.c b/drivers/usb/gadget/function/f_uvc.c
> index 71669e0e4d00..f4f6cf75930b 100644
> --- a/drivers/usb/gadget/function/f_uvc.c
> +++ b/drivers/usb/gadget/function/f_uvc.c
> @@ -430,7 +430,7 @@ uvc_register_video(struct uvc_device *uvc)
>  	uvc->vdev.vfl_dir = VFL_DIR_TX;
>  	uvc->vdev.lock = &uvc->video.mutex;
>  	uvc->vdev.device_caps = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING;
> -	strlcpy(uvc->vdev.name, cdev->gadget->name, sizeof(uvc->vdev.name));
> +	strscpy(uvc->vdev.name, cdev->gadget->name, sizeof(uvc->vdev.name));
>  
>  	video_set_drvdata(&uvc->vdev, uvc);
>  
> diff --git a/drivers/usb/gadget/function/u_ether.c b/drivers/usb/gadget/function/u_ether.c
> index 7887def05dc2..e06022873df1 100644
> --- a/drivers/usb/gadget/function/u_ether.c
> +++ b/drivers/usb/gadget/function/u_ether.c
> @@ -144,10 +144,10 @@ static void eth_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *p)
>  {
>  	struct eth_dev *dev = netdev_priv(net);
>  
> -	strlcpy(p->driver, "g_ether", sizeof(p->driver));
> -	strlcpy(p->version, UETH__VERSION, sizeof(p->version));
> -	strlcpy(p->fw_version, dev->gadget->name, sizeof(p->fw_version));
> -	strlcpy(p->bus_info, dev_name(&dev->gadget->dev), sizeof(p->bus_info));
> +	strscpy(p->driver, "g_ether", sizeof(p->driver));
> +	strscpy(p->version, UETH__VERSION, sizeof(p->version));
> +	strscpy(p->fw_version, dev->gadget->name, sizeof(p->fw_version));
> +	strscpy(p->bus_info, dev_name(&dev->gadget->dev), sizeof(p->bus_info));
>  }
>  
>  /* REVISIT can also support:
> diff --git a/drivers/usb/gadget/function/uvc_v4l2.c b/drivers/usb/gadget/function/uvc_v4l2.c
> index fd8f73bb726d..511f106f9843 100644
> --- a/drivers/usb/gadget/function/uvc_v4l2.c
> +++ b/drivers/usb/gadget/function/uvc_v4l2.c
> @@ -67,9 +67,9 @@ uvc_v4l2_querycap(struct file *file, void *fh, struct v4l2_capability *cap)
>  	struct uvc_device *uvc = video_get_drvdata(vdev);
>  	struct usb_composite_dev *cdev = uvc->func.config->cdev;
>  
> -	strlcpy(cap->driver, "g_uvc", sizeof(cap->driver));
> -	strlcpy(cap->card, cdev->gadget->name, sizeof(cap->card));
> -	strlcpy(cap->bus_info, dev_name(&cdev->gadget->dev),
> +	strscpy(cap->driver, "g_uvc", sizeof(cap->driver));
> +	strscpy(cap->card, cdev->gadget->name, sizeof(cap->card));
> +	strscpy(cap->bus_info, dev_name(&cdev->gadget->dev),
>  		sizeof(cap->bus_info));
>  	return 0;
>  }
> diff --git a/drivers/usb/gadget/udc/omap_udc.c b/drivers/usb/gadget/udc/omap_udc.c
> index 61cabb9de6ae..b0567c63d754 100644
> --- a/drivers/usb/gadget/udc/omap_udc.c
> +++ b/drivers/usb/gadget/udc/omap_udc.c
> @@ -2558,7 +2558,7 @@ omap_ep_setup(char *name, u8 addr, u8 type,
>  
>  	/* set up driver data structures */
>  	BUG_ON(strlen(name) >= sizeof ep->name);
> -	strlcpy(ep->name, name, sizeof ep->name);
> +	strscpy(ep->name, name, sizeof(ep->name));
>  	INIT_LIST_HEAD(&ep->queue);
>  	INIT_LIST_HEAD(&ep->iso);
>  	ep->bEndpointAddress = addr;
> diff --git a/drivers/usb/misc/usb251xb.c b/drivers/usb/misc/usb251xb.c
> index 04c4e3fed094..87035ac09834 100644
> --- a/drivers/usb/misc/usb251xb.c
> +++ b/drivers/usb/misc/usb251xb.c
> @@ -547,7 +547,7 @@ static int usb251xb_get_ofdata(struct usb251xb *hub,
>  		hub->boost_up = USB251XB_DEF_BOOST_UP;
>  
>  	cproperty_char = of_get_property(np, "manufacturer", NULL);
> -	strlcpy(str, cproperty_char ? : USB251XB_DEF_MANUFACTURER_STRING,
> +	strscpy(str, cproperty_char ? : USB251XB_DEF_MANUFACTURER_STRING,
>  		sizeof(str));
>  	hub->manufacturer_len = strlen(str) & 0xFF;
>  	memset(hub->manufacturer, 0, USB251XB_STRING_BUFSIZE);
> @@ -557,7 +557,7 @@ static int usb251xb_get_ofdata(struct usb251xb *hub,
>  			      USB251XB_STRING_BUFSIZE);
>  
>  	cproperty_char = of_get_property(np, "product", NULL);
> -	strlcpy(str, cproperty_char ? : data->product_str, sizeof(str));
> +	strscpy(str, cproperty_char ? : data->product_str, sizeof(str));
>  	hub->product_len = strlen(str) & 0xFF;
>  	memset(hub->product, 0, USB251XB_STRING_BUFSIZE);
>  	len = min_t(size_t, USB251XB_STRING_BUFSIZE / 2, strlen(str));
> @@ -566,7 +566,7 @@ static int usb251xb_get_ofdata(struct usb251xb *hub,
>  			      USB251XB_STRING_BUFSIZE);
>  
>  	cproperty_char = of_get_property(np, "serial", NULL);
> -	strlcpy(str, cproperty_char ? : USB251XB_DEF_SERIAL_STRING,
> +	strscpy(str, cproperty_char ? : USB251XB_DEF_SERIAL_STRING,
>  		sizeof(str));
>  	hub->serial_len = strlen(str) & 0xFF;
>  	memset(hub->serial, 0, USB251XB_STRING_BUFSIZE);
> diff --git a/drivers/usb/storage/onetouch.c b/drivers/usb/storage/onetouch.c
> index 1db2eefeea22..01f3c2779ccf 100644
> --- a/drivers/usb/storage/onetouch.c
> +++ b/drivers/usb/storage/onetouch.c
> @@ -201,7 +201,7 @@ static int onetouch_connect_input(struct us_data *ss)
>  	onetouch->dev = input_dev;
>  
>  	if (udev->manufacturer)
> -		strlcpy(onetouch->name, udev->manufacturer,
> +		strscpy(onetouch->name, udev->manufacturer,
>  			sizeof(onetouch->name));
>  	if (udev->product) {
>  		if (udev->manufacturer)
> diff --git a/drivers/usb/typec/tcpm/fusb302.c b/drivers/usb/typec/tcpm/fusb302.c
> index 96c55eaf3f80..ab89c014606e 100644
> --- a/drivers/usb/typec/tcpm/fusb302.c
> +++ b/drivers/usb/typec/tcpm/fusb302.c
> @@ -151,7 +151,7 @@ static void _fusb302_log(struct fusb302_chip *chip, const char *fmt,
>  
>  	if (fusb302_log_full(chip)) {
>  		chip->logbuffer_head = max(chip->logbuffer_head - 1, 0);
> -		strlcpy(tmpbuffer, "overflow", sizeof(tmpbuffer));
> +		strscpy(tmpbuffer, "overflow", sizeof(tmpbuffer));
>  	}
>  
>  	if (chip->logbuffer_head < 0 ||
> diff --git a/drivers/usb/usbip/stub_main.c b/drivers/usb/usbip/stub_main.c
> index 77a5b3f8736a..e8c3131a8543 100644
> --- a/drivers/usb/usbip/stub_main.c
> +++ b/drivers/usb/usbip/stub_main.c
> @@ -100,7 +100,7 @@ static int add_match_busid(char *busid)
>  	for (i = 0; i < MAX_BUSID; i++) {
>  		spin_lock(&busid_table[i].busid_lock);
>  		if (!busid_table[i].name[0]) {
> -			strlcpy(busid_table[i].name, busid, BUSID_SIZE);
> +			strscpy(busid_table[i].name, busid, BUSID_SIZE);
>  			if ((busid_table[i].status != STUB_BUSID_ALLOC) &&
>  			    (busid_table[i].status != STUB_BUSID_REMOV))
>  				busid_table[i].status = STUB_BUSID_ADDED;
> -- 
> 2.35.1
>
Wolfram Sang Aug. 19, 2022, 5:47 a.m. UTC | #4
Hi Shuah,

> Please elaborate and summarize why this change makses sense in the
> commit log? It will be easier for reviewers - saves time checking
> the link.

Okay. Will do this to all follow-ups / resends of this series.

> Acked-by: Shuah Khan <skhan@linuxfoundation.org>

Thanks,

   Wolfram
Greg Kroah-Hartman Aug. 19, 2022, 9:09 a.m. UTC | #5
On Thu, Aug 18, 2022 at 11:01:15PM +0200, Wolfram Sang wrote:
> Follow the advice of the below link and prefer 'strscpy' in this
> subsystem. Conversion is 1:1 because the return value is not used.
> Generated by a coccinelle script.
> 
> Link: https://lore.kernel.org/r/CAHk-=wgfRnXz0W3D37d01q3JFkr_i_uTL=V6A6G1oUZcprmknw@mail.gmail.com/
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>

You might want to fix up your email server, b4 doesn't think it is
sending out valid emails:

Grabbing thread from lore.kernel.org/all/20220818210116.7517-1-wsa%2Brenesas%40sang-engineering.com/t.mbox.gz
Analyzing 5 messages in the thread
Checking attestation on all messages, may take a moment...
---
  ✗ [PATCH] usb: move from strlcpy with unused retval to strscpy
    + Reviewed-by: Richard Leitner <richard.leitner@skidata.com> (✓ DKIM/skidata.com)
    + Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com> (✓ DKIM/ideasonboard.com)
    + Acked-by: Shuah Khan <skhan@linuxfoundation.org> (✓ DKIM/linuxfoundation.org)
  ---
  ✗ BADSIG: DKIM/sang-engineering.com
---
Total patches: 1
Wolfram Sang Aug. 24, 2022, 7:56 p.m. UTC | #6
>   ✗ BADSIG: DKIM/sang-engineering.com

Strange. When I save the message into a file and check locally, it seems
OK. I also never received a similar report from other b4 users.

===

$ cat message | dkimverify
signature ok
diff mbox series

Patch

diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
index 362217189ef3..1cdb8758ae01 100644
--- a/drivers/usb/atm/usbatm.c
+++ b/drivers/usb/atm/usbatm.c
@@ -1026,7 +1026,7 @@  int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
 	/* public fields */
 
 	instance->driver = driver;
-	strlcpy(instance->driver_name, driver->driver_name,
+	strscpy(instance->driver_name, driver->driver_name,
 		sizeof(instance->driver_name));
 
 	instance->usb_dev = usb_dev;
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index b5b85bf80329..837f3e57f580 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -1434,7 +1434,7 @@  static int proc_getdriver(struct usb_dev_state *ps, void __user *arg)
 	if (!intf || !intf->dev.driver)
 		ret = -ENODATA;
 	else {
-		strlcpy(gd.driver, intf->dev.driver->name,
+		strscpy(gd.driver, intf->dev.driver->name,
 				sizeof(gd.driver));
 		ret = (copy_to_user(arg, &gd, sizeof(gd)) ? -EFAULT : 0);
 	}
diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
index e0fa4b186ec6..98dc2291e9a1 100644
--- a/drivers/usb/gadget/function/f_fs.c
+++ b/drivers/usb/gadget/function/f_fs.c
@@ -3700,7 +3700,7 @@  int ffs_name_dev(struct ffs_dev *dev, const char *name)
 
 	existing = _ffs_do_find_dev(name);
 	if (!existing)
-		strlcpy(dev->name, name, ARRAY_SIZE(dev->name));
+		strscpy(dev->name, name, ARRAY_SIZE(dev->name));
 	else if (existing != dev)
 		ret = -EBUSY;
 
diff --git a/drivers/usb/gadget/function/f_uvc.c b/drivers/usb/gadget/function/f_uvc.c
index 71669e0e4d00..f4f6cf75930b 100644
--- a/drivers/usb/gadget/function/f_uvc.c
+++ b/drivers/usb/gadget/function/f_uvc.c
@@ -430,7 +430,7 @@  uvc_register_video(struct uvc_device *uvc)
 	uvc->vdev.vfl_dir = VFL_DIR_TX;
 	uvc->vdev.lock = &uvc->video.mutex;
 	uvc->vdev.device_caps = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING;
-	strlcpy(uvc->vdev.name, cdev->gadget->name, sizeof(uvc->vdev.name));
+	strscpy(uvc->vdev.name, cdev->gadget->name, sizeof(uvc->vdev.name));
 
 	video_set_drvdata(&uvc->vdev, uvc);
 
diff --git a/drivers/usb/gadget/function/u_ether.c b/drivers/usb/gadget/function/u_ether.c
index 7887def05dc2..e06022873df1 100644
--- a/drivers/usb/gadget/function/u_ether.c
+++ b/drivers/usb/gadget/function/u_ether.c
@@ -144,10 +144,10 @@  static void eth_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *p)
 {
 	struct eth_dev *dev = netdev_priv(net);
 
-	strlcpy(p->driver, "g_ether", sizeof(p->driver));
-	strlcpy(p->version, UETH__VERSION, sizeof(p->version));
-	strlcpy(p->fw_version, dev->gadget->name, sizeof(p->fw_version));
-	strlcpy(p->bus_info, dev_name(&dev->gadget->dev), sizeof(p->bus_info));
+	strscpy(p->driver, "g_ether", sizeof(p->driver));
+	strscpy(p->version, UETH__VERSION, sizeof(p->version));
+	strscpy(p->fw_version, dev->gadget->name, sizeof(p->fw_version));
+	strscpy(p->bus_info, dev_name(&dev->gadget->dev), sizeof(p->bus_info));
 }
 
 /* REVISIT can also support:
diff --git a/drivers/usb/gadget/function/uvc_v4l2.c b/drivers/usb/gadget/function/uvc_v4l2.c
index fd8f73bb726d..511f106f9843 100644
--- a/drivers/usb/gadget/function/uvc_v4l2.c
+++ b/drivers/usb/gadget/function/uvc_v4l2.c
@@ -67,9 +67,9 @@  uvc_v4l2_querycap(struct file *file, void *fh, struct v4l2_capability *cap)
 	struct uvc_device *uvc = video_get_drvdata(vdev);
 	struct usb_composite_dev *cdev = uvc->func.config->cdev;
 
-	strlcpy(cap->driver, "g_uvc", sizeof(cap->driver));
-	strlcpy(cap->card, cdev->gadget->name, sizeof(cap->card));
-	strlcpy(cap->bus_info, dev_name(&cdev->gadget->dev),
+	strscpy(cap->driver, "g_uvc", sizeof(cap->driver));
+	strscpy(cap->card, cdev->gadget->name, sizeof(cap->card));
+	strscpy(cap->bus_info, dev_name(&cdev->gadget->dev),
 		sizeof(cap->bus_info));
 	return 0;
 }
diff --git a/drivers/usb/gadget/udc/omap_udc.c b/drivers/usb/gadget/udc/omap_udc.c
index 61cabb9de6ae..b0567c63d754 100644
--- a/drivers/usb/gadget/udc/omap_udc.c
+++ b/drivers/usb/gadget/udc/omap_udc.c
@@ -2558,7 +2558,7 @@  omap_ep_setup(char *name, u8 addr, u8 type,
 
 	/* set up driver data structures */
 	BUG_ON(strlen(name) >= sizeof ep->name);
-	strlcpy(ep->name, name, sizeof ep->name);
+	strscpy(ep->name, name, sizeof(ep->name));
 	INIT_LIST_HEAD(&ep->queue);
 	INIT_LIST_HEAD(&ep->iso);
 	ep->bEndpointAddress = addr;
diff --git a/drivers/usb/misc/usb251xb.c b/drivers/usb/misc/usb251xb.c
index 04c4e3fed094..87035ac09834 100644
--- a/drivers/usb/misc/usb251xb.c
+++ b/drivers/usb/misc/usb251xb.c
@@ -547,7 +547,7 @@  static int usb251xb_get_ofdata(struct usb251xb *hub,
 		hub->boost_up = USB251XB_DEF_BOOST_UP;
 
 	cproperty_char = of_get_property(np, "manufacturer", NULL);
-	strlcpy(str, cproperty_char ? : USB251XB_DEF_MANUFACTURER_STRING,
+	strscpy(str, cproperty_char ? : USB251XB_DEF_MANUFACTURER_STRING,
 		sizeof(str));
 	hub->manufacturer_len = strlen(str) & 0xFF;
 	memset(hub->manufacturer, 0, USB251XB_STRING_BUFSIZE);
@@ -557,7 +557,7 @@  static int usb251xb_get_ofdata(struct usb251xb *hub,
 			      USB251XB_STRING_BUFSIZE);
 
 	cproperty_char = of_get_property(np, "product", NULL);
-	strlcpy(str, cproperty_char ? : data->product_str, sizeof(str));
+	strscpy(str, cproperty_char ? : data->product_str, sizeof(str));
 	hub->product_len = strlen(str) & 0xFF;
 	memset(hub->product, 0, USB251XB_STRING_BUFSIZE);
 	len = min_t(size_t, USB251XB_STRING_BUFSIZE / 2, strlen(str));
@@ -566,7 +566,7 @@  static int usb251xb_get_ofdata(struct usb251xb *hub,
 			      USB251XB_STRING_BUFSIZE);
 
 	cproperty_char = of_get_property(np, "serial", NULL);
-	strlcpy(str, cproperty_char ? : USB251XB_DEF_SERIAL_STRING,
+	strscpy(str, cproperty_char ? : USB251XB_DEF_SERIAL_STRING,
 		sizeof(str));
 	hub->serial_len = strlen(str) & 0xFF;
 	memset(hub->serial, 0, USB251XB_STRING_BUFSIZE);
diff --git a/drivers/usb/storage/onetouch.c b/drivers/usb/storage/onetouch.c
index 1db2eefeea22..01f3c2779ccf 100644
--- a/drivers/usb/storage/onetouch.c
+++ b/drivers/usb/storage/onetouch.c
@@ -201,7 +201,7 @@  static int onetouch_connect_input(struct us_data *ss)
 	onetouch->dev = input_dev;
 
 	if (udev->manufacturer)
-		strlcpy(onetouch->name, udev->manufacturer,
+		strscpy(onetouch->name, udev->manufacturer,
 			sizeof(onetouch->name));
 	if (udev->product) {
 		if (udev->manufacturer)
diff --git a/drivers/usb/typec/tcpm/fusb302.c b/drivers/usb/typec/tcpm/fusb302.c
index 96c55eaf3f80..ab89c014606e 100644
--- a/drivers/usb/typec/tcpm/fusb302.c
+++ b/drivers/usb/typec/tcpm/fusb302.c
@@ -151,7 +151,7 @@  static void _fusb302_log(struct fusb302_chip *chip, const char *fmt,
 
 	if (fusb302_log_full(chip)) {
 		chip->logbuffer_head = max(chip->logbuffer_head - 1, 0);
-		strlcpy(tmpbuffer, "overflow", sizeof(tmpbuffer));
+		strscpy(tmpbuffer, "overflow", sizeof(tmpbuffer));
 	}
 
 	if (chip->logbuffer_head < 0 ||
diff --git a/drivers/usb/usbip/stub_main.c b/drivers/usb/usbip/stub_main.c
index 77a5b3f8736a..e8c3131a8543 100644
--- a/drivers/usb/usbip/stub_main.c
+++ b/drivers/usb/usbip/stub_main.c
@@ -100,7 +100,7 @@  static int add_match_busid(char *busid)
 	for (i = 0; i < MAX_BUSID; i++) {
 		spin_lock(&busid_table[i].busid_lock);
 		if (!busid_table[i].name[0]) {
-			strlcpy(busid_table[i].name, busid, BUSID_SIZE);
+			strscpy(busid_table[i].name, busid, BUSID_SIZE);
 			if ((busid_table[i].status != STUB_BUSID_ALLOC) &&
 			    (busid_table[i].status != STUB_BUSID_REMOV))
 				busid_table[i].status = STUB_BUSID_ADDED;