linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -next] net: stmmac: platform: remove useless if/else
@ 2020-10-29  2:33 Zou Wei
  2020-10-29 12:34 ` Andrew Lunn
  0 siblings, 1 reply; 3+ messages in thread
From: Zou Wei @ 2020-10-29  2:33 UTC (permalink / raw)
  To: peppe.cavallaro, alexandre.torgue, joabreu, davem, kuba, mcoquelin.stm32
  Cc: netdev, Zou Wei, linux-stm32, linux-arm-kernel, linux-kernel

Fix the following coccinelle report:

./drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c:233:6-8:
WARNING: possible condition with no effect (if == else)

Both branches are the same, so remove the else if/else altogether.

Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Zou Wei <zou_wei@huawei.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
index af34a4c..f6c69d0 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
@@ -230,8 +230,6 @@ static int stmmac_mtl_setup(struct platform_device *pdev,
 		plat->tx_sched_algorithm = MTL_TX_ALGORITHM_WFQ;
 	else if (of_property_read_bool(tx_node, "snps,tx-sched-dwrr"))
 		plat->tx_sched_algorithm = MTL_TX_ALGORITHM_DWRR;
-	else if (of_property_read_bool(tx_node, "snps,tx-sched-sp"))
-		plat->tx_sched_algorithm = MTL_TX_ALGORITHM_SP;
 	else
 		plat->tx_sched_algorithm = MTL_TX_ALGORITHM_SP;
 
-- 
2.6.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH -next] net: stmmac: platform: remove useless if/else
  2020-10-29  2:33 [PATCH -next] net: stmmac: platform: remove useless if/else Zou Wei
@ 2020-10-29 12:34 ` Andrew Lunn
  2020-10-29 23:01   ` Jakub Kicinski
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Lunn @ 2020-10-29 12:34 UTC (permalink / raw)
  To: Zou Wei
  Cc: alexandre.torgue, netdev, linux-kernel, linux-stm32, joabreu,
	mcoquelin.stm32, kuba, peppe.cavallaro, davem, linux-arm-kernel

On Thu, Oct 29, 2020 at 10:33:52AM +0800, Zou Wei wrote:
> Fix the following coccinelle report:
> 
> ./drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c:233:6-8:
> WARNING: possible condition with no effect (if == else)
> 
> Both branches are the same, so remove the else if/else altogether.
> 
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Zou Wei <zou_wei@huawei.com>
> ---
>  drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c | 2 --
>  1 file changed, 2 deletions(-)
> 
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
> index af34a4c..f6c69d0 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
> @@ -230,8 +230,6 @@ static int stmmac_mtl_setup(struct platform_device *pdev,
>  		plat->tx_sched_algorithm = MTL_TX_ALGORITHM_WFQ;
>  	else if (of_property_read_bool(tx_node, "snps,tx-sched-dwrr"))
>  		plat->tx_sched_algorithm = MTL_TX_ALGORITHM_DWRR;
> -	else if (of_property_read_bool(tx_node, "snps,tx-sched-sp"))
> -		plat->tx_sched_algorithm = MTL_TX_ALGORITHM_SP;
>  	else
>  		plat->tx_sched_algorithm = MTL_TX_ALGORITHM_SP;

I actually prefer the original code. Code is also documentation. It
documents the fact, if "snps,tx-sched-sp" is in device tree, we use
MTL_TX_ALGORITHM_SP, but otherwise we default to MTL_TX_ALGORITHM_SP.

As with my suggestion for forcedeth, i would move the default setting
to before the whole if/else if/else block to document it is the
default.

Or just consider this a false positive and leave it alone. I can see
value in the coccinelle script, but it is going to have a lot of false
positive cases, so i'm not sure there is value in working around them
all.

	Andrew

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH -next] net: stmmac: platform: remove useless if/else
  2020-10-29 12:34 ` Andrew Lunn
@ 2020-10-29 23:01   ` Jakub Kicinski
  0 siblings, 0 replies; 3+ messages in thread
From: Jakub Kicinski @ 2020-10-29 23:01 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: alexandre.torgue, netdev, linux-kernel, linux-stm32, joabreu,
	mcoquelin.stm32, peppe.cavallaro, Zou Wei, davem,
	linux-arm-kernel

On Thu, 29 Oct 2020 13:34:45 +0100 Andrew Lunn wrote:
> On Thu, Oct 29, 2020 at 10:33:52AM +0800, Zou Wei wrote:
> > Fix the following coccinelle report:
> > 
> > ./drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c:233:6-8:
> > WARNING: possible condition with no effect (if == else)
> > 
> > Both branches are the same, so remove the else if/else altogether.
> > 
> > Reported-by: Hulk Robot <hulkci@huawei.com>
> > Signed-off-by: Zou Wei <zou_wei@huawei.com>
> > ---
> >  drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c | 2 --
> >  1 file changed, 2 deletions(-)
> > 
> > diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
> > index af34a4c..f6c69d0 100644
> > --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
> > +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
> > @@ -230,8 +230,6 @@ static int stmmac_mtl_setup(struct platform_device *pdev,
> >  		plat->tx_sched_algorithm = MTL_TX_ALGORITHM_WFQ;
> >  	else if (of_property_read_bool(tx_node, "snps,tx-sched-dwrr"))
> >  		plat->tx_sched_algorithm = MTL_TX_ALGORITHM_DWRR;
> > -	else if (of_property_read_bool(tx_node, "snps,tx-sched-sp"))
> > -		plat->tx_sched_algorithm = MTL_TX_ALGORITHM_SP;
> >  	else
> >  		plat->tx_sched_algorithm = MTL_TX_ALGORITHM_SP;  
> 
> I actually prefer the original code. Code is also documentation. It
> documents the fact, if "snps,tx-sched-sp" is in device tree, we use
> MTL_TX_ALGORITHM_SP, but otherwise we default to MTL_TX_ALGORITHM_SP.
> 
> As with my suggestion for forcedeth, i would move the default setting
> to before the whole if/else if/else block to document it is the
> default.
> 
> Or just consider this a false positive and leave it alone. I can see
> value in the coccinelle script, but it is going to have a lot of false
> positive cases, so i'm not sure there is value in working around them
> all.

Annoyingly this is not the first time this exact patch is submitted :/

I think your forcedeth suggestion is a nice compromise.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2020-10-29 23:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-29  2:33 [PATCH -next] net: stmmac: platform: remove useless if/else Zou Wei
2020-10-29 12:34 ` Andrew Lunn
2020-10-29 23:01   ` Jakub Kicinski

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