Skip to contentSkip to conversation

icplus: mdio_write(), remove unnecessary for loop

PATCH Applied Patrick Kelle 3 participants 3 messages Dec 1, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 icplus: mdio_write(), remove unnecessary for loop

At this point the variable j is always set to 7 and the code within the loop has to run only once anyway.

As suggested by David Miller:
"You can simply this even further since p[7] is what is used here, and this means len is one, the inner loop therefore executes only once, and the p[7].field value is not used (it's zero in the table) and the write to it is completely thrown away."

---
 drivers/net/ethernet/icplus/ipg.c |   13 +++----------
 1 files changed, 3 insertions(+), 10 deletions(-)
drivers/net/ethernet/icplus/ipg.c +3 -10
index 8fd80a0..075451d 100644
@@ -371,16 +371,9 @@ static void mdio_write(struct net_device *dev, int phy_id, int phy_reg, int val)
 	}
 
 	/* The last cycle is a tri-state, so read from the PHY. */
-	for (j = 7; j < 8; j++) {
-		for (i = 0; i < p[j].len; i++) {
-			ipg_write_phy_ctl(ioaddr, IPG_PC_MGMTCLK_LO | polarity);
-
-			p[j].field |= ((ipg_r8(PHY_CTRL) &
-				IPG_PC_MGMTDATA) >> 1) << (p[j].len - 1 - i);
-
-			ipg_write_phy_ctl(ioaddr, IPG_PC_MGMTCLK_HI | polarity);
-		}
-	}
+	ipg_write_phy_ctl(ioaddr, IPG_PC_MGMTCLK_LO | polarity);
+	ipg_r8(PHY_CTRL);
+	ipg_write_phy_ctl(ioaddr, IPG_PC_MGMTCLK_HI | polarity);
 }
 
 static void ipg_set_led_mode(struct net_device *dev)
Signature · 1 line
1.7.7.1
maintainer Applied
#1 lore raw

From: Patrick Kelle <[email protected]>
Date: Thu, 1 Dec 2011 14:26:56 +0100

Quoted 10 lines

At this point the variable j is always set to 7 and the code within the loop has to run only once anyway.

As suggested by David Miller:
"You can simply this even further since p[7] is what is used here, and this means len is one, the inner loop therefore executes only once, and the p[7].field value is not used (it's zero in the table) and the write to it is completely thrown away."

Applied.

Acked-by on v2 1/1
#2 lore raw
In reply to Patrick Kelle

Patrick Kelle <[email protected]> :
[...]

Quoted 5 lines

As suggested by David Miller:
"You can simply this even further since p[7] is what is used here, and this means len is one, the inner loop therefore executes only once, and the p[7].field value is not used (it's zero in the table) and the write to it is completely thrown away."

However you can:
- shorten p[] as p[7] is never used
- use read_phy_bit() to avoid the last three lines
- ARRAY_SIZE(p) the first loop (so the first limit - 7 - appears)

Signature · 1 line
Ueimor