linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/cma: Replace snprintf with strscpy in cma_new_area
@ 2026-01-26 17:45 Thorsten Blum
  2026-01-27  0:47 ` SeongJae Park
  0 siblings, 1 reply; 4+ messages in thread
From: Thorsten Blum @ 2026-01-26 17:45 UTC (permalink / raw)
  To: Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
	Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko
  Cc: Thorsten Blum, linux-mm, linux-kernel

Replace snprintf("%s", ...) with the faster and more direct strscpy().

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 mm/cma.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mm/cma.c b/mm/cma.c
index 813e6dc7b095..44b43de28c13 100644
--- a/mm/cma.c
+++ b/mm/cma.c
@@ -22,6 +22,7 @@
 #include <linux/mm.h>
 #include <linux/sizes.h>
 #include <linux/slab.h>
+#include <linux/string.h>
 #include <linux/string_choices.h>
 #include <linux/log2.h>
 #include <linux/cma.h>
@@ -233,7 +234,7 @@ static int __init cma_new_area(const char *name, phys_addr_t size,
 	cma_area_count++;
 
 	if (name)
-		snprintf(cma->name, CMA_MAX_NAME, "%s", name);
+		strscpy(cma->name, name);
 	else
 		snprintf(cma->name, CMA_MAX_NAME,  "cma%d\n", cma_area_count);
 
-- 
Thorsten Blum <thorsten.blum@linux.dev>
GPG: 1D60 735E 8AEF 3BE4 73B6  9D84 7336 78FD 8DFE EAD4



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mm/cma: Replace snprintf with strscpy in cma_new_area
  2026-01-26 17:45 [PATCH] mm/cma: Replace snprintf with strscpy in cma_new_area Thorsten Blum
@ 2026-01-27  0:47 ` SeongJae Park
  2026-01-27  0:54   ` Andrew Morton
  0 siblings, 1 reply; 4+ messages in thread
From: SeongJae Park @ 2026-01-27  0:47 UTC (permalink / raw)
  To: Thorsten Blum
  Cc: SeongJae Park, Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
	Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko, linux-mm, linux-kernel

Hello Thorsten,

On Mon, 26 Jan 2026 18:45:15 +0100 Thorsten Blum <thorsten.blum@linux.dev> wrote:

> Replace snprintf("%s", ...) with the faster and more direct strscpy().
> 
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
>  mm/cma.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/cma.c b/mm/cma.c
> index 813e6dc7b095..44b43de28c13 100644
> --- a/mm/cma.c
> +++ b/mm/cma.c
> @@ -22,6 +22,7 @@
>  #include <linux/mm.h>
>  #include <linux/sizes.h>
>  #include <linux/slab.h>
> +#include <linux/string.h>
>  #include <linux/string_choices.h>
>  #include <linux/log2.h>
>  #include <linux/cma.h>
> @@ -233,7 +234,7 @@ static int __init cma_new_area(const char *name, phys_addr_t size,
>  	cma_area_count++;
>  
>  	if (name)
> -		snprintf(cma->name, CMA_MAX_NAME, "%s", name);
> +		strscpy(cma->name, name);

Any reason to drop CMA_MAX_NAME protection?  You can pass the size of
destination buffer as the third argument of strscpy().


Thanks,
SJ

[...]


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mm/cma: Replace snprintf with strscpy in cma_new_area
  2026-01-27  0:47 ` SeongJae Park
@ 2026-01-27  0:54   ` Andrew Morton
  2026-01-27  1:05     ` SeongJae Park
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Morton @ 2026-01-27  0:54 UTC (permalink / raw)
  To: SeongJae Park
  Cc: Thorsten Blum, David Hildenbrand, Lorenzo Stoakes,
	Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko, linux-mm, linux-kernel

On Mon, 26 Jan 2026 16:47:22 -0800 SeongJae Park <sj@kernel.org> wrote:

> > @@ -233,7 +234,7 @@ static int __init cma_new_area(const char *name, phys_addr_t size,
> >  	cma_area_count++;
> >  
> >  	if (name)
> > -		snprintf(cma->name, CMA_MAX_NAME, "%s", name);
> > +		strscpy(cma->name, name);
> 
> Any reason to drop CMA_MAX_NAME protection?  You can pass the size of
> destination buffer as the third argument of strscpy().

strscpy() will now use sizeof(cma->name):

	char name[CMA_MAX_NAME];



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mm/cma: Replace snprintf with strscpy in cma_new_area
  2026-01-27  0:54   ` Andrew Morton
@ 2026-01-27  1:05     ` SeongJae Park
  0 siblings, 0 replies; 4+ messages in thread
From: SeongJae Park @ 2026-01-27  1:05 UTC (permalink / raw)
  To: Andrew Morton
  Cc: SeongJae Park, Thorsten Blum, David Hildenbrand, Lorenzo Stoakes,
	Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko, linux-mm, linux-kernel

On Mon, 26 Jan 2026 16:54:50 -0800 Andrew Morton <akpm@linux-foundation.org> wrote:

> On Mon, 26 Jan 2026 16:47:22 -0800 SeongJae Park <sj@kernel.org> wrote:
> 
> > > @@ -233,7 +234,7 @@ static int __init cma_new_area(const char *name, phys_addr_t size,
> > >  	cma_area_count++;
> > >  
> > >  	if (name)
> > > -		snprintf(cma->name, CMA_MAX_NAME, "%s", name);
> > > +		strscpy(cma->name, name);
> > 
> > Any reason to drop CMA_MAX_NAME protection?  You can pass the size of
> > destination buffer as the third argument of strscpy().
> 
> strscpy() will now use sizeof(cma->name):
> 
> 	char name[CMA_MAX_NAME];

Ah, you're right.

Reviewed-by: SeongJae Park <sj@kernel.org>


Thanks,
SJ


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-01-27  1:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-26 17:45 [PATCH] mm/cma: Replace snprintf with strscpy in cma_new_area Thorsten Blum
2026-01-27  0:47 ` SeongJae Park
2026-01-27  0:54   ` Andrew Morton
2026-01-27  1:05     ` SeongJae Park

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox