diff mbox series

[-next] eeprom: at25: Replace strncpy() with strscpy()

Message ID 20220118182047.3385295-1-keescook@chromium.org (mailing list archive)
State Mainlined
Headers show
Series [-next] eeprom: at25: Replace strncpy() with strscpy() | expand

Commit Message

Kees Cook Jan. 18, 2022, 6:20 p.m. UTC
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 <gregkh@linuxfoundation.org>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Jiri Prchal <jiri.prchal@aksignal.cz>
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/misc/eeprom/at25.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Ralph Siemsen Jan. 26, 2022, 7:48 p.m. UTC | #1
Hi Kees,

On Tue, Jan 18, 2022 at 10:20:47AM -0800, Kees Cook wrote:
>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.

Tested-by: Ralph Siemsen <ralph.siemsen@linaro.org>

Cheers,
-Ralph
Kees Cook Jan. 26, 2022, 8 p.m. UTC | #2
On Wed, Jan 26, 2022 at 02:48:39PM -0500, Ralph Siemsen wrote:
> Hi Kees,
> 
> On Tue, Jan 18, 2022 at 10:20:47AM -0800, Kees Cook wrote:
> > 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.
> 
> Tested-by: Ralph Siemsen <ralph.siemsen@linaro.org>

Thanks!
diff mbox series

Patch

diff --git a/drivers/misc/eeprom/at25.c b/drivers/misc/eeprom/at25.c
index bee727ed98db..91f96abbb3f9 100644
--- a/drivers/misc/eeprom/at25.c
+++ b/drivers/misc/eeprom/at25.c
@@ -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);