Skip to content

Commit 3b73a7b

Browse files
Russell King (Oracle)davem330
authored andcommitted
net: mdio_bus: add refcounting for fwnodes to mdiobus
Luiz Angelo Daros de Luca reports that the MDIO bus code maintains a reference to the DT node, but does not hold a refcount on the node. The simple solution to this is to add the necessary refcounting into the MDIO bus code for all users, ensuring that on registration, the refcount is incremented, and only dropped when the MDIO bus is released. Do this for fwnodes, so we not only fix this for DT, but also other types of firmware nodes as well. Reported-by: Luiz Angelo Daros de Luca <luizluca@gmail.com> Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 0f2b214 commit 3b73a7b

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

drivers/net/phy/mdio_bus.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ static void mdiobus_release(struct device *d)
193193
bus->state != MDIOBUS_ALLOCATED,
194194
"%s: not in RELEASED or ALLOCATED state\n",
195195
bus->id);
196+
197+
if (bus->state == MDIOBUS_RELEASED)
198+
fwnode_handle_put(dev_fwnode(d));
199+
196200
kfree(bus);
197201
}
198202

@@ -684,6 +688,15 @@ int __mdiobus_register(struct mii_bus *bus, struct module *owner)
684688
bus->dev.groups = NULL;
685689
dev_set_name(&bus->dev, "%s", bus->id);
686690

691+
/* If the bus state is allocated, we're registering a fresh bus
692+
* that may have a fwnode associated with it. Grab a reference
693+
* to the fwnode. This will be dropped when the bus is released.
694+
* If the bus was set to unregistered, it means that the bus was
695+
* previously registered, and we've already grabbed a reference.
696+
*/
697+
if (bus->state == MDIOBUS_ALLOCATED)
698+
fwnode_handle_get(dev_fwnode(&bus->dev));
699+
687700
/* We need to set state to MDIOBUS_UNREGISTERED to correctly release
688701
* the device in mdiobus_free()
689702
*

0 commit comments

Comments
 (0)