[PATCH v5 2/3] ubifs: use strscpy() and kmemdup_nul() where appropriate

Dmitry Antipov dmantipov at yandex.ru
Wed Apr 15 22:09:12 PDT 2026


On Thu, 2026-04-16 at 11:37 +0800, Zhihao Cheng wrote:

> > -	memcpy(dent->name, fname_name(nm), fname_len(nm));
> > -	dent->name[fname_len(nm)] = '\0';
> > +	strscpy(dent->name, fname_name(nm), fname_len(nm) + 1);
> 
> Hi Dmitry,
> I notice that some architectures can accelerate the implementation of 
> memcpy(), and the length of dentry name could be 255, I suggest to keep 
> the orignal implementation.

What about

memcpy_and_pad(dent->name, fname_len(nm) + 1, fname_name(nm), fname_len(nm), 0)?

I have a strong suspicion that all of the '\0' things should be left to
library functions. So this is not a style but rather an overall design point -
if you're inserting '\0' at your own, most likely you're doing something
wrong, at least because you're duplicating something which is already
implemented in a library function.

Dmitry



More information about the linux-mtd mailing list