Skip to contentSkip to conversation

phy: fix crash in fixed_phy_add()

PATCH Applied Rabin Vincent 3 participants 3 messages May 18, 2016 – May 20, 2016

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

PATCH v3 1/1 phy: fix crash in fixed_phy_add()

From: Rabin Vincent <[email protected]>

Since e7f4dc3536a ("mdio: Move allocation of interrupts into core"), platforms which call fixed_phy_add() before fixed_mdio_bus_init() is called (for example, because the platform code and the fixed_phy driver use the same initcall level) crash in fixed_phy_add() since the ->mii_bus is not allocated.

Also since e7f4dc3536a, these interrupts are initalized to polling by default. The few (old) platforms which directly use fixed_phy_add() from their platform code all pass PHY_POLL for the irq argument, so we can keep these platforms not crashing by simply not attempting to set the irq if PHY_POLL is passed.

Also, even if problems have not been reported on more modern platforms which used fixed_phy_register() from drivers' probe functions, we return -EPROBE_DEFER if the MDIO bus is not yet registered so that the probe is retried later.

Fixes e7f4dc3536a400 ("mdio: Move allocation of interrupts into core")

---
v3: One more suggestion from Andrew: check mii bus state

 drivers/net/phy/fixed_phy.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/net/phy/fixed_phy.c +5 -1
index fc07a88..e7dcda6 100644
@@ -255,7 +255,8 @@ int fixed_phy_add(unsigned int irq, int phy_addr,
 
 	memset(fp->regs, 0xFF,  sizeof(fp->regs[0]) * MII_REGS_NUM);
 
-	fmb->mii_bus->irq[phy_addr] = irq;
+	if (irq != PHY_POLL)
+		fmb->mii_bus->irq[phy_addr] = irq;
 
 	fp->addr = phy_addr;
 	fp->status = *status;
@@ -314,6 +315,9 @@ struct phy_device *fixed_phy_register(unsigned int irq,
 	int phy_addr;
 	int ret;
 
+	if (!fmb->mii_bus || fmb->mii_bus->state != MDIOBUS_REGISTERED)
+		return ERR_PTR(-EPROBE_DEFER);
+
 	/* Get the next available PHY address, up to PHY_MAX_ADDR */
 	spin_lock(&phy_fixed_addr_lock);
 	if (phy_fixed_addr == PHY_MAX_ADDR) {
Signature · 1 line
2.1.4
maintainer Reviewed-by on v3 1/1
#1 lore raw
Quoted 14 lines · Rabin Vincent

From: Rabin Vincent <[email protected]>

Since e7f4dc3536a ("mdio: Move allocation of interrupts into core"), platforms which call fixed_phy_add() before fixed_mdio_bus_init() is called (for example, because the platform code and the fixed_phy driver use the same initcall level) crash in fixed_phy_add() since the ->mii_bus is not allocated.

Also since e7f4dc3536a, these interrupts are initalized to polling by default. The few (old) platforms which directly use fixed_phy_add() from their platform code all pass PHY_POLL for the irq argument, so we can keep these platforms not crashing by simply not attempting to set the irq if PHY_POLL is passed.

Quoted 7 lines

Also, even if problems have not been reported on more modern platforms which used fixed_phy_register() from drivers' probe functions, we return -EPROBE_DEFER if the MDIO bus is not yet registered so that the probe is retried later.

Fixes e7f4dc3536a400 ("mdio: Move allocation of interrupts into core")

Thanks
Andrew

maintainer Applied
#2 lore raw
In reply to Rabin Vincent

From: Rabin Vincent <[email protected]>
Date: Wed, 18 May 2016 12:47:31 +0200

Quoted 19 lines

From: Rabin Vincent <[email protected]>

Since e7f4dc3536a ("mdio: Move allocation of interrupts into core"), platforms which call fixed_phy_add() before fixed_mdio_bus_init() is called (for example, because the platform code and the fixed_phy driver use the same initcall level) crash in fixed_phy_add() since the ->mii_bus is not allocated.

Also since e7f4dc3536a, these interrupts are initalized to polling by default. The few (old) platforms which directly use fixed_phy_add() from their platform code all pass PHY_POLL for the irq argument, so we can keep these platforms not crashing by simply not attempting to set the irq if PHY_POLL is passed.

Also, even if problems have not been reported on more modern platforms which used fixed_phy_register() from drivers' probe functions, we return -EPROBE_DEFER if the MDIO bus is not yet registered so that the probe is retried later.

Quoted 4 lines
Fixes e7f4dc3536a400 ("mdio: Move allocation of interrupts into core")

---
v3: One more suggestion from Andrew: check mii bus state

Applied, thanks.