From: David Sterba <dsterba@suse.cz>
To: Dinghao Liu <dinghao.liu@zju.edu.cn>
Cc: kjlu@umn.edu, Chris Mason <clm@fb.com>,
Josef Bacik <josef@toxicpanda.com>,
David Sterba <dsterba@suse.com>,
linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] btrfs: add missing check after link_free_space
Date: Mon, 9 Dec 2019 19:25:43 +0100 [thread overview]
Message-ID: <20191209182543.GQ2734@twin.jikos.cz> (raw)
In-Reply-To: <20191209034114.16212-1-dinghao.liu@zju.edu.cn>
On Mon, Dec 09, 2019 at 11:41:14AM +0800, Dinghao Liu wrote:
> The return value of link_free_space is checked out-sync.
> One branch of an if statement uses an extra check after
> WARN_ON() but its peer branch does not. WARN_ON() does
> not change the control flow, thus only using this check
> might be insufficient.
>
> Fix this by simply adding a check on ret.
>
> Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> --
> Changes in v2:
> - Add memory free for free space entry.
> ---
> fs/btrfs/free-space-cache.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
> index 3283da419200..ba2e6cea5233 100644
> --- a/fs/btrfs/free-space-cache.c
> +++ b/fs/btrfs/free-space-cache.c
> @@ -2437,6 +2437,10 @@ int btrfs_remove_free_space(struct btrfs_block_group *block_group,
> if (info->bytes) {
> ret = link_free_space(ctl, info);
> WARN_ON(ret);
> + if (ret) {
> + kmem_cache_free(btrfs_free_space_cachep, info);
> + goto out_lock;
> + }
> } else {
> kmem_cache_free(btrfs_free_space_cachep, info);
There are two link_free_space followed by WARN_ON instances in the
function, please remove both.
In the above case, the branches can be merged together so there's not
repeated kmem_cache_free, like
if (info->bytes)
ret = link_free_space(...);
kmem_cache_free(btrfs_free_space_cachep, info);
if (ret)
goto out_unlock;
prev parent reply other threads:[~2019-12-09 18:25 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-09 3:41 [PATCH v2] btrfs: add missing check after link_free_space Dinghao Liu
2019-12-09 18:25 ` David Sterba [this message]
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=20191209182543.GQ2734@twin.jikos.cz \
--to=dsterba@suse.cz \
--cc=clm@fb.com \
--cc=dinghao.liu@zju.edu.cn \
--cc=dsterba@suse.com \
--cc=josef@toxicpanda.com \
--cc=kjlu@umn.edu \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@vger.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;
as well as URLs for NNTP newsgroup(s).