Skip to contentSkip to conversation

eeprom: at25: Replace strncpy() with strscpy()

PATCH In review Kees Cook 2 participants 3 messages Jan 18, 2022 – Jan 26, 2022 Char and misc drivers

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 eeprom: at25: Replace strncpy() with strscpy()

Use strscpy() instead of strncpy(), since its use has been deprecated[1].

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings

Cc Greg Kroah-Hartman <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Jiri Prchal <[email protected]>
---
 drivers/misc/eeprom/at25.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/misc/eeprom/at25.c +2 -2
index bee727ed98db..91f96abbb3f9 100644
@@ -309,7 +309,7 @@ static int at25_fw_to_chip(struct device *dev, struct spi_eeprom *chip)
 	u32 val;
 	int err;
 
-	strncpy(chip->name, "at25", sizeof(chip->name));
+	strscpy(chip->name, "at25", sizeof(chip->name));
 
 	err = device_property_read_u32(dev, "size", &val);
 	if (err)
@@ -370,7 +370,7 @@ static int at25_fram_to_chip(struct device *dev, struct spi_eeprom *chip)
 	u8 id[FM25_ID_LEN];
 	int i;
 
-	strncpy(chip->name, "fm25", sizeof(chip->name));
+	strscpy(chip->name, "fm25", sizeof(chip->name));
 
 	/* Get ID of chip */
 	fm25_aux_read(at25, id, FM25_RDID, FM25_ID_LEN);
Signature · 1 line
2.30.2
author
#2 lore raw
Quoted 11 lines · Ralph Siemsen

Hi Kees,

Quoted 3 lines · Kees Cook

Use strscpy() instead of strncpy(), since its use has been deprecated[1].

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings

Along with your other fix to restore the missing kzalloc(), I tested this change on 32-bit arm system, and it worked as expected.

Thanks!

Signature · 1 line
Kees Cook