mm/cma: Replace snprintf with strscpy in cma_new_area
Subsystems (2)
PATCH 1/1 mm/cma: Replace snprintf with strscpy in cma_new_area
Replace snprintf("%s", ...) with the faster and more direct strscpy().
--- mm/cma.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
mm/cma.c +2 -1
@@ -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);
Signature · 2 lines
Thorsten Blum <[email protected]> GPG: 1D60 735E 8AEF 3BE4 73B6 9D84 7336 78FD 8DFE EAD4
Hello Thorsten,
Quoted 20 lines · On Mon, 26 Jan 2026 18:45:15 +0100 Thorsten Blum <[email protected]>…
Replace
snprintf("%s", ...)with the faster and more directstrscpy().Signed-off-by Thorsten Blum <[email protected]>--- mm/cma.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)mm/cma.c +1
-0@@ -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>
mm/cma.c static int __init cma_new_area(const char *name, phys_addr_t size, · line 237
Quoted 5 lines
mm/cma.c +1
-1@@ -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
[...]
Andrew Morton
maintainerQuoted 9 lines · On Mon, 26 Jan 2026 16:47:22 -0800 SeongJae Park <[email protected]> wrote:
mm/cma.c static int __init cma_new_area(const char *name, phys_addr_t size, · line 237
Quoted 6 lines
mm/cma.c +1
-1@@ -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_NAMEprotection? You can pass the size of destination buffer as the third argument ofstrscpy().
strscpy() will now use sizeof(cma->name):
char name[CMA_MAX_NAME];
SeongJae Park
Reviewed-byQuoted 12 lines · On Mon, 26 Jan 2026 16:54:50 -0800 Andrew Morton <[email protected]>…
Quoted 9 lines · On Mon, 26 Jan 2026 16:47:22 -0800 SeongJae Park <[email protected]> wrote:
mm/cma.c static int __init cma_new_area(const char *name, phys_addr_t size, · line 237
Quoted 6 lines
mm/cma.c +1
-1@@ -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_NAMEprotection? You can pass the size of destination buffer as the third argument ofstrscpy().
Quoted 3 lines
strscpy()will now usesizeof(cma->name):char name[CMA_MAX_NAME];
Ah, you're right.
Thanks,
SJ