Re: [PATCH net] net: mctp: usb: properly drop the usb interface on probe error
From: Greg Kroah-Hartman
Date: Tue Feb 24 2026 - 01:18:38 EST
On Tue, Feb 24, 2026 at 09:50:09AM +0800, Jeremy Kerr wrote:
> Hi Greg,
>
> On a second look:
>
> > diff --git a/drivers/net/mctp/mctp-usb.c b/drivers/net/mctp/mctp-usb.c
> > index ef860cfc629f..eef17ae89298 100644
> > --- a/drivers/net/mctp/mctp-usb.c
> > +++ b/drivers/net/mctp/mctp-usb.c
> > @@ -355,6 +355,7 @@ static int mctp_usb_probe(struct usb_interface *intf,
> > usb_free_urb(dev->tx_urb);
> > usb_free_urb(dev->rx_urb);
> > free_netdev(netdev);
> > + usb_put_dev(dev->usbdev);
> > return rc;
> > }
>
> Should we not do the usb_put_dev() before the free_netdev()?
Why? The usb_put_dev() doesn't really do anything, except for the fact
that you have to do it because you did a usb_get_dev() earlier. In
reality, no USB driver needs to call get/put on a usb device at all,
that is a bad pattern I made years ago for no good reason, sorry about
that.
I really should just sweep the tree to fix that up one of these days,
odds are a coccinelle script can do that...
> Given we're in NETREG_UNINITIALIZED state, we're likely to be
> immediately freeing netdev there, which includes the netdev_priv data,
> ie., dev.
That's great, but again, the usb device will still be around as the usb
core ensures that for the lifetime of probe/remove, the device will be
there with a reference. So there's no real reason to put it anywhere in
this list, other than last as that mirrors when this was grabbed, right?
thanks,
greg k-h