linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] USB: fix runtime PM after driver unbind
@ 2019-09-30 16:12 Johan Hovold
  2019-09-30 16:12 ` [PATCH 1/4] USB: usb-skeleton: " Johan Hovold
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Johan Hovold @ 2019-09-30 16:12 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Mauro Carvalho Chehab
  Cc: Pete Zaitcev, Alan Stern, linux-media, linux-usb, linux-kernel,
	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.

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(-)

-- 
2.23.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/4] USB: usb-skeleton: fix runtime PM after driver unbind
  2019-09-30 16:12 [PATCH 0/4] USB: fix runtime PM after driver unbind Johan Hovold
@ 2019-09-30 16:12 ` Johan Hovold
  2019-09-30 16:12 ` [PATCH 2/4] USB: usblp: " Johan Hovold
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Johan Hovold @ 2019-09-30 16:12 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Mauro Carvalho Chehab
  Cc: Pete Zaitcev, Alan Stern, linux-media, linux-usb, linux-kernel,
	Johan Hovold, stable

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 <stable@vger.kernel.org>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/usb-skeleton.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/usb-skeleton.c b/drivers/usb/usb-skeleton.c
index f1a5861a0586..93c3fbc2ab1f 100644
--- a/drivers/usb/usb-skeleton.c
+++ b/drivers/usb/usb-skeleton.c
@@ -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 */
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/4] USB: usblp: fix runtime PM after driver unbind
  2019-09-30 16:12 [PATCH 0/4] USB: fix runtime PM after driver unbind Johan Hovold
  2019-09-30 16:12 ` [PATCH 1/4] USB: usb-skeleton: " Johan Hovold
@ 2019-09-30 16:12 ` Johan Hovold
  2019-09-30 16:12 ` [PATCH 3/4] USB: serial: " Johan Hovold
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Johan Hovold @ 2019-09-30 16:12 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Mauro Carvalho Chehab
  Cc: Pete Zaitcev, Alan Stern, linux-media, linux-usb, linux-kernel,
	Johan Hovold, stable

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 <stable@vger.kernel.org>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/class/usblp.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/class/usblp.c b/drivers/usb/class/usblp.c
index 7fea4999d352..fb8bd60c83f4 100644
--- a/drivers/usb/class/usblp.c
+++ b/drivers/usb/class/usblp.c
@@ -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;
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/4] USB: serial: fix runtime PM after driver unbind
  2019-09-30 16:12 [PATCH 0/4] USB: fix runtime PM after driver unbind Johan Hovold
  2019-09-30 16:12 ` [PATCH 1/4] USB: usb-skeleton: " Johan Hovold
  2019-09-30 16:12 ` [PATCH 2/4] USB: usblp: " Johan Hovold
@ 2019-09-30 16:12 ` Johan Hovold
  2019-09-30 16:12 ` [PATCH 4/4] media: stkwebcam: " Johan Hovold
  2019-09-30 16:36 ` [PATCH 0/4] USB: " Mauro Carvalho Chehab
  4 siblings, 0 replies; 7+ messages in thread
From: Johan Hovold @ 2019-09-30 16:12 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Mauro Carvalho Chehab
  Cc: Pete Zaitcev, Alan Stern, linux-media, linux-usb, linux-kernel,
	Johan Hovold, stable

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 <stable@vger.kernel.org>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/serial/usb-serial.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index a3179fea38c8..8f066bb55d7d 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -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);
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 4/4] media: stkwebcam: fix runtime PM after driver unbind
  2019-09-30 16:12 [PATCH 0/4] USB: fix runtime PM after driver unbind Johan Hovold
                   ` (2 preceding siblings ...)
  2019-09-30 16:12 ` [PATCH 3/4] USB: serial: " Johan Hovold
@ 2019-09-30 16:12 ` Johan Hovold
  2019-09-30 16:36 ` [PATCH 0/4] USB: " Mauro Carvalho Chehab
  4 siblings, 0 replies; 7+ messages in thread
From: Johan Hovold @ 2019-09-30 16:12 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Mauro Carvalho Chehab
  Cc: Pete Zaitcev, Alan Stern, linux-media, linux-usb, linux-kernel,
	Johan Hovold, stable

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 <stable@vger.kernel.org>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/media/usb/stkwebcam/stk-webcam.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/media/usb/stkwebcam/stk-webcam.c b/drivers/media/usb/stkwebcam/stk-webcam.c
index be8041e3e6b8..b0cfa4c1f8cc 100644
--- a/drivers/media/usb/stkwebcam/stk-webcam.c
+++ b/drivers/media/usb/stkwebcam/stk-webcam.c
@@ -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);
 }
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/4] USB: fix runtime PM after driver unbind
  2019-09-30 16:12 [PATCH 0/4] USB: fix runtime PM after driver unbind Johan Hovold
                   ` (3 preceding siblings ...)
  2019-09-30 16:12 ` [PATCH 4/4] media: stkwebcam: " Johan Hovold
@ 2019-09-30 16:36 ` Mauro Carvalho Chehab
  2019-10-01  8:23   ` Johan Hovold
  4 siblings, 1 reply; 7+ messages in thread
From: Mauro Carvalho Chehab @ 2019-09-30 16:36 UTC (permalink / raw)
  To: Johan Hovold
  Cc: Greg Kroah-Hartman, Pete Zaitcev, Alan Stern, linux-media,
	linux-usb, linux-kernel

Em Mon, 30 Sep 2019 18:12:01 +0200
Johan Hovold <johan@kernel.org> escreveu:

> 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:

Acked-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>

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.

> 
> 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(-)
> 



Thanks,
Mauro

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/4] USB: fix runtime PM after driver unbind
  2019-09-30 16:36 ` [PATCH 0/4] USB: " Mauro Carvalho Chehab
@ 2019-10-01  8:23   ` Johan Hovold
  0 siblings, 0 replies; 7+ messages in thread
From: Johan Hovold @ 2019-10-01  8:23 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Johan Hovold, Greg Kroah-Hartman, Pete Zaitcev, Alan Stern,
	linux-media, linux-usb, linux-kernel

On Mon, Sep 30, 2019 at 01:36:03PM -0300, Mauro Carvalho Chehab wrote:
> Em Mon, 30 Sep 2019 18:12:01 +0200
> Johan Hovold <johan@kernel.org> escreveu:
> 
> > 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:
> 
> Acked-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>

Thanks for taking a look.

> 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.

Yeah, but that may be for system-wide suspend.

> 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.

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-10-01  8:23 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-30 16:12 [PATCH 0/4] USB: fix runtime PM after driver unbind Johan Hovold
2019-09-30 16:12 ` [PATCH 1/4] USB: usb-skeleton: " Johan Hovold
2019-09-30 16:12 ` [PATCH 2/4] USB: usblp: " Johan Hovold
2019-09-30 16:12 ` [PATCH 3/4] USB: serial: " Johan Hovold
2019-09-30 16:12 ` [PATCH 4/4] media: stkwebcam: " Johan Hovold
2019-09-30 16:36 ` [PATCH 0/4] USB: " Mauro Carvalho Chehab
2019-10-01  8:23   ` Johan Hovold

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).