diff mbox

lightnvm: pblk: fix error path in pblk_lines_alloc_metadata

Message ID 20170920195019.GA25759@dhcp-216.srv.tuxera.com (mailing list archive)
State New, archived
Headers show

Commit Message

Rakesh Pandit Sept. 20, 2017, 7:50 p.m. UTC
Use appropriate memory free calls based on allocation type used and
also fix number of times free is called if kmalloc fails.

Signed-off-by: Rakesh Pandit <rakesh@tuxera.com>
---
 drivers/lightnvm/pblk-init.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

=?UTF-8?q?Javier=20Gonz=C3=A1lez?= Sept. 21, 2017, 9:56 a.m. UTC | #1
> On 20 Sep 2017, at 21.50, Rakesh Pandit <rakesh@tuxera.com> wrote:
> 
> Use appropriate memory free calls based on allocation type used and
> also fix number of times free is called if kmalloc fails.
> 
> Signed-off-by: Rakesh Pandit <rakesh@tuxera.com>
> ---
> drivers/lightnvm/pblk-init.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/lightnvm/pblk-init.c b/drivers/lightnvm/pblk-init.c
> index 7cf4b53..470ef04 100644
> --- a/drivers/lightnvm/pblk-init.c
> +++ b/drivers/lightnvm/pblk-init.c
> @@ -624,12 +624,16 @@ static int pblk_lines_alloc_metadata(struct pblk *pblk)
> 
> fail_free_emeta:
> 	while (--i >= 0) {
> -		vfree(l_mg->eline_meta[i]->buf);
> +		if (l_mg->emeta_alloc_type == PBLK_VMALLOC_META)
> +			vfree(l_mg->eline_meta[i]->buf);
> +		else
> +			kfree(l_mg->eline_meta[i]->buf);
> 		kfree(l_mg->eline_meta[i]);
> 	}
> 
> +	i = PBLK_DATA_LINES;
> fail_free_smeta:
> -	for (i = 0; i < PBLK_DATA_LINES; i++)
> +	while (--i >= 0)
> 		kfree(l_mg->sline_meta[i]);

It is safe to use kfree on NULL pointers. No need to do this. You can
either send a new patch, or we can change it when picking it up.

> 
> 	return -ENOMEM;
> --
> 2.5.0

Rest looks good.


Reviewed-by: Javier González <javier@cnexlabs.com>
Rakesh Pandit Sept. 21, 2017, 10:15 a.m. UTC | #2
On Thu, Sep 21, 2017 at 11:56:46AM +0200, Javier González wrote:
> > On 20 Sep 2017, at 21.50, Rakesh Pandit <rakesh@tuxera.com> wrote:
> > 
> > Use appropriate memory free calls based on allocation type used and
> > also fix number of times free is called if kmalloc fails.
> > 
> > Signed-off-by: Rakesh Pandit <rakesh@tuxera.com>
> > ---
> > drivers/lightnvm/pblk-init.c | 8 ++++++--
> > 1 file changed, 6 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/lightnvm/pblk-init.c b/drivers/lightnvm/pblk-init.c
> > index 7cf4b53..470ef04 100644
> > --- a/drivers/lightnvm/pblk-init.c
> > +++ b/drivers/lightnvm/pblk-init.c
> > @@ -624,12 +624,16 @@ static int pblk_lines_alloc_metadata(struct pblk *pblk)
> > 
> > fail_free_emeta:
> > 	while (--i >= 0) {
> > -		vfree(l_mg->eline_meta[i]->buf);
> > +		if (l_mg->emeta_alloc_type == PBLK_VMALLOC_META)
> > +			vfree(l_mg->eline_meta[i]->buf);
> > +		else
> > +			kfree(l_mg->eline_meta[i]->buf);
> > 		kfree(l_mg->eline_meta[i]);
> > 	}
> > 
> > +	i = PBLK_DATA_LINES;
> > fail_free_smeta:
> > -	for (i = 0; i < PBLK_DATA_LINES; i++)
> > +	while (--i >= 0)
> > 		kfree(l_mg->sline_meta[i]);
> 
> It is safe to use kfree on NULL pointers. No need to do this. You can
> either send a new patch, or we can change it when picking it up.

Yes, that would be great if this is adjusted while picking up.

> 
> > 
> > 	return -ENOMEM;
> > --
> > 2.5.0
> 
> Rest looks good.
> 
> 
> Reviewed-by: Javier González <javier@cnexlabs.com>
> 

Thanks,
Matias Bjorling Sept. 21, 2017, 11:14 a.m. UTC | #3
On 09/21/2017 12:15 PM, Rakesh Pandit wrote:
> On Thu, Sep 21, 2017 at 11:56:46AM +0200, Javier González wrote:
>>> On 20 Sep 2017, at 21.50, Rakesh Pandit <rakesh@tuxera.com> wrote:
>>>
>>> Use appropriate memory free calls based on allocation type used and
>>> also fix number of times free is called if kmalloc fails.
>>>
>>> Signed-off-by: Rakesh Pandit <rakesh@tuxera.com>
>>> ---
>>> drivers/lightnvm/pblk-init.c | 8 ++++++--
>>> 1 file changed, 6 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/lightnvm/pblk-init.c b/drivers/lightnvm/pblk-init.c
>>> index 7cf4b53..470ef04 100644
>>> --- a/drivers/lightnvm/pblk-init.c
>>> +++ b/drivers/lightnvm/pblk-init.c
>>> @@ -624,12 +624,16 @@ static int pblk_lines_alloc_metadata(struct pblk *pblk)
>>>
>>> fail_free_emeta:
>>> 	while (--i >= 0) {
>>> -		vfree(l_mg->eline_meta[i]->buf);
>>> +		if (l_mg->emeta_alloc_type == PBLK_VMALLOC_META)
>>> +			vfree(l_mg->eline_meta[i]->buf);
>>> +		else
>>> +			kfree(l_mg->eline_meta[i]->buf);
>>> 		kfree(l_mg->eline_meta[i]);
>>> 	}
>>>
>>> +	i = PBLK_DATA_LINES;
>>> fail_free_smeta:
>>> -	for (i = 0; i < PBLK_DATA_LINES; i++)
>>> +	while (--i >= 0)
>>> 		kfree(l_mg->sline_meta[i]);
>>
>> It is safe to use kfree on NULL pointers. No need to do this. You can
>> either send a new patch, or we can change it when picking it up.
> 
> Yes, that would be great if this is adjusted while picking up.
> 
>>
>>>
>>> 	return -ENOMEM;
>>> --
>>> 2.5.0
>>
>> Rest looks good.
>>
>>
>> Reviewed-by: Javier González <javier@cnexlabs.com>
>>
> 
> Thanks,
> 

Thanks Rakesh. I queued it up.
diff mbox

Patch

diff --git a/drivers/lightnvm/pblk-init.c b/drivers/lightnvm/pblk-init.c
index 7cf4b53..470ef04 100644
--- a/drivers/lightnvm/pblk-init.c
+++ b/drivers/lightnvm/pblk-init.c
@@ -624,12 +624,16 @@  static int pblk_lines_alloc_metadata(struct pblk *pblk)
 
 fail_free_emeta:
 	while (--i >= 0) {
-		vfree(l_mg->eline_meta[i]->buf);
+		if (l_mg->emeta_alloc_type == PBLK_VMALLOC_META)
+			vfree(l_mg->eline_meta[i]->buf);
+		else
+			kfree(l_mg->eline_meta[i]->buf);
 		kfree(l_mg->eline_meta[i]);
 	}
 
+	i = PBLK_DATA_LINES;
 fail_free_smeta:
-	for (i = 0; i < PBLK_DATA_LINES; i++)
+	while (--i >= 0)
 		kfree(l_mg->sline_meta[i]);
 
 	return -ENOMEM;