mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Javier González" <javier@javigon.com>
To: Navid Emamdoost <navid.emamdoost@gmail.com>
Cc: emamd001@umn.edu, smccaman@umn.edu, kjlu@umn.edu,
	"Matias Bjørling" <mb@lightnvm.io>,
	linux-block@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] lightnvm: prevent memory leak in nvm_bb_chunk_sense
Date: Mon, 30 Sep 2019 10:06:38 +0200	[thread overview]
Message-ID: <8FE3FFB7-4FF5-4BF5-B95E-2FECC003702D@javigon.com> (raw)
In-Reply-To: <20190930023415.24171-1-navid.emamdoost@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1243 bytes --]

> On 30 Sep 2019, at 04.34, Navid Emamdoost <navid.emamdoost@gmail.com> wrote:
> 
> In nvm_bb_chunk_sense alloc_page allocates memory which is released at
> the end of the function. But if nvm_submit_io_sync_raw fails the error
> check skips the release and leaks the allocated page. To fix this issue
> I moved the __free_page call before error check.
> 
> Fixes: aff3fb18f957 ("lightnvm: move bad block and chunk state logic to core")
> Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
> ---
> drivers/lightnvm/core.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
> index 7543e395a2c6..5fdae518f6c9 100644
> --- a/drivers/lightnvm/core.c
> +++ b/drivers/lightnvm/core.c
> @@ -849,11 +849,12 @@ static int nvm_bb_chunk_sense(struct nvm_dev *dev, struct ppa_addr ppa)
> 	rqd.ppa_addr = generic_to_dev_addr(dev, ppa);
> 
> 	ret = nvm_submit_io_sync_raw(dev, &rqd);
> -	if (ret)
> -		return ret;
> 
> 	__free_page(page);
> 
> +	if (ret)
> +		return ret;
> +
> 	return rqd.error;
> }
> 
> --
> 2.17.1

You’re right, there is a leak here. Fix looks good to me.

Reviewed-by: Javier González <javier@javigon.com>


[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

      parent reply	other threads:[~2019-09-30  8:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-30  2:34 Navid Emamdoost
2019-09-30  7:16 ` Markus Elfring
2019-09-30  8:06 ` Javier González [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=8FE3FFB7-4FF5-4BF5-B95E-2FECC003702D@javigon.com \
    --to=javier@javigon.com \
    --cc=emamd001@umn.edu \
    --cc=kjlu@umn.edu \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mb@lightnvm.io \
    --cc=navid.emamdoost@gmail.com \
    --cc=smccaman@umn.edu \
    /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®