public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: ibm: emac: Fix some error handling path in 'emac_probe()'
@ 2017-08-18 23:07 Christophe JAILLET
  2017-08-19 13:22 ` Christian Lamparter
  0 siblings, 1 reply; 3+ messages in thread
From: Christophe JAILLET @ 2017-08-18 23:07 UTC (permalink / raw)
  To: davem, chunkeey, jarod, ivan, ebiggers, tklauser, tremyfr, robh
  Cc: netdev, linux-kernel, kernel-janitors, Christophe JAILLET

If 'irq_of_parse_and_map()' or 'of_address_to_resource()' fail, 'err' is
known to be 0 at this point.
So return -ENODEV instead in the first case and propagate the error
returned by 'of_address_to_resource()' in the 2nd case.

While at it, turn a 'err != 0' test into an equivalent 'err' to be more
consistent.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/net/ethernet/ibm/emac/core.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/ibm/emac/core.c b/drivers/net/ethernet/ibm/emac/core.c
index 95135d20458f..1af56a97fb47 100644
--- a/drivers/net/ethernet/ibm/emac/core.c
+++ b/drivers/net/ethernet/ibm/emac/core.c
@@ -3032,7 +3032,7 @@ static int emac_probe(struct platform_device *ofdev)
 
 	/* Init various config data based on device-tree */
 	err = emac_init_config(dev);
-	if (err != 0)
+	if (err)
 		goto err_free;
 
 	/* Get interrupts. EMAC irq is mandatory, WOL irq is optional */
@@ -3040,12 +3040,14 @@ static int emac_probe(struct platform_device *ofdev)
 	dev->wol_irq = irq_of_parse_and_map(np, 1);
 	if (!dev->emac_irq) {
 		printk(KERN_ERR "%pOF: Can't map main interrupt\n", np);
+		err = -ENODEV;
 		goto err_free;
 	}
 	ndev->irq = dev->emac_irq;
 
 	/* Map EMAC regs */
-	if (of_address_to_resource(np, 0, &dev->rsrc_regs)) {
+	err = of_address_to_resource(np, 0, &dev->rsrc_regs);
+	if (err) {
 		printk(KERN_ERR "%pOF: Can't get registers address\n", np);
 		goto err_irq_unmap;
 	}
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] net: ibm: emac: Fix some error handling path in 'emac_probe()'
  2017-08-18 23:07 [PATCH] net: ibm: emac: Fix some error handling path in 'emac_probe()' Christophe JAILLET
@ 2017-08-19 13:22 ` Christian Lamparter
  2017-08-20  4:41   ` Christophe JAILLET
  0 siblings, 1 reply; 3+ messages in thread
From: Christian Lamparter @ 2017-08-19 13:22 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: davem, jarod, ivan, ebiggers, tklauser, tremyfr, robh, netdev,
	linux-kernel, kernel-janitors

On Saturday, August 19, 2017 1:07:57 AM CEST Christophe JAILLET wrote:
> If 'irq_of_parse_and_map()' or 'of_address_to_resource()' fail, 'err' is
> known to be 0 at this point.
> So return -ENODEV instead in the first case and propagate the error
> returned by 'of_address_to_resource()' in the 2nd case.
> 
> While at it, turn a 'err != 0' test into an equivalent 'err' to be more
> consistent.
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
>  drivers/net/ethernet/ibm/emac/core.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ethernet/ibm/emac/core.c b/drivers/net/ethernet/ibm/emac/core.c
> index 95135d20458f..1af56a97fb47 100644
> --- a/drivers/net/ethernet/ibm/emac/core.c
> +++ b/drivers/net/ethernet/ibm/emac/core.c
> [...]
>  	/* Map EMAC regs */
> -	if (of_address_to_resource(np, 0, &dev->rsrc_regs)) {
> +	err = of_address_to_resource(np, 0, &dev->rsrc_regs);
> +	if (err) {
>  		printk(KERN_ERR "%pOF: Can't get registers address\n", np);
>  		goto err_irq_unmap;
>  	}
>  // TODO : request_mem_region
>  dev->emacp = ioremap(dev->rsrc_regs.start,
>                       resource_size(&dev->rsrc_regs));
>  ...

If you want to go for 101%: you could get rid of this block
altogether by doing: 
	dev->emacp = of_iomap(np, 0);

Note1:
This will also make the rsrc_regs variable in the emac_instance
struct redundant. So simply remove it from the core.h.

Note2: if you want to go for 110%, you could replace this with
platform_get_resource() and devm_ioremap_resource() (if you
are interested, take a look at devm_ioremap_resource's kdoc
it has an example).

Thanks,
Christian

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] net: ibm: emac: Fix some error handling path in 'emac_probe()'
  2017-08-19 13:22 ` Christian Lamparter
@ 2017-08-20  4:41   ` Christophe JAILLET
  0 siblings, 0 replies; 3+ messages in thread
From: Christophe JAILLET @ 2017-08-20  4:41 UTC (permalink / raw)
  To: Christian Lamparter
  Cc: davem, jarod, ivan, ebiggers, tklauser, tremyfr, robh, netdev,
	linux-kernel, kernel-janitors

Le 19/08/2017 à 15:22, Christian Lamparter a écrit :
> On Saturday, August 19, 2017 1:07:57 AM CEST Christophe JAILLET wrote:
>> If 'irq_of_parse_and_map()' or 'of_address_to_resource()' fail, 'err' is
>> known to be 0 at this point.
>> So return -ENODEV instead in the first case and propagate the error
>> returned by 'of_address_to_resource()' in the 2nd case.
>>
>> While at it, turn a 'err != 0' test into an equivalent 'err' to be more
>> consistent.
>>
>> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
>> ---
>>   drivers/net/ethernet/ibm/emac/core.c | 6 ++++--
>>   1 file changed, 4 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/ibm/emac/core.c b/drivers/net/ethernet/ibm/emac/core.c
>> index 95135d20458f..1af56a97fb47 100644
>> --- a/drivers/net/ethernet/ibm/emac/core.c
>> +++ b/drivers/net/ethernet/ibm/emac/core.c
>> [...]
>>   	/* Map EMAC regs */
>> -	if (of_address_to_resource(np, 0, &dev->rsrc_regs)) {
>> +	err = of_address_to_resource(np, 0, &dev->rsrc_regs);
>> +	if (err) {
>>   		printk(KERN_ERR "%pOF: Can't get registers address\n", np);
>>   		goto err_irq_unmap;
>>   	}
>>   // TODO : request_mem_region
>>   dev->emacp = ioremap(dev->rsrc_regs.start,
>>                        resource_size(&dev->rsrc_regs));
>>   ...
> If you want to go for 101%: you could get rid of this block
> altogether by doing:
> 	dev->emacp = of_iomap(np, 0);
>
> Note1:
> This will also make the rsrc_regs variable in the emac_instance
> struct redundant. So simply remove it from the core.h.
>
> Note2: if you want to go for 110%, you could replace this with
> platform_get_resource() and devm_ioremap_resource() (if you
> are interested, take a look at devm_ioremap_resource's kdoc
> it has an example).
>
> Thanks,
> Christian
>
Hi,

Thanks for the review and comments.

I've sent a v2 to go for 101% which axes some lines of code.

I won't propose anything for your other proposal. Sounds great but 
involves more changes in the error handling path and in the remove function.
I don't have the hardware, so I won't be able to test this bigger change.

Christophe

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-08-20  4:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-18 23:07 [PATCH] net: ibm: emac: Fix some error handling path in 'emac_probe()' Christophe JAILLET
2017-08-19 13:22 ` Christian Lamparter
2017-08-20  4:41   ` Christophe JAILLET

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox