Re: [PATCH] staging: atomisp: replace sprintf with strscpy

From: Dan Carpenter

Date: Thu Feb 26 2026 - 02:15:02 EST


On Wed, Feb 25, 2026 at 09:45:48PM +0100, tomasz.unger@xxxxxxxx wrote:
> From: Tomasz Unger <tomasz.unger@xxxxxxxx>
>
> Replace deprecated sprintf() with strscpy() which is the preferred
> kernel API for string copying. strscpy() is safer as it guarantees
> null-termination and prevents potential buffer overflows.
>

Technically sprintf() also guarantees NUL termination. :P

When you're writing a commit like this I want the first or second
sentence to say "This patch does not affect run-time because sd->name
is a 52 character buffer." I would prefer to avoid any talk about
"potential buffer overflows." It's the same as me claiming that I am
potentially an NBA star. Something like this:

I am doing an audit of calls to sprintf(). This code is fine
because we are copying 9 characters into a 52 character buffer.
But it would be cleaner to use strscpy() instead.

> Since sd->name is a fixed-size array, the destination buffer size
> is deduced automatically by the kernel-defined strscpy() macro,
> so no explicit size parameter is needed.
>
> Compiled and tested by loading atomisp.ko module successfully.

This information should go under the --- cut off line.

>
> Signed-off-by: Tomasz Unger <tomasz.unger@xxxxxxxx>
> ---
^^^
Here.

regards,
dan carpenter