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

yang.yang29@zte.com.cn posted 1 patch 2 years, 8 months ago
drivers/net/wireless/ath/ath5k/led.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
[PATCH net-next] ath5k: use strscpy() to instead of strncpy()
Posted by yang.yang29@zte.com.cn 2 years, 8 months ago
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>
---
 drivers/net/wireless/ath/ath5k/led.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/net/wireless/ath/ath5k/led.c b/drivers/net/wireless/ath/ath5k/led.c
index 33e9928af363..439052984796 100644
--- a/drivers/net/wireless/ath/ath5k/led.c
+++ b/drivers/net/wireless/ath/ath5k/led.c
@@ -131,8 +131,7 @@ ath5k_register_led(struct ath5k_hw *ah, struct ath5k_led *led,
 	int err;

 	led->ah = ah;
-	strncpy(led->name, name, sizeof(led->name));
-	led->name[sizeof(led->name)-1] = 0;
+	strscpy(led->name, name, sizeof(led->name));
 	led->led_dev.name = led->name;
 	led->led_dev.default_trigger = trigger;
 	led->led_dev.brightness_set = ath5k_led_brightness_set;
-- 
2.15.2
Re: [PATCH net-next] ath5k: use strscpy() to instead of strncpy()
Posted by Luis Chamberlain 2 years, 8 months ago
On Fri, Dec 23, 2022 at 10:34:45AM +0800, 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.

According to who? Are you sure you are not just sending stupid commits
to get an increase in your kernel commit count? Because this is an old
driver and who cares?

  Luis
Re: [PATCH net-next] ath5k: use strscpy() to instead of strncpy()
Posted by yang.yang29@zte.com.cn 2 years, 8 months ago
> According to who? Are you sure you are not just sending stupid commits
> to get an increase in your kernel commit count? Because this is an old
> driver and who cares?

This is suggested by Petr Mladek, please see:
https://lore.kernel.org/all/Y4cz27AbZVVd9pLJ@alley/

And if the driver no one cares, we may stop modify it.