• Russell King's avatar
    phy: fix mdiobus module safety · 3e3aaf64
    Russell King authored
    Re-implement the mdiobus module refcounting to ensure that we actually
    ensure that the mdiobus module code does not go away while we might call
    into it.
    
    The old scheme using bus->dev.driver was buggy, because bus->dev is a
    class device which never has a struct device_driver associated with it,
    and hence the associated code trying to obtain a refcount did nothing
    useful.
    
    Instead, take the approach that other subsystems do: pass the module
    when calling mdiobus_register(), and record that in the mii_bus struct.
    When we need to increment the module use count in the phy code, use
    this stored pointer.  When the phy is deteched, drop the module
    refcount, remembering that the phy device might go away at that point.
    
    This doesn't stop the mii_bus going away while there are in-use phys -
    it merely stops the underlying code vanishing.
    Signed-off-by: default avatarRussell King <rmk+kernel@arm.linux.org.uk>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    3e3aaf64
mdio_bus.c 14.7 KB