aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2014-07-24 21:10:02 -0400
committerDavid S. Miller <davem@davemloft.net>2014-07-24 21:10:02 -0400
commita88a7be6a2efcc4d3ea4543feb1b0d71d0100541 (patch)
tree79f99cf6c55a5c9fc663357008f7e3b9b873cf8d
parent042d7654ecb68383c392e3c7e86e04de023f65f9 (diff)
parentb3565f278a9babc00032292be489e7fbff4f48d1 (diff)
Merge branch 'mdio_module_unload'
Ezequiel Garcia says: ==================== net: phy: Prevent an MDIO bus from being unloaded while in use Changes from v1: * Dropped the unneeded module_put() on phy_attach_direct(). The motivation of this small series is to fix the current lack of relationship between an ethernet driver and the MDIO bus behind the PHY device. In such cases, we would find no visible link between the drivers: $ lsmod Module Size Used by Not tainted mvmdio 2941 0 mvneta 22069 0 Which means nothing prevents the MDIO driver from being removed: $ modprobe -r mvmdio # Unable to handle kernel NULL pointer dereference at virtual address 00000060 pgd = c0004000 [00000060] *pgd=00000000 Internal error: Oops: 17 [#1] SMP ARM Modules linked in: mvneta [last unloaded: mvmdio] CPU: 0 PID: 22 Comm: kworker/0:1 Not tainted 3.16.0-rc5-01127-g62c0816-dirty #608 Workqueue: events_power_efficient phy_state_machine task: df5ec840 ti: df67a000 task.ti: df67a000 PC is at phy_state_machine+0x1c/0x468 LR is at phy_state_machine+0x18/0x468 [snip] This patchset fixes this problem by adding a pair of module_{get,put}, so the module reference count is increased when the PHY device is attached and is decreased when the PHY is detached. Tested with mvneta and mv643xx_eth drivers, which depend on the mvmdio driver to handle MDIO. This series applies on both net and net-next branches. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/phy/mdio_bus.c1
-rw-r--r--drivers/net/phy/phy_device.c13
2 files changed, 14 insertions, 0 deletions
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 4eaadcfcb0fe..203651ebccb0 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -255,6 +255,7 @@ int mdiobus_register(struct mii_bus *bus)
255 255
256 bus->dev.parent = bus->parent; 256 bus->dev.parent = bus->parent;
257 bus->dev.class = &mdio_bus_class; 257 bus->dev.class = &mdio_bus_class;
258 bus->dev.driver = bus->parent->driver;
258 bus->dev.groups = NULL; 259 bus->dev.groups = NULL;
259 dev_set_name(&bus->dev, "%s", bus->id); 260 dev_set_name(&bus->dev, "%s", bus->id);
260 261
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 35d753d22f78..74a82328dd49 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -575,6 +575,7 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
575 u32 flags, phy_interface_t interface) 575 u32 flags, phy_interface_t interface)
576{ 576{
577 struct device *d = &phydev->dev; 577 struct device *d = &phydev->dev;
578 struct module *bus_module;
578 int err; 579 int err;
579 580
580 /* Assume that if there is no driver, that it doesn't 581 /* Assume that if there is no driver, that it doesn't
@@ -599,6 +600,14 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
599 return -EBUSY; 600 return -EBUSY;
600 } 601 }
601 602
603 /* Increment the bus module reference count */
604 bus_module = phydev->bus->dev.driver ?
605 phydev->bus->dev.driver->owner : NULL;
606 if (!try_module_get(bus_module)) {
607 dev_err(&dev->dev, "failed to get the bus module\n");
608 return -EIO;
609 }
610
602 phydev->attached_dev = dev; 611 phydev->attached_dev = dev;
603 dev->phydev = phydev; 612 dev->phydev = phydev;
604 613
@@ -664,6 +673,10 @@ EXPORT_SYMBOL(phy_attach);
664void phy_detach(struct phy_device *phydev) 673void phy_detach(struct phy_device *phydev)
665{ 674{
666 int i; 675 int i;
676
677 if (phydev->bus->dev.driver)
678 module_put(phydev->bus->dev.driver->owner);
679
667 phydev->attached_dev->phydev = NULL; 680 phydev->attached_dev->phydev = NULL;
668 phydev->attached_dev = NULL; 681 phydev->attached_dev = NULL;
669 phy_suspend(phydev); 682 phy_suspend(phydev);