USB: fix runtime PM after driver unbind
Subsystems (5)
Johan Hovold
maintainercover 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.
I guess Greg could take all of these directly through his tree, unless the media maintainers disagree.
Johan
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
Johan Hovold
maintainerPATCH 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.
--- drivers/usb/usb-skeleton.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/usb/usb-skeleton.c +3 -5
@@ -74,6 +74,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);
@@ -125,10 +126,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->disconnected) -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
Johan Hovold
maintainerPATCH 2/4 USB: usblp: fix runtime PM after driver unbind
In reply to Johan HovoldSince 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.
--- drivers/usb/class/usblp.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/usb/class/usblp.c +5 -3
@@ -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
Johan Hovold
maintainerPATCH 3/4 USB: serial: fix runtime PM after driver unbind
In reply to Johan HovoldSince 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.
--- drivers/usb/serial/usb-serial.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/usb/serial/usb-serial.c +1 -4
@@ -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
Johan Hovold
maintainerPATCH 4/4 media: stkwebcam: fix runtime PM after driver unbind
In reply to Johan HovoldSince 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.
--- drivers/media/usb/stkwebcam/stk-webcam.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/media/usb/stkwebcam/stk-webcam.c +1 -2
@@ -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
Em Mon, 30 Sep 2019 18:12:01 +0200
Johan Hovold <[email protected]> escreveu:
Quoted 8 lines
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.
I guess Greg could take all of these directly through his tree, unless the media maintainers disagree.
Patches look ok and I'm fine if they go via Greg's tree. So:
Yet, on a quick look on media:
$ git grep -l usb_.*pm drivers/media/usb/ drivers/media/usb/cpia2/cpia2_usb.c drivers/media/usb/dvb-usb-v2/az6007.c drivers/media/usb/dvb-usb-v2/dvb_usb.h drivers/media/usb/dvb-usb-v2/dvb_usb_core.c drivers/media/usb/gspca/gspca.c drivers/media/usb/gspca/gspca.h drivers/media/usb/siano/smsusb.c drivers/media/usb/stkwebcam/stk-webcam.c drivers/media/usb/usbvision/usbvision-i2c.c drivers/media/usb/uvc/uvc_driver.c drivers/media/usb/uvc/uvc_v4l2.c drivers/media/usb/zr364xx/zr364xx.c
There are other drivers beside stkwebcam with has some PM routines.
Ok, only two (stkwebcam and uvcvideo) uses usb_autopm_get_interface() and usb_autopm_put_interface(), but I'm wondering if the others are doing the right thing, as their implementation are probably older.
Quoted 10 lines
Johan
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
Quoted 6 lines
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(-)
Thanks,
Mauro
Johan Hovold
maintainerQuoted 9 lines · Mauro Carvalho Chehab
Em Mon, 30 Sep 2019 18:12:01 +0200
Johan Hovold <[email protected]> escreveu:Quoted 6 lines
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.
Quoted 6 lines
Quoted 2 lines
I guess Greg could take all of these directly through his tree, unless the media maintainers disagree.
Patches look ok and I'm fine if they go via Greg's tree. So:
Thanks for taking a look.
Quoted 16 lines
Yet, on a quick look on media:
$ git grep -l usb_.*pm drivers/media/usb/ drivers/media/usb/cpia2/cpia2_usb.c drivers/media/usb/dvb-usb-v2/az6007.c drivers/media/usb/dvb-usb-v2/dvb_usb.h drivers/media/usb/dvb-usb-v2/dvb_usb_core.c drivers/media/usb/gspca/gspca.c drivers/media/usb/gspca/gspca.h drivers/media/usb/siano/smsusb.c drivers/media/usb/stkwebcam/stk-webcam.c drivers/media/usb/usbvision/usbvision-i2c.c drivers/media/usb/uvc/uvc_driver.c drivers/media/usb/uvc/uvc_v4l2.c drivers/media/usb/zr364xx/zr364xx.c
Quoted 1 line
There are other drivers beside stkwebcam with has some PM routines.
Yeah, but that may be for system-wide suspend.
Quoted 3 lines
Ok, only two (stkwebcam and uvcvideo) uses
usb_autopm_get_interface()andusb_autopm_put_interface(), but I'm wondering if the others are doing the right thing, as their implementation are probably older.
Right, only these two support runtime PM through USB core (autosuspend).
In fact, I see now that stkwebcam fails to set the supports_autosuspend flag in its usb_driver struct, so runtime PM has never actually been enabled for this driver either. But I guess it doesn't hurt to fix missing puts if someones wants to try enabling it, if not only for documentation purposes and avoiding copy-paste proliferation.
Lots of legacy...
Johan