Skip to contentSkip to conversation

USB: fix runtime PM after driver unbind

PATCH In review Johan Hovold 2 participants 6 messages Oct 1, 2019 – Oct 4, 2019

Subsystems (5)
lore
Share & tools
lore

Johan Hovold

author maintainer
#0 lore raw

v2 cover USB: fix runtime PM after driver unbind

A recent change in USB core broke runtime-PM after driver unbind in several drivers (when counting all USB serial drivers). Specifically, drivers which took care not modify the runtime-PM usage counter after their disconnect callback had returned, would now fail to be suspended when a driver is later bound.

Greg, feel free to pick these up directly. The media patch has been acked by Mauro.

Johan

v2
- rebase on usb-next, I had a conflicting change to usb-skeleton in my tree
- add Mauro's ack to the media patch

Johan Hovold (4):
USB: usb-skeleton: fix runtime PM after driver unbind
USB: usblp: fix runtime PM after driver unbind
USB: serial: fix runtime PM after driver unbind
media: stkwebcam: fix runtime PM after driver unbind

 drivers/media/usb/stkwebcam/stk-webcam.c | 3 +--
 drivers/usb/class/usblp.c                | 8 +++++---
 drivers/usb/serial/usb-serial.c          | 5 +----
 drivers/usb/usb-skeleton.c               | 8 +++-----
 4 files changed, 10 insertions(+), 14 deletions(-)
Signature · 1 line
2.23.0
author maintainer
#1 lore raw

PATCH v2 1/4 USB: usb-skeleton: fix runtime PM after driver unbind

Since commit c2b71462d294 ("USB: core: Fix bug caused by duplicate interface PM usage counter") USB drivers must always balance their runtime PM gets and puts, including when the driver has already been unbound from the interface.

Leaving the interface with a positive PM usage counter would prevent a later bound driver from suspending the device.

Fixes c2b71462d294 ("USB: core: Fix bug caused by duplicate interface PM usage counter")
Cc stable <[email protected]>
---
 drivers/usb/usb-skeleton.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/usb/usb-skeleton.c +3 -5
index c31d17d05810..8001d6384c73 100644
@@ -73,6 +73,7 @@ static void skel_delete(struct kref *kref)
 	struct usb_skel *dev = to_skel_dev(kref);
 
 	usb_free_urb(dev->bulk_in_urb);
+	usb_put_intf(dev->interface);
 	usb_put_dev(dev->udev);
 	kfree(dev->bulk_in_buffer);
 	kfree(dev);
@@ -124,10 +125,7 @@ static int skel_release(struct inode *inode, struct file *file)
 		return -ENODEV;
 
 	/* allow the device to be autosuspended */
-	mutex_lock(&dev->io_mutex);
-	if (dev->interface)
-		usb_autopm_put_interface(dev->interface);
-	mutex_unlock(&dev->io_mutex);
+	usb_autopm_put_interface(dev->interface);
 
 	/* decrement the count on our device */
 	kref_put(&dev->kref, skel_delete);
@@ -507,7 +505,7 @@ static int skel_probe(struct usb_interface *interface,
 	init_waitqueue_head(&dev->bulk_in_wait);
 
 	dev->udev = usb_get_dev(interface_to_usbdev(interface));
-	dev->interface = interface;
+	dev->interface = usb_get_intf(interface);
 
 	/* set up the endpoint information */
 	/* use only the first bulk-in and bulk-out endpoints */
Signature · 1 line
2.23.0
author maintainer
#2 lore raw

PATCH v2 2/4 USB: usblp: fix runtime PM after driver unbind

In reply to Johan Hovold

Since commit c2b71462d294 ("USB: core: Fix bug caused by duplicate interface PM usage counter") USB drivers must always balance their runtime PM gets and puts, including when the driver has already been unbound from the interface.

Leaving the interface with a positive PM usage counter would prevent a later bound driver from suspending the device.

Fixes c2b71462d294 ("USB: core: Fix bug caused by duplicate interface PM usage counter")
Cc stable <[email protected]>
---
 drivers/usb/class/usblp.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/usb/class/usblp.c +5 -3
index 7fea4999d352..fb8bd60c83f4 100644
@@ -461,10 +461,12 @@ static int usblp_release(struct inode *inode, struct file *file)
 
 	mutex_lock(&usblp_mutex);
 	usblp->used = 0;
-	if (usblp->present) {
+	if (usblp->present)
 		usblp_unlink_urbs(usblp);
-		usb_autopm_put_interface(usblp->intf);
-	} else		/* finish cleanup from disconnect */
+
+	usb_autopm_put_interface(usblp->intf);
+
+	if (!usblp->present)		/* finish cleanup from disconnect */
 		usblp_cleanup(usblp);
 	mutex_unlock(&usblp_mutex);
 	return 0;
Signature · 1 line
2.23.0
author maintainer
#3 lore raw

PATCH v2 3/4 USB: serial: fix runtime PM after driver unbind

In reply to Johan Hovold

Since commit c2b71462d294 ("USB: core: Fix bug caused by duplicate interface PM usage counter") USB drivers must always balance their runtime PM gets and puts, including when the driver has already been unbound from the interface.

Leaving the interface with a positive PM usage counter would prevent a later bound driver from suspending the device.

Fixes c2b71462d294 ("USB: core: Fix bug caused by duplicate interface PM usage counter")
Cc stable <[email protected]>
---
 drivers/usb/serial/usb-serial.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/usb/serial/usb-serial.c +1 -4
index a3179fea38c8..8f066bb55d7d 100644
@@ -314,10 +314,7 @@ static void serial_cleanup(struct tty_struct *tty)
 	serial = port->serial;
 	owner = serial->type->driver.owner;
 
-	mutex_lock(&serial->disc_mutex);
-	if (!serial->disconnected)
-		usb_autopm_put_interface(serial->interface);
-	mutex_unlock(&serial->disc_mutex);
+	usb_autopm_put_interface(serial->interface);
 
 	usb_serial_put(serial);
 	module_put(owner);
Signature · 1 line
2.23.0
author maintainer
#4 lore raw

PATCH v2 4/4 media: stkwebcam: fix runtime PM after driver unbind

In reply to Johan Hovold

Since commit c2b71462d294 ("USB: core: Fix bug caused by duplicate interface PM usage counter") USB drivers must always balance their runtime PM gets and puts, including when the driver has already been unbound from the interface.

Leaving the interface with a positive PM usage counter would prevent a later bound driver from suspending the device.

Note that runtime PM has never actually been enabled for this driver since the support_autosuspend flag in its usb_driver struct is not set.

Fixes c2b71462d294 ("USB: core: Fix bug caused by duplicate interface PM usage counter")
Cc stable <[email protected]>
---
 drivers/media/usb/stkwebcam/stk-webcam.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/media/usb/stkwebcam/stk-webcam.c +1 -2
index be8041e3e6b8..b0cfa4c1f8cc 100644
@@ -643,8 +643,7 @@ static int v4l_stk_release(struct file *fp)
 		dev->owner = NULL;
 	}
 
-	if (is_present(dev))
-		usb_autopm_put_interface(dev->interface);
+	usb_autopm_put_interface(dev->interface);
 	mutex_unlock(&dev->lock);
 	return v4l2_fh_release(fp);
 }
Signature · 1 line
2.23.0
#5 lore raw
In reply to Johan Hovold
Quoted 8 lines · Johan Hovold

A recent change in USB core broke runtime-PM after driver unbind in several drivers (when counting all USB serial drivers). Specifically, drivers which took care not modify the runtime-PM usage counter after their disconnect callback had returned, would now fail to be suspended when a driver is later bound.

Greg, feel free to pick these up directly. The media patch has been acked by Mauro.

All now applied, thanks.

greg k-h