Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

power: supply: max1721x: Use strscpy() is more robust and safer

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>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>

authored by

Minghao Chi and committed by
Sebastian Reichel
301cfbc1 3639dbd7

+4 -4
+4 -4
drivers/power/supply/max1721x_battery.c
··· 384 384 } 385 385 386 386 if (!info->ManufacturerName[0]) 387 - strncpy(info->ManufacturerName, DEF_MFG_NAME, 387 + strscpy(info->ManufacturerName, DEF_MFG_NAME, 388 388 2 * MAX1721X_REG_MFG_NUMB); 389 389 390 390 if (get_string(info, MAX1721X_REG_DEV_STR, ··· 403 403 404 404 switch (dev_name & MAX172XX_DEV_MASK) { 405 405 case MAX172X1_DEV: 406 - strncpy(info->DeviceName, DEF_DEV_NAME_MAX17211, 406 + strscpy(info->DeviceName, DEF_DEV_NAME_MAX17211, 407 407 2 * MAX1721X_REG_DEV_NUMB); 408 408 break; 409 409 case MAX172X5_DEV: 410 - strncpy(info->DeviceName, DEF_DEV_NAME_MAX17215, 410 + strscpy(info->DeviceName, DEF_DEV_NAME_MAX17215, 411 411 2 * MAX1721X_REG_DEV_NUMB); 412 412 break; 413 413 default: 414 - strncpy(info->DeviceName, DEF_DEV_NAME_UNKNOWN, 414 + strscpy(info->DeviceName, DEF_DEV_NAME_UNKNOWN, 415 415 2 * MAX1721X_REG_DEV_NUMB); 416 416 } 417 417 }