cluster-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
From: Bob Peterson <rpeterso@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH] gfs2: fix possible reference leak in gfs2_check_blk_type
Date: Wed, 4 Nov 2020 11:20:21 -0500 (EST)	[thread overview]
Message-ID: <783856258.24540058.1604506821579.JavaMail.zimbra@redhat.com> (raw)
In-Reply-To: <20201030101311.39674-1-zhangqilong3@huawei.com>

----- Original Message -----
> In the fail path of gfs2_check_blk_type, forgetting to call
> gfs2_glock_dq_uninit will result in rgd_gh reference leak.
> 
> Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
> ---
>  fs/gfs2/rgrp.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
> index ee491bb9c1cc..dd3e888994f7 100644
> --- a/fs/gfs2/rgrp.c
> +++ b/fs/gfs2/rgrp.c
> @@ -2526,8 +2526,10 @@ int gfs2_check_blk_type(struct gfs2_sbd *sdp, u64
> no_addr, unsigned int type)
>  
>  	rbm.rgd = rgd;
>  	error = gfs2_rbm_from_block(&rbm, no_addr);
> -	if (WARN_ON_ONCE(error))
> +	if (WARN_ON_ONCE(error)) {
> +		gfs2_glock_dq_uninit(&rgd_gh);
>  		goto fail;
> +	}
>  
>  	if (gfs2_testbit(&rbm, false) != type)
>  		error = -ESTALE;
> --
> 2.17.1

Hi,

Thanks. This is clearly a bug. Can we do something like this instead?
Andreas, which do you prefer?

 fs/gfs2/rgrp.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
index 92d799a193b8..b26d6fcb6915 100644
--- a/fs/gfs2/rgrp.c
+++ b/fs/gfs2/rgrp.c
@@ -2529,12 +2529,10 @@ int gfs2_check_blk_type(struct gfs2_sbd *sdp, u64 no_addr, unsigned int type)
 
 	rbm.rgd = rgd;
 	error = gfs2_rbm_from_block(&rbm, no_addr);
-	if (WARN_ON_ONCE(error))
-		goto fail;
-
-	if (gfs2_testbit(&rbm, false) != type)
-		error = -ESTALE;
-
+	if (!WARN_ON_ONCE(error)) {
+		if (gfs2_testbit(&rbm, false) != type)
+			error = -ESTALE;
+	}
 	gfs2_glock_dq_uninit(&rgd_gh);
 fail:
 	return error;

Regards,

Bob Peterson



      reply	other threads:[~2020-11-04 16:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-30 10:13 [Cluster-devel] [PATCH] gfs2: fix possible reference leak in gfs2_check_blk_type Zhang Qilong
2020-11-04 16:20 ` Bob Peterson [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=783856258.24540058.1604506821579.JavaMail.zimbra@redhat.com \
    --to=rpeterso@redhat.com \
    /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).