diff mbox series

power: supply: use strscpy() is more robust and safer

Message ID 20220919024919.211210-1-chi.minghao@zte.com.cn
State New
Headers show
Series power: supply: use strscpy() is more robust and safer | expand

Commit Message

Lv Ruyi Sept. 19, 2022, 2:49 a.m. UTC
From: Minghao Chi <chi.minghao@zte.com.cn>

The implementation of strscpy() is more robust and safer.

That's now the recommended way to copy NUL terminated strings.

Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Minghao Chi <chi.minghao@zte.com.cn>
---
 drivers/power/supply/max1721x_battery.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Sebastian Reichel Feb. 3, 2023, 1 p.m. UTC | #1
Hi,

On Mon, Sep 19, 2022 at 02:49:19AM +0000, cgel.zte@gmail.com wrote:
> From: Minghao Chi <chi.minghao@zte.com.cn>
> 
> The implementation of strscpy() is more robust and safer.
> 
> That's now the recommended way to copy NUL terminated strings.
> 
> Reported-by: Zeal Robot <zealci@zte.com.cn>
> Signed-off-by: Minghao Chi <chi.minghao@zte.com.cn>
> ---

Sorry, this fell between the cracks. Applied now, thanks!

-- Sebastian

>  drivers/power/supply/max1721x_battery.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/power/supply/max1721x_battery.c b/drivers/power/supply/max1721x_battery.c
> index 473e53cd2801..0f948db958d5 100644
> --- a/drivers/power/supply/max1721x_battery.c
> +++ b/drivers/power/supply/max1721x_battery.c
> @@ -384,7 +384,7 @@ static int devm_w1_max1721x_add_device(struct w1_slave *sl)
>  	}
>  
>  	if (!info->ManufacturerName[0])
> -		strncpy(info->ManufacturerName, DEF_MFG_NAME,
> +		strscpy(info->ManufacturerName, DEF_MFG_NAME,
>  			2 * MAX1721X_REG_MFG_NUMB);
>  
>  	if (get_string(info, MAX1721X_REG_DEV_STR,
> @@ -403,15 +403,15 @@ static int devm_w1_max1721x_add_device(struct w1_slave *sl)
>  
>  		switch (dev_name & MAX172XX_DEV_MASK) {
>  		case MAX172X1_DEV:
> -			strncpy(info->DeviceName, DEF_DEV_NAME_MAX17211,
> +			strscpy(info->DeviceName, DEF_DEV_NAME_MAX17211,
>  				2 * MAX1721X_REG_DEV_NUMB);
>  			break;
>  		case MAX172X5_DEV:
> -			strncpy(info->DeviceName, DEF_DEV_NAME_MAX17215,
> +			strscpy(info->DeviceName, DEF_DEV_NAME_MAX17215,
>  				2 * MAX1721X_REG_DEV_NUMB);
>  			break;
>  		default:
> -			strncpy(info->DeviceName, DEF_DEV_NAME_UNKNOWN,
> +			strscpy(info->DeviceName, DEF_DEV_NAME_UNKNOWN,
>  				2 * MAX1721X_REG_DEV_NUMB);
>  		}
>  	}
> -- 
> 2.25.1
diff mbox series

Patch

diff --git a/drivers/power/supply/max1721x_battery.c b/drivers/power/supply/max1721x_battery.c
index 473e53cd2801..0f948db958d5 100644
--- a/drivers/power/supply/max1721x_battery.c
+++ b/drivers/power/supply/max1721x_battery.c
@@ -384,7 +384,7 @@  static int devm_w1_max1721x_add_device(struct w1_slave *sl)
 	}
 
 	if (!info->ManufacturerName[0])
-		strncpy(info->ManufacturerName, DEF_MFG_NAME,
+		strscpy(info->ManufacturerName, DEF_MFG_NAME,
 			2 * MAX1721X_REG_MFG_NUMB);
 
 	if (get_string(info, MAX1721X_REG_DEV_STR,
@@ -403,15 +403,15 @@  static int devm_w1_max1721x_add_device(struct w1_slave *sl)
 
 		switch (dev_name & MAX172XX_DEV_MASK) {
 		case MAX172X1_DEV:
-			strncpy(info->DeviceName, DEF_DEV_NAME_MAX17211,
+			strscpy(info->DeviceName, DEF_DEV_NAME_MAX17211,
 				2 * MAX1721X_REG_DEV_NUMB);
 			break;
 		case MAX172X5_DEV:
-			strncpy(info->DeviceName, DEF_DEV_NAME_MAX17215,
+			strscpy(info->DeviceName, DEF_DEV_NAME_MAX17215,
 				2 * MAX1721X_REG_DEV_NUMB);
 			break;
 		default:
-			strncpy(info->DeviceName, DEF_DEV_NAME_UNKNOWN,
+			strscpy(info->DeviceName, DEF_DEV_NAME_UNKNOWN,
 				2 * MAX1721X_REG_DEV_NUMB);
 		}
 	}