* [PATCH] lightnvm: prevent memory leak in nvm_bb_chunk_sense
@ 2019-09-30 2:34 Navid Emamdoost
2019-09-30 7:16 ` Markus Elfring
2019-09-30 8:06 ` Javier González
0 siblings, 2 replies; 3+ messages in thread
From: Navid Emamdoost @ 2019-09-30 2:34 UTC (permalink / raw)
Cc: emamd001, smccaman, kjlu, Navid Emamdoost, Matias Bjorling,
linux-block, linux-kernel
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] lightnvm: prevent memory leak in nvm_bb_chunk_sense
2019-09-30 2:34 [PATCH] lightnvm: prevent memory leak in nvm_bb_chunk_sense Navid Emamdoost
@ 2019-09-30 7:16 ` Markus Elfring
2019-09-30 8:06 ` Javier González
1 sibling, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2019-09-30 7:16 UTC (permalink / raw)
To: Navid Emamdoost, linux-block
Cc: Navid Emamdoost, Kangjie Lu, Stephen McCamant, Matias Bjorling,
linux-kernel, kernel-janitors
> To fix this issue I moved the __free_page call before error check.
Would the wording “Move the __free_page() call before the error check.”
be more succinct for the change description?
Can the following code variant be applied at the end of this function?
return ret ? ret : rqd.error;
Regards,
Markus
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] lightnvm: prevent memory leak in nvm_bb_chunk_sense
2019-09-30 2:34 [PATCH] lightnvm: prevent memory leak in nvm_bb_chunk_sense Navid Emamdoost
2019-09-30 7:16 ` Markus Elfring
@ 2019-09-30 8:06 ` Javier González
1 sibling, 0 replies; 3+ messages in thread
From: Javier González @ 2019-09-30 8:06 UTC (permalink / raw)
To: Navid Emamdoost
Cc: emamd001, smccaman, kjlu, Matias Bjørling, linux-block,
linux-kernel
[-- 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 --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-09-30 8:06 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-30 2:34 [PATCH] lightnvm: prevent memory leak in nvm_bb_chunk_sense Navid Emamdoost
2019-09-30 7:16 ` Markus Elfring
2019-09-30 8:06 ` Javier González
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).