diff mbox series

[net-next,v2] hns: use strscpy() to instead of strncpy()

Message ID 202212091533253334827@zte.com.cn (mailing list archive)
State Accepted
Headers show
Series [net-next,v2] hns: use strscpy() to instead of strncpy() | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 2 maintainers not CCed: yang.yang29@zte.com jiri@nvidia.com
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 22 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Yang Yang Dec. 9, 2022, 7:33 a.m. UTC
From: Xu Panda <xu.panda@zte.com.cn>

The implementation of strscpy() is more robust and safer.
That's now the recommended way to copy NUL terminated strings.

Signed-off-by: Xu Panda <xu.panda@zte.com.cn>
Signed-off-by: Yang Yang <yang.yang29@zte.com>
---
change for v2
 - change the prefix and subject: replace ethtool with hns,
and replace linux-next with net-next.
---
 drivers/net/ethernet/hisilicon/hns/hns_ethtool.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

Comments

Jiri Pirko Dec. 9, 2022, 9:01 a.m. UTC | #1
Fri, Dec 09, 2022 at 08:33:25AM CET, yang.yang29@zte.com.cn wrote:
>From: Xu Panda <xu.panda@zte.com.cn>
>
>The implementation of strscpy() is more robust and safer.
>That's now the recommended way to copy NUL terminated strings.
>
>Signed-off-by: Xu Panda <xu.panda@zte.com.cn>
>Signed-off-by: Yang Yang <yang.yang29@zte.com>

Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Hao Lan Dec. 13, 2022, 1:27 a.m. UTC | #2
On 2022/12/9 15:33, yang.yang29@zte.com.cn wrote:
> From: Xu Panda <xu.panda@zte.com.cn>
> 
> The implementation of strscpy() is more robust and safer.
> That's now the recommended way to copy NUL terminated strings.
> 
> Signed-off-by: Xu Panda <xu.panda@zte.com.cn>
> Signed-off-by: Yang Yang <yang.yang29@zte.com>
> ---
> change for v2
>  - change the prefix and subject: replace ethtool with hns,
> and replace linux-next with net-next.
> ---
>  drivers/net/ethernet/hisilicon/hns/hns_ethtool.c | 11 ++++-------
>  1 file changed, 4 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
> index 54faf0f2d1d8..b54f3706fb97 100644
> --- a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
> +++ b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
> @@ -644,18 +644,15 @@ static void hns_nic_get_drvinfo(struct net_device *net_dev,
>  {
>  	struct hns_nic_priv *priv = netdev_priv(net_dev);
> 
> -	strncpy(drvinfo->version, HNAE_DRIVER_VERSION,
> +	strscpy(drvinfo->version, HNAE_DRIVER_VERSION,
>  		sizeof(drvinfo->version));
> -	drvinfo->version[sizeof(drvinfo->version) - 1] = '\0';
> 
> -	strncpy(drvinfo->driver, HNAE_DRIVER_NAME, sizeof(drvinfo->driver));
> -	drvinfo->driver[sizeof(drvinfo->driver) - 1] = '\0';
> +	strscpy(drvinfo->driver, HNAE_DRIVER_NAME, sizeof(drvinfo->driver));
> 
> -	strncpy(drvinfo->bus_info, priv->dev->bus->name,
> +	strscpy(drvinfo->bus_info, priv->dev->bus->name,
>  		sizeof(drvinfo->bus_info));
> -	drvinfo->bus_info[ETHTOOL_BUSINFO_LEN - 1] = '\0';
> 
> -	strncpy(drvinfo->fw_version, "N/A", ETHTOOL_FWVERS_LEN);
> +	strscpy(drvinfo->fw_version, "N/A", ETHTOOL_FWVERS_LEN);
>  	drvinfo->eedump_len = 0;
>  }
> 
Reviewed-by: Hao Lan <lanhao@huawei.com>
diff mbox series

Patch

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
index 54faf0f2d1d8..b54f3706fb97 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
@@ -644,18 +644,15 @@  static void hns_nic_get_drvinfo(struct net_device *net_dev,
 {
 	struct hns_nic_priv *priv = netdev_priv(net_dev);

-	strncpy(drvinfo->version, HNAE_DRIVER_VERSION,
+	strscpy(drvinfo->version, HNAE_DRIVER_VERSION,
 		sizeof(drvinfo->version));
-	drvinfo->version[sizeof(drvinfo->version) - 1] = '\0';

-	strncpy(drvinfo->driver, HNAE_DRIVER_NAME, sizeof(drvinfo->driver));
-	drvinfo->driver[sizeof(drvinfo->driver) - 1] = '\0';
+	strscpy(drvinfo->driver, HNAE_DRIVER_NAME, sizeof(drvinfo->driver));

-	strncpy(drvinfo->bus_info, priv->dev->bus->name,
+	strscpy(drvinfo->bus_info, priv->dev->bus->name,
 		sizeof(drvinfo->bus_info));
-	drvinfo->bus_info[ETHTOOL_BUSINFO_LEN - 1] = '\0';

-	strncpy(drvinfo->fw_version, "N/A", ETHTOOL_FWVERS_LEN);
+	strscpy(drvinfo->fw_version, "N/A", ETHTOOL_FWVERS_LEN);
 	drvinfo->eedump_len = 0;
 }