diff mbox

[2/2] lightnvm: fix bad back free on error path

Message ID 1493803145-18082-2-git-send-email-javier@cnexlabs.com (mailing list archive)
State New, archived
Headers show

Commit Message

=?UTF-8?q?Javier=20Gonz=C3=A1lez?= May 3, 2017, 9:19 a.m. UTC
Free memory correctly when an allocation fails on a loop and we free
backwards previously successful allocations.

Signed-off-by: Javier González <javier@cnexlabs.com>
---
 drivers/lightnvm/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Matias Bjørling May 4, 2017, 8:04 a.m. UTC | #1
On 05/03/2017 11:19 AM, Javier González wrote:
> Free memory correctly when an allocation fails on a loop and we free
> backwards previously successful allocations.
>
> Signed-off-by: Javier González <javier@cnexlabs.com>
> ---
>  drivers/lightnvm/core.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
> index 54a06c3a2b8c..6a4aa608ad95 100644
> --- a/drivers/lightnvm/core.c
> +++ b/drivers/lightnvm/core.c
> @@ -74,7 +74,7 @@ static int nvm_reserve_luns(struct nvm_dev *dev, int lun_begin, int lun_end)
>
>  	return 0;
>  err:
> -	while (--i > lun_begin)
> +	while (--i >= lun_begin)
>  		clear_bit(i, dev->lun_map);
>
>  	return -EBUSY;
> @@ -211,7 +211,7 @@ static struct nvm_tgt_dev *nvm_create_tgt_dev(struct nvm_dev *dev,
>
>  	return tgt_dev;
>  err_ch:
> -	while (--i > 0)
> +	while (--i >= 0)
>  		kfree(dev_map->chnls[i].lun_offs);
>  	kfree(luns);
>  err_luns:
>

Reviewed-by: Matias Bjørling <matias@cnexlabs.com>

Jens, and this baby as well? :)
Christoph Hellwig May 4, 2017, 11:27 a.m. UTC | #2
Looks fine,

Reviewed-by: Christoph Hellwig <hch@lst.de>
diff mbox

Patch

diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
index 54a06c3a2b8c..6a4aa608ad95 100644
--- a/drivers/lightnvm/core.c
+++ b/drivers/lightnvm/core.c
@@ -74,7 +74,7 @@  static int nvm_reserve_luns(struct nvm_dev *dev, int lun_begin, int lun_end)
 
 	return 0;
 err:
-	while (--i > lun_begin)
+	while (--i >= lun_begin)
 		clear_bit(i, dev->lun_map);
 
 	return -EBUSY;
@@ -211,7 +211,7 @@  static struct nvm_tgt_dev *nvm_create_tgt_dev(struct nvm_dev *dev,
 
 	return tgt_dev;
 err_ch:
-	while (--i > 0)
+	while (--i >= 0)
 		kfree(dev_map->chnls[i].lun_offs);
 	kfree(luns);
 err_luns: