Skip to contentSkip to conversation

phy: check if parent device is NULL

PATCH In review Ruslan Babayev 2 participants 3 messages Dec 20, 2016 – Dec 21, 2016

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

PATCH 1/1 phy: check if parent device is NULL

Fixes a crash observed on Octeon.

Fixes ec988ad78ed6 ("phy: Don't increment MDIO bus refcount unless it's a

different owner")

---
 drivers/net/phy/phy_device.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/phy/phy_device.c +2 -1
index 9c06f8028f0c..043328b85643 100644
@@ -905,7 +905,8 @@ EXPORT_SYMBOL(phy_attached_print);
 int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
 		      u32 flags, phy_interface_t interface)
 {
-	struct module *ndev_owner = dev->dev.parent->driver->owner;
+	struct device *parent = dev->dev.parent;
+	struct module *ndev_owner = parent ? parent->driver->owner : NULL;
 	struct mii_bus *bus = phydev->mdio.bus;
 	struct device *d = &phydev->mdio.dev;
 	int err;
Signature · 1 line
2.7.4
#1 lore raw
Quoted 5 lines · Ruslan Babayev

Fixes a crash observed on Octeon.

Fixes ec988ad78ed6 ("phy: Don't increment MDIO bus refcount unless it's a

different owner")

Assuming you saw this with the staging Octeon driver, a fix has already been submitted:

https://lkml.org/lkml/2016/12/14/756

If this is with a different driver, I would rather we fix it in a similar way that the fix proposed above.

Thanks

Quoted 19 lines
---
 drivers/net/phy/phy_device.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/phy/phy_device.c +2 -1
index 9c06f8028f0c..043328b85643 100644
@@ -905,7 +905,8 @@ EXPORT_SYMBOL(phy_attached_print);
 int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
 		      u32 flags, phy_interface_t interface)
 {
-	struct module *ndev_owner = dev->dev.parent->driver->owner;
+	struct device *parent = dev->dev.parent;
+	struct module *ndev_owner = parent ? parent->driver->owner : NULL;
 	struct mii_bus *bus = phydev->mdio.bus;
 	struct device *d = &phydev->mdio.dev;
 	int err;
Signature · 1 line
Florian
#2 lore raw

Yes, I saw that with the staging Octeon driver.
Your patch works for me too.

Thanks Florian!

Quoted 40 lines · Florian Fainelli
Quoted 5 lines · Ruslan Babayev

Fixes a crash observed on Octeon.

Fixes ec988ad78ed6 ("phy: Don't increment MDIO bus refcount unless it's a

different owner")

Assuming you saw this with the staging Octeon driver, a fix has already been submitted:

https://lkml.org/lkml/2016/12/14/756

If this is with a different driver, I would rather we fix it in a similar way that the fix proposed above.

Thanks

Quoted 10 lines
---
 drivers/net/phy/phy_device.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/phy/phy_device.c +0 -0
index 9c06f8028f0c..043328b85643 100644

drivers/net/phy/phy_device.c EXPORT_SYMBOL(phy_attached_print); · line 912

Quoted 9 lines
drivers/net/phy/phy_device.c +2 -1
@@ -905,7 +905,8 @@ EXPORT_SYMBOL(phy_attached_print);
 int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
                    u32 flags, phy_interface_t interface)
 {
-     struct module *ndev_owner = dev->dev.parent->driver->owner;
+     struct device *parent = dev->dev.parent;
+     struct module *ndev_owner = parent ? parent->driver->owner : NULL;
      struct mii_bus *bus = phydev->mdio.bus;
      struct device *d = &phydev->mdio.dev;
      int err;

--
Florian