Skip to contentSkip to conversation

net: mdio: mvusb: drop redundant device reference

PATCH Applied Johan Hovold 3 participants 4 messages Mar 9 – Mar 11

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 net: mdio: mvusb: drop redundant device reference

Driver core holds a reference to the USB interface and its parent USB device while the interface is bound to a driver and there is no need to take additional references unless the structures are needed after disconnect.

Drop the redundant device reference to reduce cargo culting, make it easier to spot drivers where an extra reference is needed, and reduce the risk of memory leaks when drivers fail to release it.

---
 drivers/net/mdio/mdio-mvusb.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)
drivers/net/mdio/mdio-mvusb.c +2 -12
index 554837c21e73..86786ecaa4b1 100644
@@ -67,7 +67,6 @@ static int mvusb_mdio_probe(struct usb_interface *interface,
 	struct device *dev = &interface->dev;
 	struct mvusb_mdio *mvusb;
 	struct mii_bus *mdio;
-	int ret;
 
 	mdio = devm_mdiobus_alloc_size(dev, sizeof(*mvusb));
 	if (!mdio)
@@ -75,7 +74,7 @@ static int mvusb_mdio_probe(struct usb_interface *interface,
 
 	mvusb = mdio->priv;
 	mvusb->mdio = mdio;
-	mvusb->udev = usb_get_dev(interface_to_usbdev(interface));
+	mvusb->udev = interface_to_usbdev(interface);
 
 	/* Reversed from USB PCAPs, no idea what these mean. */
 	mvusb->buf[MVUSB_CMD_PREAMBLE0] = cpu_to_le16(0xe800);
@@ -88,25 +87,16 @@ static int mvusb_mdio_probe(struct usb_interface *interface,
 	mdio->write = mvusb_mdio_write;
 
 	usb_set_intfdata(interface, mvusb);
-	ret = of_mdiobus_register(mdio, dev->of_node);
-	if (ret)
-		goto put_dev;
 
-	return 0;
-
-put_dev:
-	usb_put_dev(mvusb->udev);
-	return ret;
+	return of_mdiobus_register(mdio, dev->of_node);
 }
 
 static void mvusb_mdio_disconnect(struct usb_interface *interface)
 {
 	struct mvusb_mdio *mvusb = usb_get_intfdata(interface);
-	struct usb_device *udev = mvusb->udev;
 
 	mdiobus_unregister(mvusb->mdio);
 	usb_set_intfdata(interface, NULL);
-	usb_put_dev(udev);
 }
 
 static struct usb_driver mvusb_mdio_driver = {
Signature · 1 line
2.52.0
#1 lore raw
Quoted 11 lines · Johan Hovold

Driver core holds a reference to the USB interface and its parent USB device while the interface is bound to a driver and there is no need to take additional references unless the structures are needed after disconnect.

Drop the redundant device reference to reduce cargo culting, make it easier to spot drivers where an extra reference is needed, and reduce the risk of memory leaks when drivers fail to release it.

---

Forgot the changelog.

Changes in v2:
- drop explicit error path for of_mdio_bus_register()

Johan

reviewer Reviewed-by on v2 1/1
#2 lore raw
In reply to Johan Hovold
Quoted 10 lines · Johan Hovold

Driver core holds a reference to the USB interface and its parent USB device while the interface is bound to a driver and there is no need to take additional references unless the structures are needed after disconnect.

Drop the redundant device reference to reduce cargo culting, make it easier to spot drivers where an extra reference is needed, and reduce the risk of memory leaks when drivers fail to release it.

#3 lore raw
In reply to Johan Hovold
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 10 lines · On Mon, 9 Mar 2026 09:26:41 +0100 you wrote:

Driver core holds a reference to the USB interface and its parent USB device while the interface is bound to a driver and there is no need to take additional references unless the structures are needed after disconnect.

Drop the redundant device reference to reduce cargo culting, make it easier to spot drivers where an extra reference is needed, and reduce the risk of memory leaks when drivers fail to release it.

[...]

Here is the summary with links:
- [v2] net: mdio: mvusb: drop redundant device reference

    https://git.kernel.org/netdev/net-next/c/1a6ca6497a40

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html