Skip to contentSkip to conversation

net: smsc911x: handle suspend/resume for mii bus

PATCH In review Daniel Mack 2 participants 3 messages Aug 13, 2014

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

PATCH 1/1 net: smsc911x: handle suspend/resume for mii bus

Since commit a71e3c37960c ("net: phy: Set the driver when registering an MDIO bus device"), the ->driver pointers of all mii buses are set to the parent device's driver. This means that smsc911x_{suspend,resume} will be called for the MII bus at suspend time now, in addition to the actual netdev suspend callbacks.

These functions currently assume they are only called for the netdev, and don't check whether they get back a valid pointer from dev_get_drvdata().

Fix this by bailing out early if dev_get_drvdata() returns NULL.

Cc Ezequiel Garcia <[email protected]>
Cc <[email protected]> [3.16+]
---
 drivers/net/ethernet/smsc/smsc911x.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
drivers/net/ethernet/smsc/smsc911x.c +18 -2
index 5e13fa5..2ba6590 100644
@@ -2555,7 +2555,15 @@ out_0:
 static int smsc911x_suspend(struct device *dev)
 {
 	struct net_device *ndev = dev_get_drvdata(dev);
-	struct smsc911x_data *pdata = netdev_priv(ndev);
+	struct smsc911x_data *pdata;
+
+	/* We are called for the mii bus as well, in which case
+	 * drvdata is unset.
+	 */
+	if (!ndev)
+		return 0;
+
+	pdata = netdev_priv(ndev);
 
 	/* enable wake on LAN, energy detection and the external PME
 	 * signal. */
@@ -2569,9 +2577,17 @@ static int smsc911x_suspend(struct device *dev)
 static int smsc911x_resume(struct device *dev)
 {
 	struct net_device *ndev = dev_get_drvdata(dev);
-	struct smsc911x_data *pdata = netdev_priv(ndev);
+	struct smsc911x_data *pdata;
 	unsigned int to = 100;
 
+	if (!ndev)
+		return 0;
+
+	/* We are called for the mii bus as well, in which case
+	 * drvdata is unset.
+	 */
+	pdata = netdev_priv(ndev);
+
 	/* Note 3.11 from the datasheet:
 	 * 	"When the LAN9220 is in a power saving state, a write of any
 	 * 	 data to the BYTE_TEST register will wake-up the device."
Signature · 1 line
2.0.4
#1 lore raw

Hi Daniel,

Quoted 5 lines · Daniel Mack

Since commit a71e3c37960c ("net: phy: Set the driver when registering an MDIO bus device"), the ->driver pointers of all mii buses are set to the parent device's driver. This means that smsc911x_{suspend,resume} will be called for the MII bus at suspend time now, in addition to the actual netdev suspend callbacks.

This commit has been reverted in mainline:
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/drivers/net/phy/mdio_bus.c?id=ce7991e8198b80eb6b4441b6f6114bea4a665d66

#2 lore raw

Hi Fabio,

Quoted 10 lines · Fabio Estevam
Quoted 5 lines · Daniel Mack

Since commit a71e3c37960c ("net: phy: Set the driver when registering an MDIO bus device"), the ->driver pointers of all mii buses are set to the parent device's driver. This means that smsc911x_{suspend,resume} will be called for the MII bus at suspend time now, in addition to the actual netdev suspend callbacks.

This commit has been reverted in mainline:
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/drivers/net/phy/mdio_bus.c?id=ce7991e8198b80eb6b4441b6f6114bea4a665d66

Ah, same conclusion there, so all's good :)

Thanks for the pointer, and please drop my patch then.

Daniel