diff mbox series

net: bcmasp: Use common error handling code in bcmasp_probe()

Message ID 0b2972cb-03b2-40c7-a728-6ebe2512637f@web.de (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series net: bcmasp: Use common error handling code in bcmasp_probe() | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1350 this patch: 1350
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 1378 this patch: 1378
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1378 this patch: 1378
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 29 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Markus Elfring Nov. 5, 2023, 4:33 p.m. UTC
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(-)

--
2.42.0

Comments

Wojciech Drewek Nov. 6, 2023, 10:02 a.m. UTC | #1
On 05.11.2023 17:33, Markus Elfring wrote:
> 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;

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".

>  }
> 
>  static void bcmasp_remove(struct platform_device *pdev)
> --
> 2.42.0
> 
>
Markus Elfring Nov. 6, 2023, 1:55 p.m. UTC | #2
>> 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
Wojciech Drewek Nov. 6, 2023, 2:24 p.m. UTC | #3
On 06.11.2023 14:55, Markus Elfring wrote:
> …
>>> 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.

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
Reviewed-by: Wojciech Drewek <wojciech.drewek@intel.com>

> 
> Regards,
> Markus
Jakub Kicinski Nov. 6, 2023, 10:58 p.m. UTC | #4
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 <elfring@users.sourceforge.net>
> ---
>  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.
Markus Elfring Nov. 7, 2023, 6:38 a.m. UTC | #5
>> 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
Justin Chen Nov. 7, 2023, 6:48 p.m. UTC | #6
On Mon, Nov 6, 2023 at 10:38 PM Markus Elfring <Markus.Elfring@web.de> wrote:
>
> >> 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

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 Nov. 8, 2023, 5:46 p.m. UTC | #7
On 11/7/23 10:48, Justin Chen wrote:
> On Mon, Nov 6, 2023 at 10:38 PM Markus Elfring <Markus.Elfring@web.de> wrote:
>>
>>>> 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
> 
> 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.

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?
diff mbox series

Patch

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)