linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 1/3] usb: core: hub: fix unhandled return by employing a void function
@ 2020-02-26 17:50 Eugeniu Rosca
  2020-02-26 17:50 ` [PATCH v3 2/3] usb: core: hub: do error out if usb_autopm_get_interface() fails Eugeniu Rosca
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Eugeniu Rosca @ 2020-02-26 17:50 UTC (permalink / raw)
  To: Alan Stern, linux-usb, linux-kernel
  Cc: Greg Kroah-Hartman, Thinh Nguyen, Lee, Chiasheng,
	Mathieu Malaterre, Kai-Heng Feng, Eugeniu Rosca, Eugeniu Rosca,
	Hardik Gajjar, stable, scan-admin

Address below Coverity complaint (Feb 25, 2020, 8:06 AM CET):

*** CID 1458999:  Error handling issues  (CHECKED_RETURN)
/drivers/usb/core/hub.c: 1869 in hub_probe()
1863
1864            if (id->driver_info & HUB_QUIRK_CHECK_PORT_AUTOSUSPEND)
1865                    hub->quirk_check_port_auto_suspend = 1;
1866
1867            if (id->driver_info & HUB_QUIRK_DISABLE_AUTOSUSPEND) {
1868                    hub->quirk_disable_autosuspend = 1;
 >>>     CID 1458999:  Error handling issues  (CHECKED_RETURN)
 >>>     Calling "usb_autopm_get_interface" without checking return value (as is done elsewhere 97 out of 111 times).
1869                    usb_autopm_get_interface(intf);
1870            }
1871
1872            if (hub_configure(hub, &desc->endpoint[0].desc) >= 0)
1873                    return 0;
1874

Rather than checking the return value of 'usb_autopm_get_interface()',
switch to the usb_autopm_get_interface_no_resume() API, as per:

On Tue, Feb 25, 2020 at 10:32:32AM -0500, Alan Stern wrote:
 ------ 8< ------
 > This change (i.e. 'ret = usb_autopm_get_interface') is not necessary,
 > because the resume operation cannot fail at this point (interfaces
 > are always powered-up during probe). A better solution would be to
 > call usb_autopm_get_interface_no_resume() instead.
 ------ 8< ------

Fixes: 1208f9e1d758c9 ("USB: hub: Fix the broken detection of USB3 device in SMSC hub")
Cc: Hardik Gajjar <hgajjar@de.adit-jv.com>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: stable@vger.kernel.org # v4.14+
Reported-by: scan-admin@coverity.com
Suggested-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Eugeniu Rosca <erosca@de.adit-jv.com>
---
v3:
 - Make the summary line more clear
 - s/autpm/autopm/ in patch description
 - Cc <stable> with v4.14+ since v4.14.x is the earliest stable kernel
   which accepted commit 1208f9e1d758c9 ("USB: hub: Fix the broken
   detection of USB3 device in SMSC hub")

v2:
 - [Alan Stern] Use usb_autopm_get_interface_no_resume() instead of
   usb_autopm_get_interface()
 - Augment commit description to provide background
 - Link: https://lore.kernel.org/lkml/20200225183057.31953-1-erosca@de.adit-jv.com

v1:
 - Link: https://lore.kernel.org/lkml/20200225130846.20236-1-erosca@de.adit-jv.com
---
 drivers/usb/core/hub.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 1d212f82c69b..1105983b5c1c 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -1866,7 +1866,7 @@ static int hub_probe(struct usb_interface *intf, const struct usb_device_id *id)
 
 	if (id->driver_info & HUB_QUIRK_DISABLE_AUTOSUSPEND) {
 		hub->quirk_disable_autosuspend = 1;
-		usb_autopm_get_interface(intf);
+		usb_autopm_get_interface_no_resume(intf);
 	}
 
 	if (hub_configure(hub, &desc->endpoint[0].desc) >= 0)
-- 
2.25.1


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

* [PATCH v3 2/3] usb: core: hub: do error out if usb_autopm_get_interface() fails
  2020-02-26 17:50 [PATCH v3 1/3] usb: core: hub: fix unhandled return by employing a void function Eugeniu Rosca
@ 2020-02-26 17:50 ` Eugeniu Rosca
  2020-02-26 17:50 ` [PATCH v3 3/3] usb: core: port: " Eugeniu Rosca
  2020-02-26 18:14 ` [PATCH v3 1/3] usb: core: hub: fix unhandled return by employing a void function Alan Stern
  2 siblings, 0 replies; 6+ messages in thread
From: Eugeniu Rosca @ 2020-02-26 17:50 UTC (permalink / raw)
  To: Alan Stern, linux-usb, linux-kernel
  Cc: Greg Kroah-Hartman, Thinh Nguyen, Lee, Chiasheng,
	Mathieu Malaterre, Kai-Heng Feng, Eugeniu Rosca, Eugeniu Rosca,
	stable

Reviewing a fresh portion of coverity defects in USB core
(specifically CID 1458999), Alan Stern noted below in [1]:

On Tue, Feb 25, 2020 at 02:39:23PM -0500, Alan Stern wrote:
 > A revised search finds line 997 in drivers/usb/core/hub.c and lines
 > 216, 269 in drivers/usb/core/port.c.  (I didn't try looking in any
 > other directories.)  AFAICT all three of these should check the
 > return value, although a error message in the kernel log probably
 > isn't needed.

Factor out the usb_remove_device() change into a standalone patch to
allow conflict-free integration on top of the earliest stable branches.

[1] https://lore.kernel.org/lkml/Pine.LNX.4.44L0.2002251419120.1485-100000@iolanthe.rowland.org

Fixes: 253e05724f9230 ("USB: add a "remove hardware" sysfs attribute")
Cc: stable@vger.kernel.org # v2.6.33+
Suggested-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Eugeniu Rosca <erosca@de.adit-jv.com>
---
v3:
 - Newly submitted
---
 drivers/usb/core/hub.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 1105983b5c1c..54cd8ef795ec 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -988,13 +988,17 @@ int usb_remove_device(struct usb_device *udev)
 {
 	struct usb_hub *hub;
 	struct usb_interface *intf;
+	int ret;
 
 	if (!udev->parent)	/* Can't remove a root hub */
 		return -EINVAL;
 	hub = usb_hub_to_struct_hub(udev->parent);
 	intf = to_usb_interface(hub->intfdev);
 
-	usb_autopm_get_interface(intf);
+	ret = usb_autopm_get_interface(intf);
+	if (ret < 0)
+		return ret;
+
 	set_bit(udev->portnum, hub->removed_bits);
 	hub_port_logical_disconnect(hub, udev->portnum);
 	usb_autopm_put_interface(intf);
-- 
2.25.1


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

* [PATCH v3 3/3] usb: core: port: do error out if usb_autopm_get_interface() fails
  2020-02-26 17:50 [PATCH v3 1/3] usb: core: hub: fix unhandled return by employing a void function Eugeniu Rosca
  2020-02-26 17:50 ` [PATCH v3 2/3] usb: core: hub: do error out if usb_autopm_get_interface() fails Eugeniu Rosca
@ 2020-02-26 17:50 ` Eugeniu Rosca
  2020-02-26 18:14 ` [PATCH v3 1/3] usb: core: hub: fix unhandled return by employing a void function Alan Stern
  2 siblings, 0 replies; 6+ messages in thread
From: Eugeniu Rosca @ 2020-02-26 17:50 UTC (permalink / raw)
  To: Alan Stern, linux-usb, linux-kernel
  Cc: Greg Kroah-Hartman, Thinh Nguyen, Lee, Chiasheng,
	Mathieu Malaterre, Kai-Heng Feng, Eugeniu Rosca, Eugeniu Rosca,
	stable

Reviewing a fresh portion of coverity defects in USB core
(specifically CID 1458999), Alan Stern noted below in [1]:

On Tue, Feb 25, 2020 at 02:39:23PM -0500, Alan Stern wrote:
 > A revised search finds line 997 in drivers/usb/core/hub.c and lines
 > 216, 269 in drivers/usb/core/port.c.  (I didn't try looking in any
 > other directories.)  AFAICT all three of these should check the
 > return value, although a error message in the kernel log probably
 > isn't needed.

Factor out the usb_port_runtime_{resume,suspend}() changes into a
standalone patch to allow conflict-free porting on top of stable v3.9+.

[1] https://lore.kernel.org/lkml/Pine.LNX.4.44L0.2002251419120.1485-100000@iolanthe.rowland.org

Fixes: 971fcd492cebf5 ("usb: add runtime pm support for usb port device")
Cc: stable@vger.kernel.org # v3.9+
Suggested-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Eugeniu Rosca <erosca@de.adit-jv.com>
---
v3:
 - Newly submitted
---
 drivers/usb/core/port.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/core/port.c b/drivers/usb/core/port.c
index bbbb35fa639f..235a7c645503 100644
--- a/drivers/usb/core/port.c
+++ b/drivers/usb/core/port.c
@@ -213,7 +213,10 @@ static int usb_port_runtime_resume(struct device *dev)
 	if (!port_dev->is_superspeed && peer)
 		pm_runtime_get_sync(&peer->dev);
 
-	usb_autopm_get_interface(intf);
+	retval = usb_autopm_get_interface(intf);
+	if (retval < 0)
+		return retval;
+
 	retval = usb_hub_set_port_power(hdev, hub, port1, true);
 	msleep(hub_power_on_good_delay(hub));
 	if (udev && !retval) {
@@ -266,7 +269,10 @@ static int usb_port_runtime_suspend(struct device *dev)
 	if (usb_port_block_power_off)
 		return -EBUSY;
 
-	usb_autopm_get_interface(intf);
+	retval = usb_autopm_get_interface(intf);
+	if (retval < 0)
+		return retval;
+
 	retval = usb_hub_set_port_power(hdev, hub, port1, false);
 	usb_clear_port_feature(hdev, port1, USB_PORT_FEAT_C_CONNECTION);
 	if (!port_dev->is_superspeed)
-- 
2.25.1


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

* Re: [PATCH v3 1/3] usb: core: hub: fix unhandled return by employing a void function
  2020-02-26 17:50 [PATCH v3 1/3] usb: core: hub: fix unhandled return by employing a void function Eugeniu Rosca
  2020-02-26 17:50 ` [PATCH v3 2/3] usb: core: hub: do error out if usb_autopm_get_interface() fails Eugeniu Rosca
  2020-02-26 17:50 ` [PATCH v3 3/3] usb: core: port: " Eugeniu Rosca
@ 2020-02-26 18:14 ` Alan Stern
  2020-03-03 10:40   ` Eugeniu Rosca
  2 siblings, 1 reply; 6+ messages in thread
From: Alan Stern @ 2020-02-26 18:14 UTC (permalink / raw)
  To: Eugeniu Rosca
  Cc: linux-usb, linux-kernel, Greg Kroah-Hartman, Thinh Nguyen, Lee,
	Chiasheng, Mathieu Malaterre, Kai-Heng Feng, Eugeniu Rosca,
	Hardik Gajjar, stable, scan-admin

On Wed, 26 Feb 2020, Eugeniu Rosca wrote:

> Address below Coverity complaint (Feb 25, 2020, 8:06 AM CET):
> 
> *** CID 1458999:  Error handling issues  (CHECKED_RETURN)
> /drivers/usb/core/hub.c: 1869 in hub_probe()
> 1863
> 1864            if (id->driver_info & HUB_QUIRK_CHECK_PORT_AUTOSUSPEND)
> 1865                    hub->quirk_check_port_auto_suspend = 1;
> 1866
> 1867            if (id->driver_info & HUB_QUIRK_DISABLE_AUTOSUSPEND) {
> 1868                    hub->quirk_disable_autosuspend = 1;
>  >>>     CID 1458999:  Error handling issues  (CHECKED_RETURN)
>  >>>     Calling "usb_autopm_get_interface" without checking return value (as is done elsewhere 97 out of 111 times).
> 1869                    usb_autopm_get_interface(intf);
> 1870            }
> 1871
> 1872            if (hub_configure(hub, &desc->endpoint[0].desc) >= 0)
> 1873                    return 0;
> 1874
> 
> Rather than checking the return value of 'usb_autopm_get_interface()',
> switch to the usb_autopm_get_interface_no_resume() API, as per:
> 
> On Tue, Feb 25, 2020 at 10:32:32AM -0500, Alan Stern wrote:
>  ------ 8< ------
>  > This change (i.e. 'ret = usb_autopm_get_interface') is not necessary,
>  > because the resume operation cannot fail at this point (interfaces
>  > are always powered-up during probe). A better solution would be to
>  > call usb_autopm_get_interface_no_resume() instead.
>  ------ 8< ------
> 
> Fixes: 1208f9e1d758c9 ("USB: hub: Fix the broken detection of USB3 device in SMSC hub")
> Cc: Hardik Gajjar <hgajjar@de.adit-jv.com>
> Cc: Alan Stern <stern@rowland.harvard.edu>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: stable@vger.kernel.org # v4.14+
> Reported-by: scan-admin@coverity.com
> Suggested-by: Alan Stern <stern@rowland.harvard.edu>
> Signed-off-by: Eugeniu Rosca <erosca@de.adit-jv.com>

For all three patches:

Acked-by: Alan Stern <stern@rowland.harvard.edu>


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

* Re: [PATCH v3 1/3] usb: core: hub: fix unhandled return by employing a void function
  2020-02-26 18:14 ` [PATCH v3 1/3] usb: core: hub: fix unhandled return by employing a void function Alan Stern
@ 2020-03-03 10:40   ` Eugeniu Rosca
  2020-03-03 10:57     ` Greg Kroah-Hartman
  0 siblings, 1 reply; 6+ messages in thread
From: Eugeniu Rosca @ 2020-03-03 10:40 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-usb, linux-kernel, Thinh Nguyen, Lee, Chiasheng,
	Mathieu Malaterre, Kai-Heng Feng, Hardik Gajjar, stable,
	Alan Stern, scan-admin, Eugeniu Rosca, Eugeniu Rosca

Hi Greg,

On Wed, Feb 26, 2020 at 01:14:24PM -0500, Alan Stern wrote:
> On Wed, 26 Feb 2020, Eugeniu Rosca wrote:
> > 
> > Fixes: 1208f9e1d758c9 ("USB: hub: Fix the broken detection of USB3 device in SMSC hub")
> > Cc: Hardik Gajjar <hgajjar@de.adit-jv.com>
> > Cc: Alan Stern <stern@rowland.harvard.edu>
> > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > Cc: stable@vger.kernel.org # v4.14+
> > Reported-by: scan-admin@coverity.com
> > Suggested-by: Alan Stern <stern@rowland.harvard.edu>
> > Signed-off-by: Eugeniu Rosca <erosca@de.adit-jv.com>
> 
> For all three patches:
> 
> Acked-by: Alan Stern <stern@rowland.harvard.edu>

Friendly reminder to pick up the patches, if no other comments.

-- 
Best Regards
Eugeniu Rosca

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

* Re: [PATCH v3 1/3] usb: core: hub: fix unhandled return by employing a void function
  2020-03-03 10:40   ` Eugeniu Rosca
@ 2020-03-03 10:57     ` Greg Kroah-Hartman
  0 siblings, 0 replies; 6+ messages in thread
From: Greg Kroah-Hartman @ 2020-03-03 10:57 UTC (permalink / raw)
  To: Eugeniu Rosca
  Cc: linux-usb, linux-kernel, Thinh Nguyen, Lee, Chiasheng,
	Mathieu Malaterre, Kai-Heng Feng, Hardik Gajjar, stable,
	Alan Stern, scan-admin, Eugeniu Rosca

On Tue, Mar 03, 2020 at 11:40:05AM +0100, Eugeniu Rosca wrote:
> Hi Greg,
> 
> On Wed, Feb 26, 2020 at 01:14:24PM -0500, Alan Stern wrote:
> > On Wed, 26 Feb 2020, Eugeniu Rosca wrote:
> > > 
> > > Fixes: 1208f9e1d758c9 ("USB: hub: Fix the broken detection of USB3 device in SMSC hub")
> > > Cc: Hardik Gajjar <hgajjar@de.adit-jv.com>
> > > Cc: Alan Stern <stern@rowland.harvard.edu>
> > > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > > Cc: stable@vger.kernel.org # v4.14+
> > > Reported-by: scan-admin@coverity.com
> > > Suggested-by: Alan Stern <stern@rowland.harvard.edu>
> > > Signed-off-by: Eugeniu Rosca <erosca@de.adit-jv.com>
> > 
> > For all three patches:
> > 
> > Acked-by: Alan Stern <stern@rowland.harvard.edu>
> 
> Friendly reminder to pick up the patches, if no other comments.

Less than a week, please give me a chance :)

Don't worry, they are in my to-review queue...

greg k-h

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

end of thread, other threads:[~2020-03-03 10:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-26 17:50 [PATCH v3 1/3] usb: core: hub: fix unhandled return by employing a void function Eugeniu Rosca
2020-02-26 17:50 ` [PATCH v3 2/3] usb: core: hub: do error out if usb_autopm_get_interface() fails Eugeniu Rosca
2020-02-26 17:50 ` [PATCH v3 3/3] usb: core: port: " Eugeniu Rosca
2020-02-26 18:14 ` [PATCH v3 1/3] usb: core: hub: fix unhandled return by employing a void function Alan Stern
2020-03-03 10:40   ` Eugeniu Rosca
2020-03-03 10:57     ` 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).