* [PATCH -next] lightnvm: fix possible memory leak in pblk_bb_discovery()
@ 2017-04-25 16:15 Wei Yongjun
2017-04-25 16:40 ` Javier González
2017-04-25 16:44 ` Jens Axboe
0 siblings, 2 replies; 3+ messages in thread
From: Wei Yongjun @ 2017-04-25 16:15 UTC (permalink / raw)
To: Matias Bjorling, Javier González; +Cc: Wei Yongjun, linux-block
From: Wei Yongjun <weiyongjun1@huawei.com>
'blks' is malloced in pblk_bb_discovery() and should be freed
before leaving from the nvm_get_tgt_bb_tbl() error handling cases,
otherwise it will cause memory leak. Also skip assign blks to
rlun->bb_list when error.
Fixes: a4bd217b4326 ("lightnvm: physical block device (pblk) target")
Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
---
drivers/lightnvm/pblk-init.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/lightnvm/pblk-init.c b/drivers/lightnvm/pblk-init.c
index 3996e4b..5c8f404 100644
--- a/drivers/lightnvm/pblk-init.c
+++ b/drivers/lightnvm/pblk-init.c
@@ -399,13 +399,15 @@ static int pblk_bb_discovery(struct nvm_tgt_dev *dev, struct pblk_lun *rlun)
nr_blks = nvm_bb_tbl_fold(dev->parent, blks, nr_blks);
if (nr_blks < 0) {
- kfree(blks);
ret = nr_blks;
+ goto out;
}
rlun->bb_list = blks;
+ return 0;
out:
+ kfree(blks);
return ret;
}
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH -next] lightnvm: fix possible memory leak in pblk_bb_discovery()
2017-04-25 16:15 [PATCH -next] lightnvm: fix possible memory leak in pblk_bb_discovery() Wei Yongjun
@ 2017-04-25 16:40 ` Javier González
2017-04-25 16:44 ` Jens Axboe
1 sibling, 0 replies; 3+ messages in thread
From: Javier González @ 2017-04-25 16:40 UTC (permalink / raw)
To: Wei Yongjun; +Cc: Matias Bjørling, Wei Yongjun, linux-block
[-- Attachment #1: Type: text/plain, Size: 579 bytes --]
> On 25 Apr 2017, at 18.15, Wei Yongjun <weiyj.lk@gmail.com> wrote:
>
> From: Wei Yongjun <weiyongjun1@huawei.com>
>
> 'blks' is malloced in pblk_bb_discovery() and should be freed
> before leaving from the nvm_get_tgt_bb_tbl() error handling cases,
> otherwise it will cause memory leak. Also skip assign blks to
> rlun->bb_list when error.
>
> Fixes: a4bd217b4326 ("lightnvm: physical block device (pblk) target")
> Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
> ---
>
Thanks Wei. Looks good.
Reviewed-by: Javier González <javier@cnexlabs.com>
[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 801 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH -next] lightnvm: fix possible memory leak in pblk_bb_discovery()
2017-04-25 16:15 [PATCH -next] lightnvm: fix possible memory leak in pblk_bb_discovery() Wei Yongjun
2017-04-25 16:40 ` Javier González
@ 2017-04-25 16:44 ` Jens Axboe
1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2017-04-25 16:44 UTC (permalink / raw)
To: Wei Yongjun, Matias Bjorling, Javier González
Cc: Wei Yongjun, linux-block
On 04/25/2017 09:15 AM, Wei Yongjun wrote:
> From: Wei Yongjun <weiyongjun1@huawei.com>
>
> 'blks' is malloced in pblk_bb_discovery() and should be freed
> before leaving from the nvm_get_tgt_bb_tbl() error handling cases,
> otherwise it will cause memory leak. Also skip assign blks to
> rlun->bb_list when error.
Added for 4.12, thanks.
--
Jens Axboe
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-04-25 16:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-04-25 16:15 [PATCH -next] lightnvm: fix possible memory leak in pblk_bb_discovery() Wei Yongjun
2017-04-25 16:40 ` Javier González
2017-04-25 16:44 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox