net: stmmac: platform: remove useless if/else
Subsystems (4)
PATCH 1/1 net: stmmac: platform: remove useless if/else
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.
--- drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c | 2 -- 1 file changed, 2 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c +0 -2
@@ -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;
Signature · 7 lines
2.6.2 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 18 lines · Zou Wei
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 <[email protected]>Signed-off-by Zou Wei <[email protected]>--- drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c | 2 -- 1 file changed, 2 deletions(-)drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c +0
-0
drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c static int stmmac_mtl_setup(struct platform_device *pdev, · line 234
Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c +0
-2@@ -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
Jakub Kicinski
maintainerQuoted 31 lines · On Thu, 29 Oct 2020 13:34:45 +0100 Andrew Lunn wrote:
Quoted 18 lines · Zou Wei
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 <[email protected]>Signed-off-by Zou Wei <[email protected]>--- drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c | 2 -- 1 file changed, 2 deletions(-)drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c +0
-0drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c static int stmmac_mtl_setup(struct platform_device *pdev, · line 234
Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c +0
-2@@ -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 toMTL_TX_ALGORITHM_SP.
Quoted 8 lines
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
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel