* [PATCH] net: mctp: fix device leak on probe failure
@ 2026-03-05 10:45 Johan Hovold
2026-03-05 23:58 ` Jeremy Kerr
2026-03-07 0:10 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 4+ messages in thread
From: Johan Hovold @ 2026-03-05 10:45 UTC (permalink / raw)
To: Jeremy Kerr, Matt Johnston
Cc: Andrew Lunn, David S . Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, netdev, linux-kernel, Johan Hovold, stable
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.
This driver takes a reference to the USB device during probe but does
not to release it on probe failures.
Drop the redundant device reference to fix the leak, reduce cargo
culting, make it easier to spot drivers where an extra reference is
needed, and reduce the risk of further memory leaks.
Fixes: 0791c0327a6e ("net: mctp: Add MCTP USB transport driver")
Cc: stable@vger.kernel.org # 6.15
Cc: Jeremy Kerr <jk@codeconstruct.com.au>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/net/mctp/mctp-usb.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/net/mctp/mctp-usb.c b/drivers/net/mctp/mctp-usb.c
index ef860cfc629f..3b5dff144177 100644
--- a/drivers/net/mctp/mctp-usb.c
+++ b/drivers/net/mctp/mctp-usb.c
@@ -329,7 +329,7 @@ static int mctp_usb_probe(struct usb_interface *intf,
SET_NETDEV_DEV(netdev, &intf->dev);
dev = netdev_priv(netdev);
dev->netdev = netdev;
- dev->usbdev = usb_get_dev(interface_to_usbdev(intf));
+ dev->usbdev = interface_to_usbdev(intf);
dev->intf = intf;
usb_set_intfdata(intf, dev);
@@ -365,7 +365,6 @@ static void mctp_usb_disconnect(struct usb_interface *intf)
mctp_unregister_netdev(dev->netdev);
usb_free_urb(dev->tx_urb);
usb_free_urb(dev->rx_urb);
- usb_put_dev(dev->usbdev);
free_netdev(dev->netdev);
}
--
2.52.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] net: mctp: fix device leak on probe failure
2026-03-05 10:45 [PATCH] net: mctp: fix device leak on probe failure Johan Hovold
@ 2026-03-05 23:58 ` Jeremy Kerr
2026-03-06 1:23 ` Jeremy Kerr
2026-03-07 0:10 ` patchwork-bot+netdevbpf
1 sibling, 1 reply; 4+ messages in thread
From: Jeremy Kerr @ 2026-03-05 23:58 UTC (permalink / raw)
To: Johan Hovold, Matt Johnston
Cc: Andrew Lunn, David S . Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, netdev, linux-kernel, stable
Hi John,
> 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.
>
> This driver takes a reference to the USB device during probe but does
> not to release it on probe failures.
>
> Drop the redundant device reference to fix the leak, reduce cargo
> culting, make it easier to spot drivers where an extra reference is
> needed, and reduce the risk of further memory leaks.
Sounds good, but I would suggest syncing with Greg K-H too; he's in the
process of doing a v2 for the same thing:
https://lore.kernel.org/netdev/2026022539-punch-supper-884c@gregkh/
Given the discussion there, this looks in-line with the longer-term move
from usb_get_dev(), so:
Acked-by: Jeremy Kerr <jk@codeconstruct.com.au>
Thanks,
Jeremy
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] net: mctp: fix device leak on probe failure
2026-03-05 23:58 ` Jeremy Kerr
@ 2026-03-06 1:23 ` Jeremy Kerr
0 siblings, 0 replies; 4+ messages in thread
From: Jeremy Kerr @ 2026-03-06 1:23 UTC (permalink / raw)
To: Johan Hovold, Matt Johnston, Greg Kroah-Hartman
Cc: Andrew Lunn, David S . Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, netdev, linux-kernel, stable
+CC Greg
Context is Johan's patch at
https://lore.kernel.org/netdev/20260305104549.16110-1-johan@kernel.org/
Cheers,
Jeremy
> Hi John,
>
> > 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.
> >
> > This driver takes a reference to the USB device during probe but does
> > not to release it on probe failures.
> >
> > Drop the redundant device reference to fix the leak, reduce cargo
> > culting, make it easier to spot drivers where an extra reference is
> > needed, and reduce the risk of further memory leaks.
>
> Sounds good, but I would suggest syncing with Greg K-H too; he's in the
> process of doing a v2 for the same thing:
>
> https://lore.kernel.org/netdev/2026022539-punch-supper-884c@gregkh/
>
> Given the discussion there, this looks in-line with the longer-term move
> from usb_get_dev(), so:
>
> Acked-by: Jeremy Kerr <jk@codeconstruct.com.au>
>
> Thanks,
>
>
> Jeremy
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] net: mctp: fix device leak on probe failure
2026-03-05 10:45 [PATCH] net: mctp: fix device leak on probe failure Johan Hovold
2026-03-05 23:58 ` Jeremy Kerr
@ 2026-03-07 0:10 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-03-07 0:10 UTC (permalink / raw)
To: Johan Hovold
Cc: jk, matt, andrew+netdev, davem, edumazet, kuba, pabeni, netdev,
linux-kernel, stable
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Thu, 5 Mar 2026 11:45:49 +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.
>
> This driver takes a reference to the USB device during probe but does
> not to release it on probe failures.
>
> [...]
Here is the summary with links:
- net: mctp: fix device leak on probe failure
https://git.kernel.org/netdev/net/c/224a0d284c3c
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-03-07 0:10 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-05 10:45 [PATCH] net: mctp: fix device leak on probe failure Johan Hovold
2026-03-05 23:58 ` Jeremy Kerr
2026-03-06 1:23 ` Jeremy Kerr
2026-03-07 0:10 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox