On Tue, 13 Jan 2026 12:05:13 -0500
Yury Norov <[email protected]> wrote:

> On Mon, Jan 12, 2026 at 03:30:36PM +0800, Fushuai Wang wrote:
> > From: Fushuai Wang <[email protected]>
> > 
> > Use copy_from_user_nul() instead of copy_from_user() to simplify
> > the code.
> > 
> > No functional change.
> > 
> > Signed-off-by: Fushuai Wang <[email protected]>
> > ---
> >  kernel/trace/trace.c | 3 +--
> >  1 file changed, 1 insertion(+), 2 deletions(-)
> > 
> > diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
> > index baec63134ab6..b6ffd006fcf9 100644
> > --- a/kernel/trace/trace.c
> > +++ b/kernel/trace/trace.c
> > @@ -11266,10 +11266,9 @@ ssize_t trace_parse_run_command(struct file *file, 
> > const char __user *buffer,
> >             if (size >= WRITE_BUFSIZE)
> >                     size = WRITE_BUFSIZE - 1;
> >  
> > -           if (copy_from_user(kbuf, buffer + done, size))
> > +           if (copy_from_user_nul(kbuf, buffer + done, size))
> >                     return -EFAULT;  
> 
> This hides the original error. Can you switch it to:
> 
>                 err = copy_xxx();
>                 if (err)
>                         return err;

No, the current way is fine. It's failing on reading user space. EFAULT
is good enough.

-- Steve


> 
> I understand that in this case EFAULT is the only possible error, but
> the above pattern is really error-prone, and is reproduced again and
> again over the kernel.
> 
> > -           kbuf[size] = '\0';
> >             buf = kbuf;
> >             do {
> >                     tmp = strchr(buf, '\n');
> > -- 
> > 2.36.1  


Reply via email to