]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/commitdiff
mdio: Abstract device_remove() and device_free()
authorAndrew Lunn <andrew@lunn.ch>
Wed, 6 Jan 2016 19:11:27 +0000 (20:11 +0100)
committerDavid S. Miller <davem@davemloft.net>
Thu, 7 Jan 2016 19:31:27 +0000 (14:31 -0500)
Make device_free and device_remove operations in the mdio device
structure, so the core code does not need to differentiate between
phy devices and generic mdio devices.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/phy/mdio_bus.c
drivers/net/phy/mdio_device.c
drivers/net/phy/phy_device.c
include/linux/mdio.h

index 0573cfd2116f746412259388bb4a9baf0878a52a..0be7b3d65f0fd14742d66d3c2bb4439efcba87ef 100644 (file)
@@ -299,6 +299,7 @@ static inline void of_mdiobus_link_mdiodev(struct mii_bus *mdio,
  */
 int __mdiobus_register(struct mii_bus *bus, struct module *owner)
 {
+       struct mdio_device *mdiodev;
        int i, err;
 
        if (NULL == bus || NULL == bus->name ||
@@ -344,11 +345,12 @@ int __mdiobus_register(struct mii_bus *bus, struct module *owner)
 
 error:
        while (--i >= 0) {
-               struct phy_device *phydev = mdiobus_get_phy(bus, i);
-               if (phydev) {
-                       phy_device_remove(phydev);
-                       phy_device_free(phydev);
-               }
+               mdiodev = bus->mdio_map[i];
+               if (!mdiodev)
+                       continue;
+
+               mdiodev->device_remove(mdiodev);
+               mdiodev->device_free(mdiodev);
        }
        device_del(&bus->dev);
        return err;
@@ -358,7 +360,6 @@ EXPORT_SYMBOL(__mdiobus_register);
 void mdiobus_unregister(struct mii_bus *bus)
 {
        struct mdio_device *mdiodev;
-       struct phy_device *phydev;
        int i;
 
        BUG_ON(bus->state != MDIOBUS_REGISTERED);
@@ -369,14 +370,8 @@ void mdiobus_unregister(struct mii_bus *bus)
                if (!mdiodev)
                        continue;
 
-               if (!(mdiodev->flags & MDIO_DEVICE_FLAG_PHY)) {
-                       phydev = container_of(mdiodev, struct phy_device, mdio);
-                       phy_device_remove(phydev);
-                       phy_device_free(phydev);
-               } else {
-                       mdio_device_remove(mdiodev);
-                       mdio_device_free(mdiodev);
-               }
+               mdiodev->device_remove(mdiodev);
+               mdiodev->device_free(mdiodev);
        }
        device_del(&bus->dev);
 }
index 64e3777c85b40f6da3a0f27093478f95b590f6d5..9c88e6749b9a4194353fd81df36e1dc2ebab4d69 100644 (file)
@@ -46,6 +46,8 @@ struct mdio_device *mdio_device_create(struct mii_bus *bus, int addr)
        mdiodev->dev.release = mdio_device_release;
        mdiodev->dev.parent = &bus->dev;
        mdiodev->dev.bus = &mdio_bus_type;
+       mdiodev->device_free = mdio_device_free;
+       mdiodev->device_remove = mdio_device_remove;
        mdiodev->bus = bus;
        mdiodev->addr = addr;
 
index af6cb6556cf90050520b86683c91daf1aee7276f..319300627c0bb730bf6b934925771c8e02741c4d 100644 (file)
@@ -47,11 +47,27 @@ void phy_device_free(struct phy_device *phydev)
 }
 EXPORT_SYMBOL(phy_device_free);
 
+static void phy_mdio_device_free(struct mdio_device *mdiodev)
+{
+       struct phy_device *phydev;
+
+       phydev = container_of(mdiodev, struct phy_device, mdio);
+       phy_device_free(phydev);
+}
+
 static void phy_device_release(struct device *dev)
 {
        kfree(to_phy_device(dev));
 }
 
+static void phy_mdio_device_remove(struct mdio_device *mdiodev)
+{
+       struct phy_device *phydev;
+
+       phydev = container_of(mdiodev, struct phy_device, mdio);
+       phy_device_remove(phydev);
+}
+
 enum genphy_driver {
        GENPHY_DRV_1G,
        GENPHY_DRV_10G,
@@ -308,6 +324,8 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, int phy_id,
        mdiodev->bus_match = phy_bus_match;
        mdiodev->addr = addr;
        mdiodev->flags = MDIO_DEVICE_FLAG_PHY;
+       mdiodev->device_free = phy_mdio_device_free;
+       mdiodev->device_remove = phy_mdio_device_remove;
 
        dev->speed = 0;
        dev->duplex = -1;
index 75f7fad0af4f7ea081762980aaf8b4425300bffe..5bfd99d1a40a7fe91833780909534cd3aa2f990a 100644 (file)
@@ -18,7 +18,11 @@ struct mdio_device {
 
        const struct dev_pm_ops *pm_ops;
        struct mii_bus *bus;
+
        int (*bus_match)(struct device *dev, struct device_driver *drv);
+       void (*device_free)(struct mdio_device *mdiodev);
+       void (*device_remove)(struct mdio_device *mdiodev);
+
        /* Bus address of the MDIO device (0-31) */
        int addr;
        int flags;