Re: [PATCH 2/5] spi: lm70llp: Use strscpy() instead of strcpy()

From: David Laight

Date: Fri Oct 09 2026 - 10:54:59 EST


On Fri, 9 Oct 2026 19:06:06 +0530
Aayush Kumar <code@xxxxxxxxxxx> wrote:

> Use a safer function strscpy() instead of strcpy() for copying to
> arrays. Only idiomatic code replacement, and no functional changes.
>
> Signed-off-by: Aayush Kumar <code@xxxxxxxxxxx>
> ---
> drivers/spi/spi-lm70llp.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/spi/spi-lm70llp.c b/drivers/spi/spi-lm70llp.c
> index e61e89b41..bd8028892 100644
> --- a/drivers/spi/spi-lm70llp.c
> +++ b/drivers/spi/spi-lm70llp.c
> @@ -252,7 +252,7 @@ static void spi_lm70llp_attach(struct parport *p)
> * We are binding to the generic drivers/hwmon/lm70.c device
> * driver.
> */
> - strcpy(pp->info.modalias, "lm70");
> + strscpy(pp->info.modalias, "lm70", sizeof(pp->info.modalias));

Come on, if you are going to do that use the two argument form.
Or just don't bother at all.
Do the test compiles - if the literal string is too long you'll
get a compile error for strcpy(), but strscpy() truncates and returns
an error.
So strcpy() is arguably better.

David

> pp->info.max_speed_hz = 6 * 1000 * 1000;
> pp->info.chip_select = 0;
> pp->info.mode = SPI_3WIRE | SPI_MODE_0;