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

From: SeongJae Park

Date: Mon Jan 26 2026 - 20:05:18 EST


On Mon, 26 Jan 2026 16:54:50 -0800 Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> wrote:

> On Mon, 26 Jan 2026 16:47:22 -0800 SeongJae Park <sj@xxxxxxxxxx> 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@xxxxxxxxxx>


Thanks,
SJ