diff mbox

[09/26] ARM: OMAP: dmtimer: Get rid of check for mem resource error

Message ID 1398375849-6017-10-git-send-email-joelf@ti.com (mailing list archive)
State New, archived
Headers show

Commit Message

Joel Fernandes April 24, 2014, 9:43 p.m. UTC
The subsequent devm_ioremap_resource will catch it and print an error, let it
be checked there.

Signed-off-by: Joel Fernandes <joelf@ti.com>
---
 arch/arm/plat-omap/dmtimer.c |    4 ----
 1 file changed, 4 deletions(-)

Comments

Tony Lindgren May 7, 2014, 3:24 p.m. UTC | #1
* Joel Fernandes <joelf@ti.com> [140424 14:44]:
> The subsequent devm_ioremap_resource will catch it and print an error, let it
> be checked there.
> 
> Signed-off-by: Joel Fernandes <joelf@ti.com>
> ---
>  arch/arm/plat-omap/dmtimer.c |    4 ----
>  1 file changed, 4 deletions(-)
> 
> diff --git a/arch/arm/plat-omap/dmtimer.c b/arch/arm/plat-omap/dmtimer.c
> index 7e806f9..1fd30fa 100644
> --- a/arch/arm/plat-omap/dmtimer.c
> +++ b/arch/arm/plat-omap/dmtimer.c
> @@ -810,10 +810,6 @@ static int omap_dm_timer_probe(struct platform_device *pdev)
>  	}
>  
>  	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> -	if (unlikely(!mem)) {
> -		dev_err(dev, "%s: no memory resource.\n", __func__);
> -		return -ENODEV;
> -	}
>  
>  	timer = devm_kzalloc(dev, sizeof(struct omap_dm_timer), GFP_KERNEL);
>  	if (!timer) {

We still need to return an error here and not try to continue though.

Tony
Joel Fernandes May 7, 2014, 9:52 p.m. UTC | #2
On 05/07/2014 10:24 AM, Tony Lindgren wrote:
> * Joel Fernandes <joelf@ti.com> [140424 14:44]:
>> The subsequent devm_ioremap_resource will catch it and print an error, let it
>> be checked there.
>>
>> Signed-off-by: Joel Fernandes <joelf@ti.com>
>> ---
>>  arch/arm/plat-omap/dmtimer.c |    4 ----
>>  1 file changed, 4 deletions(-)
>>
>> diff --git a/arch/arm/plat-omap/dmtimer.c b/arch/arm/plat-omap/dmtimer.c
>> index 7e806f9..1fd30fa 100644
>> --- a/arch/arm/plat-omap/dmtimer.c
>> +++ b/arch/arm/plat-omap/dmtimer.c
>> @@ -810,10 +810,6 @@ static int omap_dm_timer_probe(struct platform_device *pdev)
>>  	}
>>  
>>  	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>> -	if (unlikely(!mem)) {
>> -		dev_err(dev, "%s: no memory resource.\n", __func__);
>> -		return -ENODEV;
>> -	}
>>  
>>  	timer = devm_kzalloc(dev, sizeof(struct omap_dm_timer), GFP_KERNEL);
>>  	if (!timer) {
> 
> We still need to return an error here and not try to continue though.

We are returning an error if mem is NULL so the redundant check is
unnecessary:

...
        timer->io_base = devm_ioremap_resource(dev, mem);
        if (IS_ERR(timer->io_base))
                return PTR_ERR(timer->io_base);


thanks,

-Joel
Tony Lindgren May 7, 2014, 10:10 p.m. UTC | #3
* Joel Fernandes <joelf@ti.com> [140507 14:53]:
> On 05/07/2014 10:24 AM, Tony Lindgren wrote:
> > * Joel Fernandes <joelf@ti.com> [140424 14:44]:
> >> The subsequent devm_ioremap_resource will catch it and print an error, let it
> >> be checked there.
> >>
> >> Signed-off-by: Joel Fernandes <joelf@ti.com>
> >> ---
> >>  arch/arm/plat-omap/dmtimer.c |    4 ----
> >>  1 file changed, 4 deletions(-)
> >>
> >> diff --git a/arch/arm/plat-omap/dmtimer.c b/arch/arm/plat-omap/dmtimer.c
> >> index 7e806f9..1fd30fa 100644
> >> --- a/arch/arm/plat-omap/dmtimer.c
> >> +++ b/arch/arm/plat-omap/dmtimer.c
> >> @@ -810,10 +810,6 @@ static int omap_dm_timer_probe(struct platform_device *pdev)
> >>  	}
> >>  
> >>  	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> >> -	if (unlikely(!mem)) {
> >> -		dev_err(dev, "%s: no memory resource.\n", __func__);
> >> -		return -ENODEV;
> >> -	}
> >>  
> >>  	timer = devm_kzalloc(dev, sizeof(struct omap_dm_timer), GFP_KERNEL);
> >>  	if (!timer) {
> > 
> > We still need to return an error here and not try to continue though.
> 
> We are returning an error if mem is NULL so the redundant check is
> unnecessary:
> 
> ...
>         timer->io_base = devm_ioremap_resource(dev, mem);
>         if (IS_ERR(timer->io_base))
>                 return PTR_ERR(timer->io_base);

Why would you want to even continue omap_dm_timer_probe()
further and allocate memory if platform_get_resource() fails?

Tony
Joel Fernandes May 7, 2014, 10:14 p.m. UTC | #4
On 05/07/2014 05:10 PM, Tony Lindgren wrote:
> * Joel Fernandes <joelf@ti.com> [140507 14:53]:
>> On 05/07/2014 10:24 AM, Tony Lindgren wrote:
>>> * Joel Fernandes <joelf@ti.com> [140424 14:44]:
>>>> The subsequent devm_ioremap_resource will catch it and print an error, let it
>>>> be checked there.
>>>>
>>>> Signed-off-by: Joel Fernandes <joelf@ti.com>
>>>> ---
>>>>  arch/arm/plat-omap/dmtimer.c |    4 ----
>>>>  1 file changed, 4 deletions(-)
>>>>
>>>> diff --git a/arch/arm/plat-omap/dmtimer.c b/arch/arm/plat-omap/dmtimer.c
>>>> index 7e806f9..1fd30fa 100644
>>>> --- a/arch/arm/plat-omap/dmtimer.c
>>>> +++ b/arch/arm/plat-omap/dmtimer.c
>>>> @@ -810,10 +810,6 @@ static int omap_dm_timer_probe(struct platform_device *pdev)
>>>>  	}
>>>>  
>>>>  	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>>>> -	if (unlikely(!mem)) {
>>>> -		dev_err(dev, "%s: no memory resource.\n", __func__);
>>>> -		return -ENODEV;
>>>> -	}
>>>>  
>>>>  	timer = devm_kzalloc(dev, sizeof(struct omap_dm_timer), GFP_KERNEL);
>>>>  	if (!timer) {
>>>
>>> We still need to return an error here and not try to continue though.
>>
>> We are returning an error if mem is NULL so the redundant check is
>> unnecessary:
>>
>> ...
>>         timer->io_base = devm_ioremap_resource(dev, mem);
>>         if (IS_ERR(timer->io_base))
>>                 return PTR_ERR(timer->io_base);
> 
> Why would you want to even continue omap_dm_timer_probe()
> further and allocate memory if platform_get_resource() fails?
> 

But its freed anyway on error. I just felt that extra LOC could be
removed. Ideally we should do something like


mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
io_base = devm_ioremap_resource(dev, mem);
if (IS_ERR(io_base))
	return PTR_ERR(io_base);

timer = devm_kzalloc(dev, sizeof(struct omap_dm_timer), GFP_KERNEL);
if (!timer) {
 ...
}
timer->io_base = io_base;


That combines the platform_get_resource and devm_ioremap_resource error
paths into 1 path and avoids redundant checks.. I can do it this way, or
if you want drop the patch entirely, I'm OK with it both ways..

thanks,

-Joel
Tony Lindgren May 7, 2014, 10:22 p.m. UTC | #5
* Joel Fernandes <joelf@ti.com> [140507 15:15]:
> On 05/07/2014 05:10 PM, Tony Lindgren wrote:
> > * Joel Fernandes <joelf@ti.com> [140507 14:53]:
> >> On 05/07/2014 10:24 AM, Tony Lindgren wrote:
> >>> * Joel Fernandes <joelf@ti.com> [140424 14:44]:
> >>>> The subsequent devm_ioremap_resource will catch it and print an error, let it
> >>>> be checked there.
> >>>>
> >>>> Signed-off-by: Joel Fernandes <joelf@ti.com>
> >>>> ---
> >>>>  arch/arm/plat-omap/dmtimer.c |    4 ----
> >>>>  1 file changed, 4 deletions(-)
> >>>>
> >>>> diff --git a/arch/arm/plat-omap/dmtimer.c b/arch/arm/plat-omap/dmtimer.c
> >>>> index 7e806f9..1fd30fa 100644
> >>>> --- a/arch/arm/plat-omap/dmtimer.c
> >>>> +++ b/arch/arm/plat-omap/dmtimer.c
> >>>> @@ -810,10 +810,6 @@ static int omap_dm_timer_probe(struct platform_device *pdev)
> >>>>  	}
> >>>>  
> >>>>  	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> >>>> -	if (unlikely(!mem)) {
> >>>> -		dev_err(dev, "%s: no memory resource.\n", __func__);
> >>>> -		return -ENODEV;
> >>>> -	}
> >>>>  
> >>>>  	timer = devm_kzalloc(dev, sizeof(struct omap_dm_timer), GFP_KERNEL);
> >>>>  	if (!timer) {
> >>>
> >>> We still need to return an error here and not try to continue though.
> >>
> >> We are returning an error if mem is NULL so the redundant check is
> >> unnecessary:
> >>
> >> ...
> >>         timer->io_base = devm_ioremap_resource(dev, mem);
> >>         if (IS_ERR(timer->io_base))
> >>                 return PTR_ERR(timer->io_base);
> > 
> > Why would you want to even continue omap_dm_timer_probe()
> > further and allocate memory if platform_get_resource() fails?
> > 
> 
> But its freed anyway on error. I just felt that extra LOC could be
> removed. Ideally we should do something like
> 
> 
> mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> io_base = devm_ioremap_resource(dev, mem);
> if (IS_ERR(io_base))
> 	return PTR_ERR(io_base);
> 
> timer = devm_kzalloc(dev, sizeof(struct omap_dm_timer), GFP_KERNEL);
> if (!timer) {
>  ...
> }
> timer->io_base = io_base;
> 
> 
> That combines the platform_get_resource and devm_ioremap_resource error
> paths into 1 path and avoids redundant checks.. I can do it this way, or
> if you want drop the patch entirely, I'm OK with it both ways..

Just drop the dev_err if anything. Removing error checking from
function calls is always going to cause people to wonder what's
going on.

Tony
diff mbox

Patch

diff --git a/arch/arm/plat-omap/dmtimer.c b/arch/arm/plat-omap/dmtimer.c
index 7e806f9..1fd30fa 100644
--- a/arch/arm/plat-omap/dmtimer.c
+++ b/arch/arm/plat-omap/dmtimer.c
@@ -810,10 +810,6 @@  static int omap_dm_timer_probe(struct platform_device *pdev)
 	}
 
 	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (unlikely(!mem)) {
-		dev_err(dev, "%s: no memory resource.\n", __func__);
-		return -ENODEV;
-	}
 
 	timer = devm_kzalloc(dev, sizeof(struct omap_dm_timer), GFP_KERNEL);
 	if (!timer) {