[net-next] net: hns3: use strscpy() to instead of strncpy()

Message ID 202212091538591375035@zte.com.cn
State New
Headers
Series [net-next] net: hns3: use strscpy() to instead of strncpy() |

Commit Message

Yang Yang Dec. 9, 2022, 7:38 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 subject, replace linux-next with net-next.
---
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
  

Comments

Jiri Pirko Dec. 9, 2022, 9:02 a.m. UTC | #1
Fri, Dec 09, 2022 at 08:38:59AM 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>
  
patchwork-bot+netdevbpf@kernel.org Dec. 12, 2022, 9:11 p.m. UTC | #2
Hello:

This patch was applied to bpf/bpf-next.git (master)
by Jakub Kicinski <kuba@kernel.org>:

On Fri, 9 Dec 2022 15:38:59 +0800 (CST) you 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>
> 
> [...]

Here is the summary with links:
  - [net-next] net: hns3: use strscpy() to instead of strncpy()
    https://git.kernel.org/bpf/bpf-next/c/80a464d83f08

You are awesome, thank you!
  

Patch

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
index cdf76fb58d45..55306fe8a540 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
@@ -639,13 +639,11 @@  static void hns3_get_drvinfo(struct net_device *netdev,
 		return;
 	}

-	strncpy(drvinfo->driver, dev_driver_string(&h->pdev->dev),
+	strscpy(drvinfo->driver, dev_driver_string(&h->pdev->dev),
 		sizeof(drvinfo->driver));
-	drvinfo->driver[sizeof(drvinfo->driver) - 1] = '\0';

-	strncpy(drvinfo->bus_info, pci_name(h->pdev),
+	strscpy(drvinfo->bus_info, pci_name(h->pdev),
 		sizeof(drvinfo->bus_info));
-	drvinfo->bus_info[ETHTOOL_BUSINFO_LEN - 1] = '\0';

 	fw_version = priv->ae_handle->ae_algo->ops->get_fw_version(h);