net: usb: switch to two-argument strscpy
Subsystems (8)
PATCH 1/1 net: usb: switch to two-argument strscpy
All instances of strscpy in the USB network drivers use the size of the destination. If given only two arguments, strscpy will automatically use the size of the destination. Make the code more concise by switching to the two-argument form of strscpy.
Also add a blank line after a variable declaration in catc.c to adhere to kernel code style, since the surrounding code is being touched.
--- drivers/net/usb/aqc111.c | 2 +- drivers/net/usb/asix_common.c | 4 ++-- drivers/net/usb/catc.c | 5 +++-- drivers/net/usb/ipheth.c | 2 +- drivers/net/usb/lan78xx.c | 2 +- drivers/net/usb/pegasus.c | 2 +- drivers/net/usb/r8152.c | 9 ++++----- drivers/net/usb/rtl8150.c | 4 ++-- drivers/net/usb/sierra_net.c | 4 ++-- drivers/net/usb/sr9800.c | 4 ++-- drivers/net/usb/usbnet.c | 13 ++++++------- 11 files changed, 25 insertions(+), 26 deletions(-)
drivers/net/usb/aqc111.c +1 -1
@@ -207,7 +207,7 @@ static void aqc111_get_drvinfo(struct net_device *net,/* Inherit standard device info */ usbnet_get_drvinfo (net, info); -strscpy (info->driver,DRIVER_NAME ,sizeof (info->driver)); +strscpy (info->driver,DRIVER_NAME ); snprintf(info->fw_version, sizeof(info->fw_version), "%u.%u.%u", aqc111_data->fw_ver.major, aqc111_data->fw_ver.minor,
drivers/net/usb/asix_common.c +2 -2
@@ -735,8 +735,8 @@ void asix_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *info) {/* Inherit standard device info */ usbnet_get_drvinfo (net, info); -strscpy (info->driver,DRIVER_NAME ,sizeof (info->driver)); -strscpy (info->version,DRIVER_VERSION ,sizeof (info->version)); +strscpy (info->driver,DRIVER_NAME ); +strscpy (info->version,DRIVER_VERSION ); }int asix_set_mac_address (struct net_device *net,void *p)
drivers/net/usb/catc.c +3 -2
@@ -672,8 +672,9 @@ static void catc_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) {struct catc *catc =netdev_priv (dev); -strscpy (info->driver, driver_name,sizeof (info->driver)); -strscpy (info->version,DRIVER_VERSION ,sizeof (info->version)); + +strscpy (info->driver, driver_name); +strscpy (info->version,DRIVER_VERSION );usb_make_path (catc->usbdev, info->bus_info,sizeof (info->bus_info)); }
drivers/net/usb/ipheth.c +1 -1
@@ -586,7 +586,7 @@ static int ipheth_probe(struct usb_interface *intf, netdev->netdev_ops = &ipheth_netdev_ops; netdev->watchdog_timeo =IPHETH_TX_TIMEOUT ; -strscpy (netdev->name,"eth%d" ,sizeof (netdev->name)); +strscpy (netdev->name,"eth%d" ); dev =netdev_priv (netdev); dev->udev = udev;
drivers/net/usb/lan78xx.c +1 -1
@@ -1811,7 +1811,7 @@ static void lan78xx_get_drvinfo(struct net_device *net, {struct lan78xx_net *dev =netdev_priv (net); -strscpy (info->driver,DRIVER_NAME ,sizeof (info->driver)); +strscpy (info->driver,DRIVER_NAME );usb_make_path (dev->udev, info->bus_info,sizeof (info->bus_info)); }
drivers/net/usb/pegasus.c +1 -1
@@ -896,7 +896,7 @@ static void pegasus_get_drvinfo(struct net_device *dev, {pegasus_t *pegasus =netdev_priv (dev); -strscpy (info->driver, driver_name,sizeof (info->driver)); +strscpy (info->driver, driver_name);usb_make_path (pegasus->usb, info->bus_info,sizeof (info->bus_info)); }
drivers/net/usb/r8152.c +4 -5
@@ -5256,7 +5256,7 @@ static void rtl8152_apply_firmware(struct r8152 *tp, bool power_cut) rtl_fw->post_fw (tp);rtl_reset_ocp_base (tp); -strscpy (rtl_fw->version, fw_hdr->version,RTL_VER_SIZE ); +strscpy (rtl_fw->version, fw_hdr->version);dev_dbg (&tp->intf->dev,"load %s successfully\n" , rtl_fw->version); }
@@ -8755,12 +8755,11 @@ static void rtl8152_get_drvinfo(struct net_device *netdev, {struct r8152 *tp =netdev_priv (netdev); -strscpy (info->driver,MODULENAME ,sizeof (info->driver)); -strscpy (info->version,DRIVER_VERSION ,sizeof (info->version)); +strscpy (info->driver,MODULENAME ); +strscpy (info->version,DRIVER_VERSION );usb_make_path (tp->udev, info->bus_info,sizeof (info->bus_info));if (!IS_ERR_OR_NULL (tp->rtl_fw.fw)) -strscpy (info->fw_version, tp->rtl_fw.version, -sizeof (info->fw_version)); +strscpy (info->fw_version, tp->rtl_fw.version); } static
drivers/net/usb/rtl8150.c +2 -2
@@ -784,8 +784,8 @@ static void rtl8150_get_drvinfo(struct net_device *netdev, struct ethtool_drvinf {rtl8150_t *dev =netdev_priv (netdev); -strscpy (info->driver, driver_name,sizeof (info->driver)); -strscpy (info->version,DRIVER_VERSION ,sizeof (info->version)); +strscpy (info->driver, driver_name); +strscpy (info->version,DRIVER_VERSION );usb_make_path (dev->udev, info->bus_info,sizeof (info->bus_info)); }
drivers/net/usb/sierra_net.c +2 -2
@@ -612,8 +612,8 @@ static void sierra_net_get_drvinfo(struct net_device *net, {/* Inherit standard device info */ usbnet_get_drvinfo (net, info); -strscpy (info->driver, driver_name,sizeof (info->driver)); -strscpy (info->version,DRIVER_VERSION ,sizeof (info->version)); +strscpy (info->driver, driver_name); +strscpy (info->version,DRIVER_VERSION ); }static u32 sierra_net_get_link (struct net_device *net)
drivers/net/usb/sr9800.c +2 -2
@@ -474,8 +474,8 @@ static void sr_get_drvinfo(struct net_device *net, {/* Inherit standard device info */ usbnet_get_drvinfo (net, info); -strscpy (info->driver,DRIVER_NAME ,sizeof (info->driver)); -strscpy (info->version,DRIVER_VERSION ,sizeof (info->version)); +strscpy (info->driver,DRIVER_NAME ); +strscpy (info->version,DRIVER_VERSION ); }static u32 sr_get_link (struct net_device *net)
drivers/net/usb/usbnet.c +6 -7
@@ -1089,9 +1089,8 @@ void usbnet_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *info) {struct usbnet *dev =netdev_priv (net); -strscpy (info->driver, dev->driver_name,sizeof (info->driver)); -strscpy (info->fw_version, dev->driver_info->description, -sizeof (info->fw_version)); +strscpy (info->driver, dev->driver_name); +strscpy (info->fw_version, dev->driver_info->description);usb_make_path (dev->udev, info->bus_info,sizeof (info->bus_info)); }EXPORT_SYMBOL_GPL (usbnet_get_drvinfo);
@@ -1783,7 +1782,7 @@ usbnet_probe(struct usb_interface *udev, const struct usb_device_id *prod) dev->interrupt_count =0 ; dev->net = net; -strscpy (net->name,"usb%d" ,sizeof (net->name)); +strscpy (net->name,"usb%d" );/* rx and tx sides can use different message sizes; * bind() should set rx_urb_size in that case.
@@ -1809,13 +1808,13 @@ usbnet_probe(struct usb_interface *udev, const struct usb_device_id *prod)*/ if ((dev->driver_info->flags &FLAG_ETHER ) !=0 && !usbnet_needs_usb_name_format (dev, net)) -strscpy (net->name,"eth%d" ,sizeof (net->name)); +strscpy (net->name,"eth%d" );/* WLAN devices should always be named "wlan%d" */ if ((dev->driver_info->flags &FLAG_WLAN ) !=0 ) -strscpy (net->name,"wlan%d" ,sizeof (net->name)); +strscpy (net->name,"wlan%d" );/* WWAN devices should always be named "wwan%d" */ if ((dev->driver_info->flags &FLAG_WWAN ) !=0 ) -strscpy (net->name,"wwan%d" ,sizeof (net->name)); +strscpy (net->name,"wwan%d" );/* devices that cannot do ARP */ if ((dev->driver_info->flags &FLAG_NOARP ) !=0 )
Signature · 1 line
2.43.0
Quoted 7 lines · Ethan Nelson-Moore
All instances of strscpy in the USB network drivers use the size of the destination. If given only two arguments, strscpy will automatically use the size of the destination. Make the code more concise by switching to the two-argument form of strscpy.
Also add a blank line after a variable declaration in
catc.cto adhere to kernel code style, since the surrounding code is being touched.
It should go after your patch that drops some of the strscpy():s. Hence make a v3 as a series of two patches.
Code wise this LGTM, thanks for doing this.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 11 lines · Andy Shevchenko
Quoted 7 lines · Ethan Nelson-Moore
All instances of strscpy in the USB network drivers use the size of the destination. If given only two arguments, strscpy will automatically use the size of the destination. Make the code more concise by switching to the two-argument form of strscpy.
Also add a blank line after a variable declaration in
catc.cto adhere to kernel code style, since the surrounding code is being touched.It should go after your patch that drops some of the strscpy():s. Hence make a v3 as a series of two patches.
FWIW, your v3 missed this patch... What's your plan with it?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Jakub Kicinski
maintainerQuoted 7 lines · On Sun, 25 Jan 2026 19:50:15 -0800 Ethan Nelson-Moore wrote:
All instances of strscpy in the USB network drivers use the size of the destination. If given only two arguments, strscpy will automatically use the size of the destination. Make the code more concise by switching to the two-argument form of strscpy.
Also add a blank line after a variable declaration in
catc.cto adhere to kernel code style, since the surrounding code is being touched.
Let's not waste our time replacing all 3-arg strscpy()s with 2-arg right after we wasted our time replacing strxcpy() with strscpy(). Who cares.
Signature · 1 line
pw-bot: reject