cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
* [cocci] [PATCH] net: bcmasp: Use common error handling code in bcmasp_probe()
@ 2023-11-05 16:33 Markus Elfring
       [not found] ` <83b0921a-5718-4dbf-b9bd-5662e47e3807@intel.com>
       [not found] ` <20231106145806.669875f4@kernel.org>
  0 siblings, 2 replies; 5+ messages in thread
From: Markus Elfring @ 2023-11-05 16:33 UTC (permalink / raw)
  To: Julia Lawall, David S. Miller, Eric Dumazet, Florian Fainelli,
	Jakub Kicinski, Justin Chen, Paolo Abeni,
	bcm-kernel-feedback-list, netdev, kernel-janitors
  Cc: cocci, LKML

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 5 Nov 2023 17:24:01 +0100

Add a jump target so that a bit of exception handling can be better
reused at the end of this function.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/net/ethernet/broadcom/asp2/bcmasp.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp.c b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
index 29b04a274d07..675437e44b94 100644
--- a/drivers/net/ethernet/broadcom/asp2/bcmasp.c
+++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
@@ -1304,9 +1304,8 @@ static int bcmasp_probe(struct platform_device *pdev)
 		intf = bcmasp_interface_create(priv, intf_node, i);
 		if (!intf) {
 			dev_err(dev, "Cannot create eth interface %d\n", i);
-			bcmasp_remove_intfs(priv);
 			of_node_put(intf_node);
-			goto of_put_exit;
+			goto remove_intfs;
 		}
 		list_add_tail(&intf->list, &priv->intfs);
 		i++;
@@ -1331,8 +1330,7 @@ static int bcmasp_probe(struct platform_device *pdev)
 			netdev_err(intf->ndev,
 				   "failed to register net_device: %d\n", ret);
 			priv->destroy_wol(priv);
-			bcmasp_remove_intfs(priv);
-			goto of_put_exit;
+			goto remove_intfs;
 		}
 		count++;
 	}
@@ -1342,6 +1340,10 @@ static int bcmasp_probe(struct platform_device *pdev)
 of_put_exit:
 	of_node_put(ports_node);
 	return ret;
+
+remove_intfs:
+	bcmasp_remove_intfs(priv);
+	goto of_put_exit;
 }

 static void bcmasp_remove(struct platform_device *pdev)
--
2.42.0


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

* Re: [cocci] [PATCH] net: bcmasp: Use common error handling code in bcmasp_probe()
       [not found] ` <83b0921a-5718-4dbf-b9bd-5662e47e3807@intel.com>
@ 2023-11-06 13:55   ` Markus Elfring
  0 siblings, 0 replies; 5+ messages in thread
From: Markus Elfring @ 2023-11-06 13:55 UTC (permalink / raw)
  To: Wojciech Drewek, Julia Lawall, David S. Miller, Eric Dumazet,
	Florian Fainelli, Jakub Kicinski, Justin Chen, Paolo Abeni,
	bcm-kernel-feedback-list, netdev, kernel-janitors
  Cc: cocci, LKML, Simon Horman

…
>> Add a jump target so that a bit of exception handling can be better
>> reused at the end of this function.
>> +++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
>> @@ -1304,9 +1304,8 @@ static int bcmasp_probe(struct platform_device *pdev)
>>  		intf = bcmasp_interface_create(priv, intf_node, i);
>>  		if (!intf) {
>>  			dev_err(dev, "Cannot create eth interface %d\n", i);
>> -			bcmasp_remove_intfs(priv);
>>  			of_node_put(intf_node);
>> -			goto of_put_exit;
>> +			goto remove_intfs;
>>  		}
>>  		list_add_tail(&intf->list, &priv->intfs);
>>  		i++;
>> @@ -1331,8 +1330,7 @@ static int bcmasp_probe(struct platform_device *pdev)
>>  			netdev_err(intf->ndev,
>>  				   "failed to register net_device: %d\n", ret);
>>  			priv->destroy_wol(priv);
>> -			bcmasp_remove_intfs(priv);
>> -			goto of_put_exit;
>> +			goto remove_intfs;
>>  		}
>>  		count++;
>>  	}
>> @@ -1342,6 +1340,10 @@ static int bcmasp_probe(struct platform_device *pdev)
>>  of_put_exit:
>>  	of_node_put(ports_node);
>>  	return ret;
>> +
>> +remove_intfs:
>> +	bcmasp_remove_intfs(priv);
>> +	goto of_put_exit;
>
> Why is it at the end of the function? Just move it above of_put_exit and it will naturally
> go to the of_node_put call. No need for "goto of_put_exit".

I got the impression that the call of the function “bcmasp_remove_intfs” belongs only
to exceptional cases in the shown control flow.

Regards,
Markus

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

* Re: [cocci] net: bcmasp: Use common error handling code in bcmasp_probe()
       [not found] ` <20231106145806.669875f4@kernel.org>
@ 2023-11-07  6:38   ` Markus Elfring
       [not found]     ` <CALSSxFYRgPwEq+QhCOYPqrtae8RvL=jTOcz4mk3vbe+Fc0QwbQ@mail.gmail.com>
  0 siblings, 1 reply; 5+ messages in thread
From: Markus Elfring @ 2023-11-07  6:38 UTC (permalink / raw)
  To: Jakub Kicinski, Wojciech Drewek
  Cc: Julia Lawall, David S. Miller, Eric Dumazet, Florian Fainelli,
	Justin Chen, Paolo Abeni, bcm-kernel-feedback-list, netdev,
	kernel-janitors, cocci, LKML, Simon Horman

>> Add a jump target so that a bit of exception handling can be better
>> reused at the end of this function.
>> ---
>>  drivers/net/ethernet/broadcom/asp2/bcmasp.c | 10 ++++++----
>>  1 file changed, 6 insertions(+), 4 deletions(-)
>
> The diffstat proves otherwise.
> Please don't send such patches to networking.

How does this feedback fit to a change possibility which was reviewed by
Wojciech Drewek yesterday?

Regards,
Markus

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

* [cocci] [PATCH v2] net: bcmasp: Use common error handling code in bcmasp_probe()
       [not found]       ` <4053e838-e5cf-4450-8067-21bdec989d1b@broadcom.com>
@ 2023-11-15  9:10         ` Markus Elfring
       [not found]           ` <CALSSxFYBhv==pJTme0FThxP9JBJszsj1v4G2s-HGzkaevbyvBA@mail.gmail.com>
  0 siblings, 1 reply; 5+ messages in thread
From: Markus Elfring @ 2023-11-15  9:10 UTC (permalink / raw)
  To: Florian Fainelli, Justin Chen, Jakub Kicinski, Wojciech Drewek,
	Julia Lawall, David S. Miller, Eric Dumazet, Paolo Abeni,
	bcm-kernel-feedback-list, netdev, kernel-janitors
  Cc: LKML, cocci, Simon Horman

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 15 Nov 2023 09:38:56 +0100

Add a jump target so that a bit of exception handling can be better reused
in this function implementation.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---

v2:
Special expectations were expressed for the previous patch size.

* Jakub Kicinski
  https://lore.kernel.org/netdev/20231106145806.669875f4@kernel.org/

* Justin Chen
  https://lore.kernel.org/netdev/CALSSxFYRgPwEq+QhCOYPqrtae8RvL=jTOcz4mk3vbe+Fc0QwbQ@mail.gmail.com/

* Florian Fainelli
  https://lore.kernel.org/netdev/4053e838-e5cf-4450-8067-21bdec989d1b@broadcom.com/


Thus another change variant can eventually be integrated.


 drivers/net/ethernet/broadcom/asp2/bcmasp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp.c b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
index 29b04a274d07..7d6c15732d9f 100644
--- a/drivers/net/ethernet/broadcom/asp2/bcmasp.c
+++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
@@ -1304,9 +1304,8 @@ static int bcmasp_probe(struct platform_device *pdev)
 		intf = bcmasp_interface_create(priv, intf_node, i);
 		if (!intf) {
 			dev_err(dev, "Cannot create eth interface %d\n", i);
-			bcmasp_remove_intfs(priv);
 			of_node_put(intf_node);
-			goto of_put_exit;
+			goto remove_intfs;
 		}
 		list_add_tail(&intf->list, &priv->intfs);
 		i++;
@@ -1331,6 +1330,7 @@ static int bcmasp_probe(struct platform_device *pdev)
 			netdev_err(intf->ndev,
 				   "failed to register net_device: %d\n", ret);
 			priv->destroy_wol(priv);
+remove_intfs:
 			bcmasp_remove_intfs(priv);
 			goto of_put_exit;
 		}
--
2.42.1


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

* Re: [cocci] [PATCH v2] net: bcmasp: Use common error handling code in bcmasp_probe()
       [not found]           ` <CALSSxFYBhv==pJTme0FThxP9JBJszsj1v4G2s-HGzkaevbyvBA@mail.gmail.com>
@ 2023-11-16 20:24             ` Markus Elfring
  0 siblings, 0 replies; 5+ messages in thread
From: Markus Elfring @ 2023-11-16 20:24 UTC (permalink / raw)
  To: Justin Chen, bcm-kernel-feedback-list, netdev, kernel-janitors
  Cc: Florian Fainelli, Jakub Kicinski, Wojciech Drewek, Julia Lawall,
	David S. Miller, Eric Dumazet, Paolo Abeni, LKML, cocci,
	Simon Horman

>> Add a jump target so that a bit of exception handling can be better reused
>> in this function implementation.
>> +++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
>> @@ -1304,9 +1304,8 @@ static int bcmasp_probe(struct platform_device *pdev)
>>                 intf = bcmasp_interface_create(priv, intf_node, i);
>>                 if (!intf) {
>>                         dev_err(dev, "Cannot create eth interface %d\n", i);
>> -                       bcmasp_remove_intfs(priv);
>>                         of_node_put(intf_node);
>> -                       goto of_put_exit;
>> +                       goto remove_intfs;
>>                 }
>>                 list_add_tail(&intf->list, &priv->intfs);
>>                 i++;
>> @@ -1331,6 +1330,7 @@ static int bcmasp_probe(struct platform_device *pdev)
>>                         netdev_err(intf->ndev,
>>                                    "failed to register net_device: %d\n", ret);
>>                         priv->destroy_wol(priv);
>> +remove_intfs:
>>                         bcmasp_remove_intfs(priv);
>>                         goto of_put_exit;
>>                 }
>> --
>> 2.42.1
>>
> nak. Doesn't save any lines of code.

Would you get into the mood to take also another look at consequences for executable code?


> Doesn't make things clearer or easier to follow.

Maybe.


> This doesn't seem like an improvement to me.

Can this software implementation benefit from one function call less?

Regards,
Markus

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

end of thread, other threads:[~2023-11-16 20:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-05 16:33 [cocci] [PATCH] net: bcmasp: Use common error handling code in bcmasp_probe() Markus Elfring
     [not found] ` <83b0921a-5718-4dbf-b9bd-5662e47e3807@intel.com>
2023-11-06 13:55   ` Markus Elfring
     [not found] ` <20231106145806.669875f4@kernel.org>
2023-11-07  6:38   ` [cocci] " Markus Elfring
     [not found]     ` <CALSSxFYRgPwEq+QhCOYPqrtae8RvL=jTOcz4mk3vbe+Fc0QwbQ@mail.gmail.com>
     [not found]       ` <4053e838-e5cf-4450-8067-21bdec989d1b@broadcom.com>
2023-11-15  9:10         ` [cocci] [PATCH v2] " Markus Elfring
     [not found]           ` <CALSSxFYBhv==pJTme0FThxP9JBJszsj1v4G2s-HGzkaevbyvBA@mail.gmail.com>
2023-11-16 20:24             ` Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).