Skip to content

Commit cff9c56

Browse files
luizlucadavem330
authored andcommitted
net: mdio: get/put device node during (un)registration
The __of_mdiobus_register() function was storing the device node in dev.of_node without increasing its reference count. It implicitly relied on the caller to maintain the allocated node until the mdiobus was unregistered. Now, __of_mdiobus_register() will acquire the node before assigning it, and of_mdiobus_unregister_callback() will be called at the end of mdio_unregister(). Drivers can now release the node immediately after MDIO registration. Some of them are already doing that even before this patch. Signed-off-by: Luiz Angelo Daros de Luca <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 92de776 commit cff9c56

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

drivers/net/mdio/of_mdio.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ bool of_mdiobus_child_is_phy(struct device_node *child)
139139
}
140140
EXPORT_SYMBOL(of_mdiobus_child_is_phy);
141141

142+
static void __of_mdiobus_unregister_callback(struct mii_bus *mdio)
143+
{
144+
of_node_put(mdio->dev.of_node);
145+
}
146+
142147
/**
143148
* __of_mdiobus_register - Register mii_bus and create PHYs from the device tree
144149
* @mdio: pointer to mii_bus structure
@@ -166,6 +171,8 @@ int __of_mdiobus_register(struct mii_bus *mdio, struct device_node *np,
166171
* the device tree are populated after the bus has been registered */
167172
mdio->phy_mask = ~0;
168173

174+
mdio->__unregister_callback = __of_mdiobus_unregister_callback;
175+
of_node_get(np);
169176
device_set_node(&mdio->dev, of_fwnode_handle(np));
170177

171178
/* Get bus level PHY reset GPIO details */
@@ -177,7 +184,7 @@ int __of_mdiobus_register(struct mii_bus *mdio, struct device_node *np,
177184
/* Register the MDIO bus */
178185
rc = __mdiobus_register(mdio, owner);
179186
if (rc)
180-
return rc;
187+
goto put_node;
181188

182189
/* Loop over the child nodes and register a phy_device for each phy */
183190
for_each_available_child_of_node(np, child) {
@@ -237,6 +244,9 @@ int __of_mdiobus_register(struct mii_bus *mdio, struct device_node *np,
237244
unregister:
238245
of_node_put(child);
239246
mdiobus_unregister(mdio);
247+
248+
put_node:
249+
of_node_put(np);
240250
return rc;
241251
}
242252
EXPORT_SYMBOL(__of_mdiobus_register);

drivers/net/phy/mdio_bus.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,9 @@ void mdiobus_unregister(struct mii_bus *bus)
787787
gpiod_set_value_cansleep(bus->reset_gpiod, 1);
788788

789789
device_del(&bus->dev);
790+
791+
if (bus->__unregister_callback)
792+
bus->__unregister_callback(bus);
790793
}
791794
EXPORT_SYMBOL(mdiobus_unregister);
792795

include/linux/phy.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,9 @@ struct mii_bus {
434434

435435
/** @shared: shared state across different PHYs */
436436
struct phy_package_shared *shared[PHY_MAX_ADDR];
437+
438+
/** @__unregister_callback: called at the last step of unregistration */
439+
void (*__unregister_callback)(struct mii_bus *bus);
437440
};
438441
#define to_mii_bus(d) container_of(d, struct mii_bus, dev)
439442

0 commit comments

Comments
 (0)