Skip to contentSkip to conversation

net: stmmac: phy logging fixes

PATCH Superseded Romain Perier 3 participants 7 messages Aug 21, 2017 – Aug 22, 2017

Subsystems (5)

v2 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v2 cover net: stmmac: phy logging fixes

This set of patches fixes issues related to logging. First it delete old code that is no longer used in stmmac_mdio_register(). Then, it fixes a crash that happens when phydev->drv is NULL and phy_attached_info() is called prior phy_driver is binded to phydev.

Changes in v2:
- Fixed wording in commit message
- "commit" not needed in the "Fixes" tag

Romain Perier (2):
net: stmmac: Delete dead code for MDIO registration
net: phy: Don't use drv when it is NULL in phy_attached_print

 drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 16 ----------------
 drivers/net/phy/phy_device.c                      | 13 +++++++++++--
 2 files changed, 11 insertions(+), 18 deletions(-)
Signature · 1 line
2.11.0
#1 lore raw

PATCH v2 1/2 net: stmmac: Delete dead code for MDIO registration

This code is no longer used, the logging function was changed by commit fbca164776e4 ("net: stmmac: Use the right logging functi").

Fixes fbca164776e4 ("net: stmmac: Use the right logging functi")
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 16 ----------------
 1 file changed, 16 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c +0 -16
index 72ec711fcba2..f5f37bfa1d58 100644
@@ -248,9 +248,6 @@ int stmmac_mdio_register(struct net_device *ndev)
 	found = 0;
 	for (addr = 0; addr < PHY_MAX_ADDR; addr++) {
 		struct phy_device *phydev = mdiobus_get_phy(new_bus, addr);
-		int act = 0;
-		char irq_num[4];
-		char *irq_str;
 
 		if (!phydev)
 			continue;
@@ -273,19 +270,6 @@ int stmmac_mdio_register(struct net_device *ndev)
 		if (priv->plat->phy_addr == -1)
 			priv->plat->phy_addr = addr;
 
-		act = (priv->plat->phy_addr == addr);
-		switch (phydev->irq) {
-		case PHY_POLL:
-			irq_str = "POLL";
-			break;
-		case PHY_IGNORE_INTERRUPT:
-			irq_str = "IGNORE";
-			break;
-		default:
-			sprintf(irq_num, "%d", phydev->irq);
-			irq_str = irq_num;
-			break;
-		}
 		phy_attached_info(phydev);
 		found = 1;
 	}
Signature · 1 line
2.11.0
#4 lore raw

PATCH v2 2/2 net: phy: Don't use drv when it is NULL in phy_attached_print

In reply to Romain Perier

Currently, if this logging function is used prior the phy driver is bound to the phy device (that is usually done from .ndo_open), 'phydev->drv' might be NULL, resulting in a kernel crash. That is typically the case in the stmmac driver, info about the phy is displayed during the registration of the MDIO bus, and then genphy driver is bound to this phydev when .ndo_open is called.

This commit fixes the issue by using the right genphy driver, when phydev->drv is NULL.

Fixes fbca164776e4 ("net: stmmac: Use the right logging functi")
---
 drivers/net/phy/phy_device.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/net/phy/phy_device.c +11 -2
index 1790f7fec125..6af6dc6dfeaf 100644
@@ -864,15 +864,24 @@ EXPORT_SYMBOL(phy_attached_info);
 #define ATTACHED_FMT "attached PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)"
 void phy_attached_print(struct phy_device *phydev, const char *fmt, ...)
 {
+	struct phy_driver *drv = phydev->drv;
+
+	if (!drv) {
+		if (phydev->is_c45)
+			drv = &genphy_10g_driver;
+		else
+			drv = &genphy_driver;
+	}
+
 	if (!fmt) {
 		dev_info(&phydev->mdio.dev, ATTACHED_FMT "\n",
-			 phydev->drv->name, phydev_name(phydev),
+			 drv->name, phydev_name(phydev),
 			 phydev->irq);
 	} else {
 		va_list ap;
 
 		dev_info(&phydev->mdio.dev, ATTACHED_FMT,
-			 phydev->drv->name, phydev_name(phydev),
+			 drv->name, phydev_name(phydev),
 			 phydev->irq);
 
 		va_start(ap, fmt);
Signature · 1 line
2.11.0
maintainer
#5 lore raw

Re: [PATCH v2 2/2] net: phy: Don't use drv when it is NULL in phy_attached_print

Quoted 23 lines · Romain Perier

Currently, if this logging function is used prior the phy driver is bound to the phy device (that is usually done from .ndo_open), 'phydev->drv' might be NULL, resulting in a kernel crash. That is typically the case in the stmmac driver, info about the phy is displayed during the registration of the MDIO bus, and then genphy driver is bound to this phydev when .ndo_open is called.

This commit fixes the issue by using the right genphy driver, when phydev->drv is NULL.

Fixes fbca164776e4 ("net: stmmac: Use the right logging functi")
---
 drivers/net/phy/phy_device.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/net/phy/phy_device.c +0 -0
index 1790f7fec125..6af6dc6dfeaf 100644
@@ -864,15 +864,24 @@ EXPORT_SYMBOL(phy_attached_info);
 #define ATTACHED_FMT "attached PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)"
 void phy_attached_print(struct phy_device *phydev, const char *fmt, ...)

drivers/net/phy/phy_device.c EXPORT_SYMBOL(phy_attached_info); · line 875

Quoted 10 lines
drivers/net/phy/phy_device.c +9 -0
 {
+	struct phy_driver *drv = phydev->drv;
+
+	if (!drv) {
+		if (phydev->is_c45)
+			drv = &genphy_10g_driver;
+		else
+			drv = &genphy_driver;
+	}
+

As i said in my comment to v1, i don't like this.

Andrew

#2 lore raw

Re: [PATCH v2 1/2] net: stmmac: Delete dead code for MDIO registration

In reply to Romain Perier
Quoted 30 lines · Romain Perier

This code is no longer used, the logging function was changed by commit fbca164776e4 ("net: stmmac: Use the right logging functi").

Fixes fbca164776e4 ("net: stmmac: Use the right logging functi")
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 16 ----------------
 1 file changed, 16 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c +0 -6
index 72ec711fcba2..f5f37bfa1d58 100644
@@ -248,9 +248,6 @@ int stmmac_mdio_register(struct net_device *ndev)
 	found = 0;
 	for (addr = 0; addr < PHY_MAX_ADDR; addr++) {
 		struct phy_device *phydev = mdiobus_get_phy(new_bus, addr);
-		int act = 0;
-		char irq_num[4];
-		char *irq_str;
 
 		if (!phydev)
 			continue;
@@ -273,19 +270,6 @@ int stmmac_mdio_register(struct net_device *ndev)
 		if (priv->plat->phy_addr == -1)
 			priv->plat->phy_addr = addr;
 
-		act = (priv->plat->phy_addr == addr);
-		switch (phydev->irq) {
-		case PHY_POLL:

drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c int stmmac_mdio_register(struct net_device *ndev) · line 288

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c +0 -10
-			irq_str = "POLL";
-			break;
-		case PHY_IGNORE_INTERRUPT:
-			irq_str = "IGNORE";
-			break;
-		default:
-			sprintf(irq_num, "%d", phydev->irq);
-			irq_str = irq_num;
-			break;
-		}

I was actually just looking into moving these prints to phy_attached_info(), since it is useful to know whether the interrupt is POLL, IGNORE, or valid. Can you move that there? Then you can really migrate over phy_attached_info() with no information loss.

Thanks!

Signature · 1 line
Florian
#6 lore raw

Re: [PATCH v2 2/2] net: phy: Don't use drv when it is NULL in phy_attached_print

In reply to Andrew Lunn
Quoted 28 lines · Andrew Lunn
Quoted 27 lines · Romain Perier

Currently, if this logging function is used prior the phy driver is bound to the phy device (that is usually done from .ndo_open), 'phydev->drv' might be NULL, resulting in a kernel crash. That is typically the case in the stmmac driver, info about the phy is displayed during the registration of the MDIO bus, and then genphy driver is bound to this phydev when .ndo_open is called.

This commit fixes the issue by using the right genphy driver, when phydev->drv is NULL.

Fixes fbca164776e4 ("net: stmmac: Use the right logging functi")
---
 drivers/net/phy/phy_device.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/net/phy/phy_device.c +3 -0
index 1790f7fec125..6af6dc6dfeaf 100644
@@ -864,15 +864,24 @@ EXPORT_SYMBOL(phy_attached_info);
 #define ATTACHED_FMT "attached PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)"
 void phy_attached_print(struct phy_device *phydev, const char *fmt, ...)
 {
+	struct phy_driver *drv = phydev->drv;
+
+	if (!drv) {
Quoted 8 lines

drivers/net/phy/phy_device.c EXPORT_SYMBOL(phy_attached_info); · line 875

Quoted 6 lines
drivers/net/phy/phy_device.c +6 -0
+		if (phydev->is_c45)
+			drv = &genphy_10g_driver;
+		else
+			drv = &genphy_driver;
+	}
+

As i said in my comment to v1, i don't like this.

Agreed, just use Andrew's earlier suggestion of checking phydev->drv validity.

We don't have an equivalent of "unregistered" in the PHY layer, but "unbound" seems like it could be what we want here.

Thanks

Signature · 1 line
Florian
#3 lore raw

Re: [PATCH v2 1/2] net: stmmac: Delete dead code for MDIO registration

In reply to Florian Fainelli

Hello,

Quoted 46 lines · Florian Fainelli
Quoted 30 lines · Romain Perier

This code is no longer used, the logging function was changed by commit fbca164776e4 ("net: stmmac: Use the right logging functi").

Fixes fbca164776e4 ("net: stmmac: Use the right logging functi")
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 16 ----------------
 1 file changed, 16 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c +0 -6
index 72ec711fcba2..f5f37bfa1d58 100644
@@ -248,9 +248,6 @@ int stmmac_mdio_register(struct net_device *ndev)
 	found = 0;
 	for (addr = 0; addr < PHY_MAX_ADDR; addr++) {
 		struct phy_device *phydev = mdiobus_get_phy(new_bus, addr);
-		int act = 0;
-		char irq_num[4];
-		char *irq_str;
 
 		if (!phydev)
 			continue;
@@ -273,19 +270,6 @@ int stmmac_mdio_register(struct net_device *ndev)
 		if (priv->plat->phy_addr == -1)
 			priv->plat->phy_addr = addr;
 
-		act = (priv->plat->phy_addr == addr);
-		switch (phydev->irq) {
-		case PHY_POLL:

drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c int stmmac_mdio_register(struct net_device *ndev) · line 288

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c +0 -10
-			irq_str = "POLL";
-			break;
-		case PHY_IGNORE_INTERRUPT:
-			irq_str = "IGNORE";
-			break;
-		default:
-			sprintf(irq_num, "%d", phydev->irq);
-			irq_str = irq_num;
-			break;
-		}

I was actually just looking into moving these prints to phy_attached_info(), since it is useful to know whether the interrupt is POLL, IGNORE, or valid. Can you move that there? Then you can really migrate over phy_attached_info() with no information loss.

Quoted 1 line

Thanks!

Sure, I can take a look.

Thanks,
Romain