mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-07-23 15:27:29 +00:00
net: phy: add device-managed devm_mdiobus_register
If there's no special ordering requirement for mdiobus_unregister(), then driver code can be simplified by using a device-managed version of mdiobus_register(). Prerequisite is that bus allocation has been done device-managed too. Else mdiobus_free() may be called whilst bus is still registered, resulting in a BUG_ON(). Therefore let devm_mdiobus_register() return -EPERM if bus was allocated non-managed. Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
4406d36dfd
commit
38f961e744
2 changed files with 24 additions and 1 deletions
|
@ -241,6 +241,9 @@ struct mii_bus {
|
|||
int (*reset)(struct mii_bus *bus);
|
||||
struct mdio_bus_stats stats[PHY_MAX_ADDR];
|
||||
|
||||
unsigned int is_managed:1; /* is device-managed */
|
||||
unsigned int is_managed_registered:1;
|
||||
|
||||
/*
|
||||
* A lock to ensure that only one thing can read/write
|
||||
* the MDIO bus at a time
|
||||
|
@ -286,6 +289,20 @@ static inline struct mii_bus *mdiobus_alloc(void)
|
|||
|
||||
int __mdiobus_register(struct mii_bus *bus, struct module *owner);
|
||||
#define mdiobus_register(bus) __mdiobus_register(bus, THIS_MODULE)
|
||||
static inline int devm_mdiobus_register(struct mii_bus *bus)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (!bus->is_managed)
|
||||
return -EPERM;
|
||||
|
||||
ret = mdiobus_register(bus);
|
||||
if (!ret)
|
||||
bus->is_managed_registered = 1;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void mdiobus_unregister(struct mii_bus *bus);
|
||||
void mdiobus_free(struct mii_bus *bus);
|
||||
struct mii_bus *devm_mdiobus_alloc_size(struct device *dev, int sizeof_priv);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue