linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/4] USB: fix runtime PM after driver unbind
@ 2019-10-01  8:49 Johan Hovold
  2019-10-01  8:49 ` [PATCH v2 1/4] USB: usb-skeleton: " Johan Hovold
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Johan Hovold @ 2019-10-01  8:49 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.

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

-- 
2.23.0


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

* [PATCH v2 1/4] USB: usb-skeleton: fix runtime PM after driver unbind
  2019-10-01  8:49 [PATCH v2 0/4] USB: fix runtime PM after driver unbind Johan Hovold
@ 2019-10-01  8:49 ` Johan Hovold
  2019-10-01  8:49 ` [PATCH v2 2/4] USB: usblp: " Johan Hovold
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Johan Hovold @ 2019-10-01  8:49 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 c31d17d05810..8001d6384c73 100644
--- a/drivers/usb/usb-skeleton.c
+++ b/drivers/usb/usb-skeleton.c
@@ -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 */
-- 
2.23.0


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

* [PATCH v2 2/4] USB: usblp: fix runtime PM after driver unbind
  2019-10-01  8:49 [PATCH v2 0/4] USB: fix runtime PM after driver unbind Johan Hovold
  2019-10-01  8:49 ` [PATCH v2 1/4] USB: usb-skeleton: " Johan Hovold
@ 2019-10-01  8:49 ` Johan Hovold
  2019-10-01  8:49 ` [PATCH v2 3/4] USB: serial: " Johan Hovold
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Johan Hovold @ 2019-10-01  8:49 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] 6+ messages in thread

* [PATCH v2 3/4] USB: serial: fix runtime PM after driver unbind
  2019-10-01  8:49 [PATCH v2 0/4] USB: fix runtime PM after driver unbind Johan Hovold
  2019-10-01  8:49 ` [PATCH v2 1/4] USB: usb-skeleton: " Johan Hovold
  2019-10-01  8:49 ` [PATCH v2 2/4] USB: usblp: " Johan Hovold
@ 2019-10-01  8:49 ` Johan Hovold
  2019-10-01  8:49 ` [PATCH v2 4/4] media: stkwebcam: " Johan Hovold
  2019-10-04 12:39 ` [PATCH v2 0/4] USB: " Greg Kroah-Hartman
  4 siblings, 0 replies; 6+ messages in thread
From: Johan Hovold @ 2019-10-01  8:49 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] 6+ messages in thread

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

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 <stable@vger.kernel.org>
Acked-by: Mauro Carvalho Chehab <mchehab+samsung@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] 6+ messages in thread

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

On Tue, Oct 01, 2019 at 10:49:04AM +0200, Johan Hovold wrote:
> 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

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

end of thread, other threads:[~2019-10-04 12:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-01  8:49 [PATCH v2 0/4] USB: fix runtime PM after driver unbind Johan Hovold
2019-10-01  8:49 ` [PATCH v2 1/4] USB: usb-skeleton: " Johan Hovold
2019-10-01  8:49 ` [PATCH v2 2/4] USB: usblp: " Johan Hovold
2019-10-01  8:49 ` [PATCH v2 3/4] USB: serial: " Johan Hovold
2019-10-01  8:49 ` [PATCH v2 4/4] media: stkwebcam: " Johan Hovold
2019-10-04 12:39 ` [PATCH v2 0/4] USB: " Greg Kroah-Hartman

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