mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Austin Kim <austindh.kim@gmail.com>
Cc: tj@kernel.org, neilb@suse.de, linux-kernel@vger.kernel.org,
	austin.kim@lge.com
Subject: Re: [PATCH] kernfs: move return value check after kmalloc()
Date: Fri, 21 May 2021 06:39:40 +0200	[thread overview]
Message-ID: <YKc5jLVhw8+Oy165@kroah.com> (raw)
In-Reply-To: <20210521025525.GA1379@raspberrypi>

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 <austindh.kim@gmail.com>
> ---
>  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

  parent reply	other threads:[~2021-05-21  4:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-21  2:55 Austin Kim
2021-05-21  3:28 ` NeilBrown
2021-05-21  4:39 ` Greg KH [this message]
2021-05-21  6:55   ` Austin Kim
2021-05-21 12:15     ` David Laight
2021-05-21 12:55 ` David Laight

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YKc5jLVhw8+Oy165@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=austin.kim@lge.com \
    --cc=austindh.kim@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=neilb@suse.de \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®