public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Gao Xiang <hsiangkao@linux.alibaba.com>
To: Sandeep Dhavale <dhavale@google.com>,
	linux-erofs@lists.ozlabs.org, Gao Xiang <xiang@kernel.org>,
	Chao Yu <chao@kernel.org>, Yue Hu <huyue2@coolpad.com>,
	Jeffle Xu <jefflexu@linux.alibaba.com>,
	Chunhai Guo <guochunhai@vivo.com>
Cc: kernel-team@android.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1] erofs: fix possible memory leak in z_erofs_gbuf_exit()
Date: Tue, 25 Jun 2024 09:02:40 +0800	[thread overview]
Message-ID: <00e92d3f-7bdd-44b8-8a2f-ea07fd47d040@linux.alibaba.com> (raw)
In-Reply-To: <20240624220206.3373197-1-dhavale@google.com>



On 2024/6/25 06:02, Sandeep Dhavale wrote:
> Because we incorrectly reused of variable `i` in `z_erofs_gbuf_exit()`
> for inner loop, we may exit early from outer loop resulting in memory
> leak. Fix this by using separate variable for iterating through inner loop.
> 
> Fixes: f36f3010f676 ("erofs: rename per-CPU buffers to global buffer pool and make it configurable")
> 
> Signed-off-by: Sandeep Dhavale <dhavale@google.com>

Reviewed-by: Gao Xiang <hsiangkao@linux.alibaba.com>

Thanks,
Gao Xiang

> ---
>   fs/erofs/zutil.c | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/erofs/zutil.c b/fs/erofs/zutil.c
> index 036024bce9f7..b80f612867c2 100644
> --- a/fs/erofs/zutil.c
> +++ b/fs/erofs/zutil.c
> @@ -148,7 +148,7 @@ int __init z_erofs_gbuf_init(void)
>   
>   void z_erofs_gbuf_exit(void)
>   {
> -	int i;
> +	int i, j;
>   
>   	for (i = 0; i < z_erofs_gbuf_count + (!!z_erofs_rsvbuf); ++i) {
>   		struct z_erofs_gbuf *gbuf = &z_erofs_gbufpool[i];
> @@ -161,9 +161,9 @@ void z_erofs_gbuf_exit(void)
>   		if (!gbuf->pages)
>   			continue;
>   
> -		for (i = 0; i < gbuf->nrpages; ++i)
> -			if (gbuf->pages[i])
> -				put_page(gbuf->pages[i]);
> +		for (j = 0; j < gbuf->nrpages; ++j)
> +			if (gbuf->pages[j])
> +				put_page(gbuf->pages[j]);
>   		kfree(gbuf->pages);
>   		gbuf->pages = NULL;
>   	}

  reply	other threads:[~2024-06-25  1:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-24 22:02 [PATCH v1] erofs: fix possible memory leak in z_erofs_gbuf_exit() Sandeep Dhavale
2024-06-25  1:02 ` Gao Xiang [this message]
2024-06-26  8:26 ` Chao Yu

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=00e92d3f-7bdd-44b8-8a2f-ea07fd47d040@linux.alibaba.com \
    --to=hsiangkao@linux.alibaba.com \
    --cc=chao@kernel.org \
    --cc=dhavale@google.com \
    --cc=guochunhai@vivo.com \
    --cc=huyue2@coolpad.com \
    --cc=jefflexu@linux.alibaba.com \
    --cc=kernel-team@android.com \
    --cc=linux-erofs@lists.ozlabs.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=xiang@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