2022-08-18 21:37:31

by Wolfram Sang

[permalink] [raw]
Subject: [PATCH] net: move from strlcpy with unused retval to strscpy

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 <[email protected]>
---
net/core/dev.c | 4 ++--
net/core/drop_monitor.c | 2 +-
net/core/netpoll.c | 4 ++--
3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/net/core/dev.c b/net/core/dev.c
index 716df64fcfa5..09058fe676ea 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -1100,7 +1100,7 @@ static int dev_alloc_name_ns(struct net *net,
BUG_ON(!net);
ret = __dev_alloc_name(net, name, buf);
if (ret >= 0)
- strlcpy(dev->name, buf, IFNAMSIZ);
+ strscpy(dev->name, buf, IFNAMSIZ);
return ret;
}

@@ -1137,7 +1137,7 @@ static int dev_get_valid_name(struct net *net, struct net_device *dev,
else if (netdev_name_in_use(net, name))
return -EEXIST;
else if (dev->name != name)
- strlcpy(dev->name, name, IFNAMSIZ);
+ strscpy(dev->name, name, IFNAMSIZ);

return 0;
}
diff --git a/net/core/drop_monitor.c b/net/core/drop_monitor.c
index 75501e1bdd25..876664fc605e 100644
--- a/net/core/drop_monitor.c
+++ b/net/core/drop_monitor.c
@@ -464,7 +464,7 @@ net_dm_hw_trap_summary_probe(void *ignore, const struct devlink *devlink,
goto out;

hw_entry = &hw_entries->entries[hw_entries->num_entries];
- strlcpy(hw_entry->trap_name, metadata->trap_name,
+ strscpy(hw_entry->trap_name, metadata->trap_name,
NET_DM_MAX_HW_TRAP_NAME_LEN - 1);
hw_entry->count = 1;
hw_entries->num_entries++;
diff --git a/net/core/netpoll.c b/net/core/netpoll.c
index 5d27067b72d5..9be762e1d042 100644
--- a/net/core/netpoll.c
+++ b/net/core/netpoll.c
@@ -556,7 +556,7 @@ int netpoll_parse_options(struct netpoll *np, char *opt)
if ((delim = strchr(cur, ',')) == NULL)
goto parse_failed;
*delim = 0;
- strlcpy(np->dev_name, cur, sizeof(np->dev_name));
+ strscpy(np->dev_name, cur, sizeof(np->dev_name));
cur = delim;
}
cur++;
@@ -610,7 +610,7 @@ int __netpoll_setup(struct netpoll *np, struct net_device *ndev)
int err;

np->dev = ndev;
- strlcpy(np->dev_name, ndev->name, IFNAMSIZ);
+ strscpy(np->dev_name, ndev->name, IFNAMSIZ);

if (ndev->priv_flags & IFF_DISABLE_NETPOLL) {
np_err(np, "%s doesn't support polling, aborting\n",
--
2.35.1


2022-08-19 06:58:30

by Marc Kleine-Budde

[permalink] [raw]
Subject: Re: [PATCH] net: move from strlcpy with unused retval to strscpy

On 18.08.2022 23:00:34, 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 <[email protected]>
> ---
> drivers/net/can/sja1000/peak_pcmcia.c | 2 +-
> drivers/net/can/usb/peak_usb/pcan_usb_core.c | 2 +-

Acked-by: Marc Kleine-Budde <[email protected]> # for CAN

regards,
Marc

--
Pengutronix e.K. | Marc Kleine-Budde |
Embedded Linux | https://www.pengutronix.de |
Vertretung West/Dortmund | Phone: +49-231-2826-924 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |


Attachments:
(No filename) (873.00 B)
signature.asc (499.00 B)
Download all attachments

2022-08-19 10:33:02

by Petr Machata

[permalink] [raw]
Subject: Re: [PATCH] net: move from strlcpy with unused retval to strscpy


Wolfram Sang <[email protected]> writes:

> drivers/net/ethernet/mellanox/mlxsw/core.c | 2 +-
> drivers/net/ethernet/mellanox/mlxsw/minimal.c | 4 ++--
> .../ethernet/mellanox/mlxsw/spectrum_ethtool.c | 6 +++---

Reviewed-by: Petr Machata <[email protected]> # For drivers/net/ethernet/mellanox/mlxsw

> diff --git a/drivers/net/ethernet/mellanox/mlxsw/core.c b/drivers/net/ethernet/mellanox/mlxsw/core.c
> index 75553eb2c7f2..7331635607f7 100644
> --- a/drivers/net/ethernet/mellanox/mlxsw/core.c
> +++ b/drivers/net/ethernet/mellanox/mlxsw/core.c
> @@ -633,7 +633,7 @@ static void mlxsw_emad_process_string_tlv(const struct sk_buff *skb,
> return;
>
> string = mlxsw_emad_string_tlv_string_data(string_tlv);
> - strlcpy(trans->emad_err_string, string,
> + strscpy(trans->emad_err_string, string,
> MLXSW_EMAD_STRING_TLV_STRING_LEN);
> }
>
> diff --git a/drivers/net/ethernet/mellanox/mlxsw/minimal.c b/drivers/net/ethernet/mellanox/mlxsw/minimal.c
> index bb1cd4bae82e..e3c045a82ae2 100644
> --- a/drivers/net/ethernet/mellanox/mlxsw/minimal.c
> +++ b/drivers/net/ethernet/mellanox/mlxsw/minimal.c
> @@ -94,14 +94,14 @@ static void mlxsw_m_module_get_drvinfo(struct net_device *dev,
> struct mlxsw_m_port *mlxsw_m_port = netdev_priv(dev);
> struct mlxsw_m *mlxsw_m = mlxsw_m_port->mlxsw_m;
>
> - strlcpy(drvinfo->driver, mlxsw_m->bus_info->device_kind,
> + strscpy(drvinfo->driver, mlxsw_m->bus_info->device_kind,
> sizeof(drvinfo->driver));
> snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
> "%d.%d.%d",
> mlxsw_m->bus_info->fw_rev.major,
> mlxsw_m->bus_info->fw_rev.minor,
> mlxsw_m->bus_info->fw_rev.subminor);
> - strlcpy(drvinfo->bus_info, mlxsw_m->bus_info->device_name,
> + strscpy(drvinfo->bus_info, mlxsw_m->bus_info->device_name,
> sizeof(drvinfo->bus_info));
> }
>
> diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_ethtool.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_ethtool.c
> index 915dffb85a1c..dcd79d7e2af4 100644
> --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_ethtool.c
> +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_ethtool.c
> @@ -14,16 +14,16 @@ static void mlxsw_sp_port_get_drvinfo(struct net_device *dev,
> struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
> struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
>
> - strlcpy(drvinfo->driver, mlxsw_sp->bus_info->device_kind,
> + strscpy(drvinfo->driver, mlxsw_sp->bus_info->device_kind,
> sizeof(drvinfo->driver));
> - strlcpy(drvinfo->version, mlxsw_sp_driver_version,
> + strscpy(drvinfo->version, mlxsw_sp_driver_version,
> sizeof(drvinfo->version));
> snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
> "%d.%d.%d",
> mlxsw_sp->bus_info->fw_rev.major,
> mlxsw_sp->bus_info->fw_rev.minor,
> mlxsw_sp->bus_info->fw_rev.subminor);
> - strlcpy(drvinfo->bus_info, mlxsw_sp->bus_info->device_name,
> + strscpy(drvinfo->bus_info, mlxsw_sp->bus_info->device_name,
> sizeof(drvinfo->bus_info));
> }

2022-08-23 01:54:05

by patchwork-bot+netdevbpf

[permalink] [raw]
Subject: Re: [PATCH] net: move from strlcpy with unused retval to strscpy

Hello:

This patch was applied to netdev/net-next.git (master)
by Jakub Kicinski <[email protected]>:

On Thu, 18 Aug 2022 23:02:15 +0200 you 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 <[email protected]>
>
> [...]

Here is the summary with links:
- net: move from strlcpy with unused retval to strscpy
https://git.kernel.org/netdev/net-next/c/70986397a15b

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html


2022-08-23 07:33:53

by Krzysztof Hałasa

[permalink] [raw]
Subject: Re: [PATCH] net: move from strlcpy with unused retval to strscpy

Wolfram Sang <[email protected]> writes:

> 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.

Looks good to me (IXP4xx Ethernet).
Acked-by: Krzysztof Hałasa <[email protected]>

> +++ b/drivers/net/ethernet/xscale/ixp4xx_eth.c
> @@ -999,11 +999,11 @@ static void ixp4xx_get_drvinfo(struct net_device *dev,
> {
> struct port *port = netdev_priv(dev);
>
> - strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
> + strscpy(info->driver, DRV_NAME, sizeof(info->driver));
> snprintf(info->fw_version, sizeof(info->fw_version), "%u:%u:%u:%u",
> port->firmware[0], port->firmware[1],
> port->firmware[2], port->firmware[3]);
> - strlcpy(info->bus_info, "internal", sizeof(info->bus_info));
> + strscpy(info->bus_info, "internal", sizeof(info->bus_info));
> }
>

--
Krzysztof "Chris" Hałasa

Sieć Badawcza Łukasiewicz
Przemysłowy Instytut Automatyki i Pomiarów PIAP
Al. Jerozolimskie 202, 02-486 Warszawa