2021-05-21 09:42:00

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH] kernfs: move return value check after kmalloc()

On Fri, May 21, 2021 at 03:55:25AM +0100, Austin Kim wrote:
> With 414985ae23c0 ("sysfs, kernfs: move file core code to fs/kernfs/file.c"),
> 'return -ENOMEM' is executed when kmalloc() returns NULL.
>
> Since 'commit 4ef67a8c95f3 ("sysfs/kernfs: make read requests on pre-alloc
> files use the buffer.")', 'return -ENOMEM' statement is not properly located.
>
> Fix it by moving 'return -ENOMEM' after return from kmalloc().
>
> Fixes: 4ef67a8c95f3 ("sysfs/kernfs: make read requests on pre-alloc files use the buffer.")
> Signed-off-by: Austin Kim <[email protected]>
> ---
> fs/kernfs/file.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
> index c75719312147..c5e2429af836 100644
> --- a/fs/kernfs/file.c
> +++ b/fs/kernfs/file.c
> @@ -191,10 +191,11 @@ static ssize_t kernfs_file_read_iter(struct kiocb *iocb, struct iov_iter *iter)
> buf = of->prealloc_buf;
> if (buf)
> mutex_lock(&of->prealloc_mutex);
> - else
> + else {
> buf = kmalloc(len, GFP_KERNEL);
> - if (!buf)
> - return -ENOMEM;
> + if (!buf)
> + return -ENOMEM;
> + }
>
> /*
> * @of->mutex nests outside active ref and is used both to ensure that
> --
> 2.20.1
>

Like Neil said, I don't see the "bug" you are fixing here. What is
currently wrong with the existing code?

thanks,

greg k-h


2021-05-21 20:08:36

by Austin Kim

[permalink] [raw]
Subject: Re: [PATCH] kernfs: move return value check after kmalloc()

2021년 5월 21일 (금) 오후 1:39, Greg KH <[email protected]>님이 작성:
>
> On Fri, May 21, 2021 at 03:55:25AM +0100, Austin Kim wrote:
> > With 414985ae23c0 ("sysfs, kernfs: move file core code to fs/kernfs/file.c"),
> > 'return -ENOMEM' is executed when kmalloc() returns NULL.
> >
> > Since 'commit 4ef67a8c95f3 ("sysfs/kernfs: make read requests on pre-alloc
> > files use the buffer.")', 'return -ENOMEM' statement is not properly located.
> >
> > Fix it by moving 'return -ENOMEM' after return from kmalloc().
> >
> > Fixes: 4ef67a8c95f3 ("sysfs/kernfs: make read requests on pre-alloc files use the buffer.")
> > Signed-off-by: Austin Kim <[email protected]>
[...]
>
> Like Neil said, I don't see the "bug" you are fixing here. What is
> currently wrong with the existing code?

I just found something to improve a little, which has nothing to do with 'Bug'.
(of->prealloc_buf is allocated ahead of kernfs_file_read_iter().)

Should be cautious of adding 'Fixes' tag.

Thanks

>
> thanks,
>
> greg k-h