Re: [PATCH] mm/cma: Replace snprintf with strscpy in cma_new_area

From: SeongJae Park

Date: Mon Jan 26 2026 - 19:47:38 EST


Hello Thorsten,

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

> Replace snprintf("%s", ...) with the faster and more direct strscpy().
>
> Signed-off-by: Thorsten Blum <thorsten.blum@xxxxxxxxx>
> ---
> 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

[...]