* [PATCH] m68k: replace deprecated strncpy with strscpy
@ 2025-04-16 5:31 Shankari02
0 siblings, 0 replies; 6+ messages in thread
From: Shankari02 @ 2025-04-16 5:31 UTC (permalink / raw)
To: linux-kernel; +Cc: linux-m68k, skhan, Shankari02
The use of strncpy() does not guarantee NUL-termination and is deprecated
in the Linux kernel. This code manually terminates the buffer afterward,
but using strscpy() is simpler and safer.
This change replaces the strncpy() + NUL termination pattern with strscpy().
Signed-off-by: Shankari Anand <shankari.ak0208@gmail.com>
---
arch/m68k/kernel/setup_mm.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/arch/m68k/kernel/setup_mm.c b/arch/m68k/kernel/setup_mm.c
index 15c1a595a1de..48ce67947678 100644
--- a/arch/m68k/kernel/setup_mm.c
+++ b/arch/m68k/kernel/setup_mm.c
@@ -243,8 +243,7 @@ void __init setup_arch(char **cmdline_p)
setup_initial_init_mm((void *)PAGE_OFFSET, _etext, _edata, _end);
#if defined(CONFIG_BOOTPARAM)
- strncpy(m68k_command_line, CONFIG_BOOTPARAM_STRING, CL_SIZE);
- m68k_command_line[CL_SIZE - 1] = 0;
+ strscpy(m68k_command_line, CONFIG_BOOTPARAM_STRING, CL_SIZE);
#endif /* CONFIG_BOOTPARAM */
process_uboot_commandline(&m68k_command_line[0], CL_SIZE);
*cmdline_p = m68k_command_line;
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH] m68k: replace deprecated strncpy with strscpy
@ 2025-04-17 20:10 Shankari02
2025-04-21 13:01 ` Jean-Michel Hautbois
2025-04-22 6:53 ` Geert Uytterhoeven
0 siblings, 2 replies; 6+ messages in thread
From: Shankari02 @ 2025-04-17 20:10 UTC (permalink / raw)
To: linux-m68k; +Cc: geert, jeanmichel.hautbois, Shankari02
The use of strncpy() does not guarantee NUL-termination and is deprecated
in the Linux kernel. This code manually terminates the buffer afterward,
but using strscpy() is simpler and safer.
This change replaces the strncpy() + NUL termination pattern with strscpy().
Signed-off-by: Shankari Anand <shankari.ak0208@gmail.com>
---
arch/m68k/kernel/setup_mm.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/arch/m68k/kernel/setup_mm.c b/arch/m68k/kernel/setup_mm.c
index 15c1a595a1de..48ce67947678 100644
--- a/arch/m68k/kernel/setup_mm.c
+++ b/arch/m68k/kernel/setup_mm.c
@@ -243,8 +243,7 @@ void __init setup_arch(char **cmdline_p)
setup_initial_init_mm((void *)PAGE_OFFSET, _etext, _edata, _end);
#if defined(CONFIG_BOOTPARAM)
- strncpy(m68k_command_line, CONFIG_BOOTPARAM_STRING, CL_SIZE);
- m68k_command_line[CL_SIZE - 1] = 0;
+ strscpy(m68k_command_line, CONFIG_BOOTPARAM_STRING, CL_SIZE);
#endif /* CONFIG_BOOTPARAM */
process_uboot_commandline(&m68k_command_line[0], CL_SIZE);
*cmdline_p = m68k_command_line;
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] m68k: replace deprecated strncpy with strscpy
2025-04-17 20:10 [PATCH] m68k: replace deprecated strncpy with strscpy Shankari02
@ 2025-04-21 13:01 ` Jean-Michel Hautbois
2025-04-21 21:00 ` Jean-Michel Hautbois
2025-04-22 6:53 ` Geert Uytterhoeven
1 sibling, 1 reply; 6+ messages in thread
From: Jean-Michel Hautbois @ 2025-04-21 13:01 UTC (permalink / raw)
To: Shankari02, linux-m68k; +Cc: geert
Hi Shankari,
On 17/04/2025 22:10, Shankari02 wrote:
> The use of strncpy() does not guarantee NUL-termination and is deprecated
> in the Linux kernel. This code manually terminates the buffer afterward,
> but using strscpy() is simpler and safer.
This assumption is true, but adding a link to the explanation could be
better ?
https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy
>
> This change replaces the strncpy() + NUL termination pattern with strscpy().
>
> Signed-off-by: Shankari Anand <shankari.ak0208@gmail.com>
> ---
> arch/m68k/kernel/setup_mm.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/arch/m68k/kernel/setup_mm.c b/arch/m68k/kernel/setup_mm.c
> index 15c1a595a1de..48ce67947678 100644
> --- a/arch/m68k/kernel/setup_mm.c
> +++ b/arch/m68k/kernel/setup_mm.c
> @@ -243,8 +243,7 @@ void __init setup_arch(char **cmdline_p)
> setup_initial_init_mm((void *)PAGE_OFFSET, _etext, _edata, _end);
>
> #if defined(CONFIG_BOOTPARAM)
> - strncpy(m68k_command_line, CONFIG_BOOTPARAM_STRING, CL_SIZE);
> - m68k_command_line[CL_SIZE - 1] = 0;
> + strscpy(m68k_command_line, CONFIG_BOOTPARAM_STRING, CL_SIZE);
> #endif /* CONFIG_BOOTPARAM */
> process_uboot_commandline(&m68k_command_line[0], CL_SIZE);
> *cmdline_p = m68k_command_line;
As we are not using the return value, I think it is a safe replacement.
With the link added:
Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@yoseli.org>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] m68k: replace deprecated strncpy with strscpy
2025-04-21 13:01 ` Jean-Michel Hautbois
@ 2025-04-21 21:00 ` Jean-Michel Hautbois
0 siblings, 0 replies; 6+ messages in thread
From: Jean-Michel Hautbois @ 2025-04-21 21:00 UTC (permalink / raw)
To: Shankari02, linux-m68k; +Cc: geert
Hi,
On 21/04/2025 15:01, Jean-Michel Hautbois wrote:
> Hi Shankari,
>
> On 17/04/2025 22:10, Shankari02 wrote:
>> The use of strncpy() does not guarantee NUL-termination and is deprecated
>> in the Linux kernel. This code manually terminates the buffer afterward,
>> but using strscpy() is simpler and safer.
>
> This assumption is true, but adding a link to the explanation could be
> better ?
> https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy
>
>>
>> This change replaces the strncpy() + NUL termination pattern with
>> strscpy().
>>
>> Signed-off-by: Shankari Anand <shankari.ak0208@gmail.com>
>> ---
>> arch/m68k/kernel/setup_mm.c | 3 +--
>> 1 file changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/arch/m68k/kernel/setup_mm.c b/arch/m68k/kernel/setup_mm.c
>> index 15c1a595a1de..48ce67947678 100644
>> --- a/arch/m68k/kernel/setup_mm.c
>> +++ b/arch/m68k/kernel/setup_mm.c
>> @@ -243,8 +243,7 @@ void __init setup_arch(char **cmdline_p)
>> setup_initial_init_mm((void *)PAGE_OFFSET, _etext, _edata, _end);
>> #if defined(CONFIG_BOOTPARAM)
>> - strncpy(m68k_command_line, CONFIG_BOOTPARAM_STRING, CL_SIZE);
>> - m68k_command_line[CL_SIZE - 1] = 0;
>> + strscpy(m68k_command_line, CONFIG_BOOTPARAM_STRING, CL_SIZE);
>> #endif /* CONFIG_BOOTPARAM */
>> process_uboot_commandline(&m68k_command_line[0], CL_SIZE);
>> *cmdline_p = m68k_command_line;
>
> As we are not using the return value, I think it is a safe replacement.
>
> With the link added:
> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@yoseli.org>
Sorry for this one:
s/Signed-off-by/Reviewed-by/
JM
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] m68k: replace deprecated strncpy with strscpy
2025-04-17 20:10 [PATCH] m68k: replace deprecated strncpy with strscpy Shankari02
2025-04-21 13:01 ` Jean-Michel Hautbois
@ 2025-04-22 6:53 ` Geert Uytterhoeven
[not found] ` <CAPRMd3m2UmfPrzD2eXW9s_Uc1kM4cwCB4pMAbSSPX+MB85=H=A@mail.gmail.com>
1 sibling, 1 reply; 6+ messages in thread
From: Geert Uytterhoeven @ 2025-04-22 6:53 UTC (permalink / raw)
To: Shankari02; +Cc: linux-m68k, jeanmichel.hautbois
Hi Shankari,
On Thu, 17 Apr 2025 at 22:10, Shankari02 <shankari.ak0208@gmail.com> wrote:
> The use of strncpy() does not guarantee NUL-termination and is deprecated
> in the Linux kernel. This code manually terminates the buffer afterward,
> but using strscpy() is simpler and safer.
>
> This change replaces the strncpy() + NUL termination pattern with strscpy().
>
> Signed-off-by: Shankari Anand <shankari.ak0208@gmail.com>
Thanks for your patch!
> --- a/arch/m68k/kernel/setup_mm.c
> +++ b/arch/m68k/kernel/setup_mm.c
> @@ -243,8 +243,7 @@ void __init setup_arch(char **cmdline_p)
> setup_initial_init_mm((void *)PAGE_OFFSET, _etext, _edata, _end);
>
> #if defined(CONFIG_BOOTPARAM)
> - strncpy(m68k_command_line, CONFIG_BOOTPARAM_STRING, CL_SIZE);
> - m68k_command_line[CL_SIZE - 1] = 0;
> + strscpy(m68k_command_line, CONFIG_BOOTPARAM_STRING, CL_SIZE);
> #endif /* CONFIG_BOOTPARAM */
> process_uboot_commandline(&m68k_command_line[0], CL_SIZE);
> *cmdline_p = m68k_command_line;
The same change was already applied as commit a7130910b80753d5 ("m68k:
mm: Replace deprecated strncpy() with strscpy()") in v6.15-rc1.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] m68k: replace deprecated strncpy with strscpy
[not found] ` <CAPRMd3m2UmfPrzD2eXW9s_Uc1kM4cwCB4pMAbSSPX+MB85=H=A@mail.gmail.com>
@ 2025-04-23 15:42 ` Shankari
0 siblings, 0 replies; 6+ messages in thread
From: Shankari @ 2025-04-23 15:42 UTC (permalink / raw)
To: Geert Uytterhoeven; +Cc: linux-m68k, jeanmichel.hautbois
Hi Geert,
Thank you for the quick review and for pointing that out!
Apologies for the duplicate. I'll make sure to check for existing
commits more carefully next time. I appreciate your time and feedback.
Regards,
Shankari
On Wed, Apr 23, 2025 at 8:49 PM Shankari <shankari.ak0208@gmail.com> wrote:
>
> Hi Geert,
>
> Thank you for the quick review and for pointing that out!
>
> Apologies for the duplicate. I'll make sure to check for existing commits more carefully next time. I appreciate your time and feedback.
>
> Regards,
> Shankari
>
>
> On Tue, Apr 22, 2025 at 12:23 PM Geert Uytterhoeven <geert@linux-m68k.org> wrote:
>>
>> Hi Shankari,
>>
>> On Thu, 17 Apr 2025 at 22:10, Shankari02 <shankari.ak0208@gmail.com> wrote:
>> > The use of strncpy() does not guarantee NUL-termination and is deprecated
>> > in the Linux kernel. This code manually terminates the buffer afterward,
>> > but using strscpy() is simpler and safer.
>> >
>> > This change replaces the strncpy() + NUL termination pattern with strscpy().
>> >
>> > Signed-off-by: Shankari Anand <shankari.ak0208@gmail.com>
>>
>> Thanks for your patch!
>>
>> > --- a/arch/m68k/kernel/setup_mm.c
>> > +++ b/arch/m68k/kernel/setup_mm.c
>> > @@ -243,8 +243,7 @@ void __init setup_arch(char **cmdline_p)
>> > setup_initial_init_mm((void *)PAGE_OFFSET, _etext, _edata, _end);
>> >
>> > #if defined(CONFIG_BOOTPARAM)
>> > - strncpy(m68k_command_line, CONFIG_BOOTPARAM_STRING, CL_SIZE);
>> > - m68k_command_line[CL_SIZE - 1] = 0;
>> > + strscpy(m68k_command_line, CONFIG_BOOTPARAM_STRING, CL_SIZE);
>> > #endif /* CONFIG_BOOTPARAM */
>> > process_uboot_commandline(&m68k_command_line[0], CL_SIZE);
>> > *cmdline_p = m68k_command_line;
>>
>> The same change was already applied as commit a7130910b80753d5 ("m68k:
>> mm: Replace deprecated strncpy() with strscpy()") in v6.15-rc1.
>>
>> Gr{oetje,eeting}s,
>>
>> Geert
>>
>> --
>> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
>>
>> In personal conversations with technical people, I call myself a hacker. But
>> when I'm talking to journalists I just say "programmer" or something like that.
>> -- Linus Torvalds
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-04-23 15:42 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-17 20:10 [PATCH] m68k: replace deprecated strncpy with strscpy Shankari02
2025-04-21 13:01 ` Jean-Michel Hautbois
2025-04-21 21:00 ` Jean-Michel Hautbois
2025-04-22 6:53 ` Geert Uytterhoeven
[not found] ` <CAPRMd3m2UmfPrzD2eXW9s_Uc1kM4cwCB4pMAbSSPX+MB85=H=A@mail.gmail.com>
2025-04-23 15:42 ` Shankari
-- strict thread matches above, loose matches on Subject: below --
2025-04-16 5:31 Shankari02
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).