2009-07-30 12:49:51

by Stoyan Gaydarov

[permalink] [raw]
Subject: Re: [PATCH] [mtd] fixed faulty check

Resubmit of a patch with some additions, see http://lkml.org/lkml/2009/7/30/97

Signed-off-by: Stoyan Gaydarov <[email protected]>
---
drivers/mtd/maps/physmap_of.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/drivers/mtd/maps/physmap_of.c b/drivers/mtd/maps/physmap_of.c
index 39d357b..e7ab5f0 100644
--- a/drivers/mtd/maps/physmap_of.c
+++ b/drivers/mtd/maps/physmap_of.c
@@ -215,7 +215,8 @@ static int __devinit of_flash_probe(struct of_device *dev,
goto err_out;

mtd_list = kzalloc(sizeof(struct mtd_info) * count, GFP_KERNEL);
- if (!info)
+ if (!mtd_list)
+ kfree(info);
goto err_out;

dev_set_drvdata(&dev->dev, info);
--
1.6.3.3


Subject: Re: [PATCH] [mtd] fixed faulty check

Stoyan Gaydarov wrote:
> Resubmit of a patch with some additions, see http://lkml.org/lkml/2009/7/30/97
>
Please add a description of the path here. That's the place where people
are looking for them. The link might be a an additional reference.

> Signed-off-by: Stoyan Gaydarov <[email protected]>
> ---
> drivers/mtd/maps/physmap_of.c | 3 ++-
> 1 files changed, 2 insertions(+), 1 deletions(-)
>
> diff --git a/drivers/mtd/maps/physmap_of.c b/drivers/mtd/maps/physmap_of.c
> index 39d357b..e7ab5f0 100644
> --- a/drivers/mtd/maps/physmap_of.c
> +++ b/drivers/mtd/maps/physmap_of.c
> @@ -215,7 +215,8 @@ static int __devinit of_flash_probe(struct of_device *dev,
> goto err_out;
>
> mtd_list = kzalloc(sizeof(struct mtd_info) * count, GFP_KERNEL);
> - if (!info)
> + if (!mtd_list)
> + kfree(info);
> goto err_out;

This is not python, you have to be explicit about braces. Now your code
looks like this:

mtd_list = kzalloc(sizeof(struct mtd_info) * count, GFP_KERNEL);
if (!mtd_list)
kfree(info);
goto err_out;
>
> dev_set_drvdata(&dev->dev, info);


Sebastian

2009-07-30 13:39:30

by Vimal Singh

[permalink] [raw]
Subject: Re: [PATCH] [mtd] fixed faulty check

On Thu, Jul 30, 2009 at 6:33 PM, Sebastian Andrzej
Siewior<[email protected]> wrote:
> Stoyan Gaydarov wrote:
>>
>> Resubmit of a patch with some additions, see
>> http://lkml.org/lkml/2009/7/30/97
>>
> Please add a description of the path here. That's the place where people
> are looking for them. The link might be a an additional reference.
>
>> Signed-off-by: Stoyan Gaydarov <[email protected]>
>> ---
>> ?drivers/mtd/maps/physmap_of.c | ? ?3 ++-
>> ?1 files changed, 2 insertions(+), 1 deletions(-)
>>
>> diff --git a/drivers/mtd/maps/physmap_of.c b/drivers/mtd/maps/physmap_of.c
>> index 39d357b..e7ab5f0 100644
>> --- a/drivers/mtd/maps/physmap_of.c
>> +++ b/drivers/mtd/maps/physmap_of.c
>> @@ -215,7 +215,8 @@ static int __devinit of_flash_probe(struct of_device
>> *dev,
>> ? ? ? ? ? ? ? ?goto err_out;
>> ? ? ? ? ?mtd_list = kzalloc(sizeof(struct mtd_info) * count, GFP_KERNEL);
>> - ? ? ? if (!info)
>> + ? ? ? if (!mtd_list)
>> + ? ? ? ? ? ? ? kfree(info);
>> ? ? ? ? ? ? ? ?goto err_out;

What if you go to 'err_out' due to some other error?? Do not you need
to free 'info'?
So, better free it in at the label.

Currently label is like below, which is again incorrect.
-----code snippet (line 339)-----
err_out:
kfree(mtd_list);
of_flash_remove(dev);
-------------------------------------------
Think about when you get jump to this label even before 'mtd_list' is
allocated. This is the scenario of null pointer dereferencing.

So, this requires two separate labels:
-one label for errors which occur before 'mtd_list' memory allocation
-and, another for then onward errors

something like below:

err_out2:
kfree(info);
kfree(mtd_list);
err_out1:
of_flash_remove(dev);

-vimal

>
> This is not python, you have to be explicit about braces. Now your code
> looks like this:
>
> ? ? ? ?mtd_list = kzalloc(sizeof(struct mtd_info) * count, GFP_KERNEL);
> ? ? ? ?if (!mtd_list)
> ? ? ? ? ? ? ? ?kfree(info);
> ? ? ? ?goto err_out;
>>
>> ? ? ? ? ?dev_set_drvdata(&dev->dev, info);
>
>
> Sebastian
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at ?http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at ?http://www.tux.org/lkml/
>



--
---
Regards,
\/ | |\/| /-\ |_

____ __o
------ -\<,
----- ( )/ ( )

Subject: Re: [PATCH] [mtd] fixed faulty check

vimal singh wrote:
> What if you go to 'err_out' due to some other error?? Do not you need
> to free 'info'?
We have to and of_flash_remove() takes care of it.

The initial patch would be shorter if
dev_set_drvdata(&dev->dev, info);
would be moved prior the kzalloc()

Sebastian

2009-07-30 14:15:08

by Vimal Singh

[permalink] [raw]
Subject: Re: [PATCH] [mtd] fixed faulty check

On Thu, Jul 30, 2009 at 7:17 PM, Sebastian Andrzej
Siewior<[email protected]> wrote:
> vimal singh wrote:
>>
>> What if you go to 'err_out' due to some other error?? Do not you need
>> to free 'info'?
>
> We have to and of_flash_remove() takes care of it.

that's correct...

>
> The initial patch would be shorter if
> ?dev_set_drvdata(&dev->dev, info);
> would be moved prior the kzalloc()
>
> Sebastian
>



--
---
Regards,
\/ | |\/| /-\ |_

____ __o
------ -\<,
----- ( )/ ( )