Skip to contentSkip to conversation

net: mctp: usb: properly drop the usb interface on probe error

PATCH In review Greg Kroah-Hartman 2 participants 6 messages Feb 23 – Feb 25

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

PATCH 1/1 net: mctp: usb: properly drop the usb interface on probe error

When an error happens in mctp_usb_probe() the reference count on the usb interface structure needs to be properly dropped as it was incremented earlier in the function.

Cc Jeremy Kerr <[email protected]>
Cc Matt Johnston <[email protected]>
Cc stable <[email protected]>
Assisted-by gkh_clanker_2000
---
 drivers/net/mctp/mctp-usb.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/mctp/mctp-usb.c +1 -0
index ef860cfc629f..eef17ae89298 100644
@@ -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;
 }
 
Signature · 1 line
2.53.0
maintainer Acked-by on v1 1/1
#1 lore raw

Hi Greg,

Quoted 3 lines

When an error happens in mctp_usb_probe() the reference count on the usb interface structure needs to be properly dropped as it was incremented earlier in the function.

Looks good, thanks for the fix.

Cheers,

Jeremy

maintainer
#2 lore raw
In reply to Greg Kroah-Hartman

Hi Greg,

On a second look:

drivers/net/mctp/mctp-usb.c static int mctp_usb_probe(struct usb_interface *intf, · line 360

Quoted 11 lines
drivers/net/mctp/mctp-usb.c +1 -0
index ef860cfc629f..eef17ae89298 100644
@@ -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()?

Given we're in NETREG_UNINITIALIZED state, we're likely to be immediately freeing netdev there, which includes the netdev_priv data, ie., dev.

Cheers,

Jeremy

#3 lore raw
Quoted 4 lines · Jeremy Kerr

Hi Greg,

On a second look:

Quoted 13 lines

drivers/net/mctp/mctp-usb.c static int mctp_usb_probe(struct usb_interface *intf, · line 360

Quoted 11 lines
drivers/net/mctp/mctp-usb.c +1 -0
index ef860cfc629f..eef17ae89298 100644
@@ -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...

Quoted 3 lines

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

maintainer
#4 lore raw

Hi Greg,

Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
drivers/net/mctp/mctp-usb.c +0 -0
index ef860cfc629f..eef17ae89298 100644
@@ -355,6 +355,7 @@ static int mctp_usb_probe(struct usb_interface *intf,
Quoted 8 lines

drivers/net/mctp/mctp-usb.c static int mctp_usb_probe(struct usb_interface *intf, · line 360

Quoted 6 lines
drivers/net/mctp/mctp-usb.c +1 -0
         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()?

Quoted 2 lines

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.

More that the dev-> dereference may be invalid at that point, since the netdev (and hence dev) has been free_netdev()-ed.

Cheers,

Jeremy

#5 lore raw
Quoted 16 lines · Jeremy Kerr

Hi Greg,

Quoted 14 lines
Quoted 13 lines

drivers/net/mctp/mctp-usb.c static int mctp_usb_probe(struct usb_interface *intf, · line 360

Quoted 11 lines
drivers/net/mctp/mctp-usb.c +1 -0
index ef860cfc629f..eef17ae89298 100644
@@ -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()?

Quoted 5 lines
Quoted 2 lines

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.

More that the dev-> dereference may be invalid at that point, since the netdev (and hence dev) has been free_netdev()-ed.

Argh, I missed that, yes, you are right, let me make a v2 of this, thanks for the review!

greg k-h