net: bcmasp: Use common error handling code in bcmasp_probe()
PATCH 1/1 net: bcmasp: Use common error handling code in bcmasp_probe()
From: Markus Elfring <[email protected]>
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.
--- drivers/net/ethernet/broadcom/asp2/bcmasp.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/net/ethernet/broadcom/asp2/bcmasp.c +6 -4
@@ -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
Quoted 37 lines · Markus Elfring
From: Markus Elfring <[email protected]>
Date: Sun, 5 Nov 2023 17:24:01 +0100Add 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 <[email protected]>--- drivers/net/ethernet/broadcom/asp2/bcmasp.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)drivers/net/ethernet/broadcom/asp2/bcmasp.c +2
-4@@ -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++; }
drivers/net/ethernet/broadcom/asp2/bcmasp.c static int bcmasp_probe(struct platform_device *pdev) · line 1346
Quoted 7 lines
drivers/net/ethernet/broadcom/asp2/bcmasp.c +4
-0@@ -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".
Quoted 7 lines
drivers/net/ethernet/broadcom/asp2/bcmasp.c +0
-1}static void bcmasp_remove (struct platform_device *pdev) --2.42.0
…
Quoted 2 lines
Quoted 2 lines
Add a jump target so that a bit of exception handling can be better reused at the end of this function.
…
Quoted 25 lines
Quoted 25 lines
+++
b/drivers/net/ethernet/broadcom/asp2/bcmasp.cdrivers/net/ethernet/broadcom/asp2/bcmasp.c +2
-4@@ -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);
Quoted 8 lines
drivers/net/ethernet/broadcom/asp2/bcmasp.c static int bcmasp_probe(struct platform_device *pdev) · line 1346
Quoted 5 lines
drivers/net/ethernet/broadcom/asp2/bcmasp.c +4
-0return 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_exitand it will naturally go to theof_node_putcall. No need for "gotoof_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
Wojciech Drewek
Reviewed-byQuoted 38 lines · Markus Elfring
…
Quoted 2 lines
Quoted 2 lines
Add a jump target so that a bit of exception handling can be better reused at the end of this function.
…
Quoted 25 lines
Quoted 25 lines
+++
b/drivers/net/ethernet/broadcom/asp2/bcmasp.cdrivers/net/ethernet/broadcom/asp2/bcmasp.c +2
-4@@ -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);Quoted 8 lines
drivers/net/ethernet/broadcom/asp2/bcmasp.c static int bcmasp_probe(struct platform_device *pdev) · line 1346
Quoted 5 lines
drivers/net/ethernet/broadcom/asp2/bcmasp.c +4
-0return 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_exitand it will naturally go to theof_node_putcall. No need for "gotoof_put_exit".
Quoted 2 lines
I got the impression that the call of the function “bcmasp_remove_intfs” belongs only to exceptional cases in the shown control flow.
Ah, yes, you're right. If we move it above of_put_exit as I suggested then it'll be executed in successful path as well.
Makes sense now
Quoted 3 lines
Regards,
Markus
Jakub Kicinski
maintainerQuoted 7 lines · On Sun, 5 Nov 2023 17:33:46 +0100 Markus Elfring wrote:
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 <[email protected]>--- 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.
Quoted 2 lines
Quoted 2 lines
Add a jump target so that a bit of exception handling can be better reused at the end of this function.
…
Quoted 6 lines
Quoted 3 lines
--- 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
Justin Chen
maintainerQuoted 8 lines · Markus Elfring
Quoted 3 lines
Quoted 3 lines
Add a jump target so that a bit of exception handling can be better reused at the end of this function.
…
Quoted 4 lines
Quoted 3 lines
--- drivers/net/ethernet/broadcom/asp2/bcmasp.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
Quoted 8 lines
Quoted 2 lines
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
We are making the code harder to follow with these changes. Also adding more lines than removing. Don't think this patch is an improvement IMHO. NAK on my end.
Thanks,
Justin
Florian Fainelli
maintainerQuoted 15 lines · Justin Chen
Quoted 14 lines · Markus Elfring
Quoted 3 lines
Quoted 3 lines
Add a jump target so that a bit of exception handling can be better reused at the end of this function.
…
Quoted 6 lines
Quoted 3 lines
--- 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?
Quoted 6 lines
Quoted 2 lines
Regards,
MarkusWe are making the code harder to follow with these changes. Also adding more lines than removing. Don't think this patch is an improvement IMHO. NAK on my end.
Likewise, at the very least, why not have the remove_intfs label immediately above the of_put_exit one so then it just falls through, and then obviously update the return path to drop the reference count and return success?
Signature · 1 line
Florian
PATCH v2 1/1 net: bcmasp: Use common error handling code in bcmasp_probe()
From: Markus Elfring <[email protected]>
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.
---
v2:
Special expectations were expressed for the previous patch size.
* Jakub Kicinski
https://lore.kernel.org/netdev/[email protected]/
* Justin Chen
https://lore.kernel.org/netdev/CALSSxFYRgPwEq+QhCOYPqrtae8RvL=jTOcz4mk3vbe+Fc0QwbQ@mail.gmail.com/
* Florian Fainelli
https://lore.kernel.org/netdev/[email protected]/
Thus another change variant can eventually be integrated.
drivers/net/ethernet/broadcom/asp2/bcmasp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/broadcom/asp2/bcmasp.c +2 -2
@@ -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
Justin Chen
maintainerQuoted 53 lines · Markus Elfring
From: Markus Elfring <[email protected]>
Date: Wed, 15 Nov 2023 09:38:56 +0100Add a jump target so that a bit of exception handling can be better reused in this function implementation.
Signed-off-by Markus Elfring <[email protected]>---
v2:
Special expectations were expressed for the previous patch size.* Jakub Kicinski
https://lore.kernel.org/netdev/[email protected]/* Justin Chen
https://lore.kernel.org/netdev/CALSSxFYRgPwEq+QhCOYPqrtae8RvL=jTOcz4mk3vbe+Fc0QwbQ@mail.gmail.com/* Florian Fainelli
https://lore.kernel.org/netdev/[email protected]/Thus another change variant can eventually be integrated.
drivers/net/ethernet/broadcom/asp2/bcmasp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/net/ethernet/broadcom/asp2/bcmasp.c +2
-3@@ -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; } --
Quoted 2 lines
2.42.1
nak. Doesn't save any lines of code. Doesn't make things clearer or easier to follow. This doesn't seem like an improvement to me.
Justin
Quoted 2 lines
Quoted 2 lines
Add a jump target so that a bit of exception handling can be better reused in this function implementation.
…
Quoted 16 lines
Quoted 16 lines
+++
b/drivers/net/ethernet/broadcom/asp2/bcmasp.cdrivers/net/ethernet/broadcom/asp2/bcmasp.c +1
-2@@ -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);
Quoted 8 lines
Quoted 7 lines
drivers/net/ethernet/broadcom/asp2/bcmasp.c +1
-1+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?
Quoted 1 line
Doesn't make things clearer or easier to follow.
Maybe.
Quoted 1 line
This doesn't seem like an improvement to me.
Can this software implementation benefit from one function call less?
Regards,
Markus