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

From: Petr Machata
Date: Fri Aug 19 2022 - 05:58:21 EST



Wolfram Sang <wsa+renesas@xxxxxxxxxxxxxxxxxxxx> 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 <petrm@xxxxxxxxxx> # 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));
> }