mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] usb: core: Unregister device on component_add() failure
@ 2022-02-09 16:45 Fabio M. De Francesco
  2022-02-10 14:29 ` Heikki Krogerus
  0 siblings, 1 reply; 2+ messages in thread
From: Fabio M. De Francesco @ 2022-02-09 16:45 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Heikki Krogerus, Rafael J. Wysocki,
	Andy Shevchenko, linux-usb, linux-kernel
  Cc: Fabio M. De Francesco, syzbot+60df062e1c41940cae0f

Commit 8c67d06f3fd9 ("usb: Link the ports to the connectors they are
attached to") creates a link to the USB Type-C connector for every new
port that is added when possible. If component_add() fails,
usb_hub_create_port_device() prints a warning but does not unregister
the device and does not return errors to the callers.

Syzbot reported a "WARNING in component_del()".

Fix this issue in usb_hub_create_port_device by calling device_unregister()
and returning the errors from component_add().

Reported-and-tested-by: syzbot+60df062e1c41940cae0f@syzkaller.appspotmail.com
Fixes: 8c67d06f3fd9 ("usb: Link the ports to the connectors they are attached to")
Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
---

v1->v2: Move find_and_link_peer() soon after the 'if' test for "retval", 
	as suggested by Heikki Krogerus with his review of v1.

 drivers/usb/core/port.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/core/port.c b/drivers/usb/core/port.c
index c2bbf97a79be..d5bc36ca5b1f 100644
--- a/drivers/usb/core/port.c
+++ b/drivers/usb/core/port.c
@@ -602,11 +602,14 @@ int usb_hub_create_port_device(struct usb_hub *hub, int port1)
 		return retval;
 	}
 
-	find_and_link_peer(hub, port1);
-
 	retval = component_add(&port_dev->dev, &connector_ops);
-	if (retval)
+	if (retval) {
 		dev_warn(&port_dev->dev, "failed to add component\n");
+		device_unregister(&port_dev->dev);
+		return retval;
+	}
+
+	find_and_link_peer(hub, port1);
 
 	/*
 	 * Enable runtime pm and hold a refernce that hub_configure()
-- 
2.34.1


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

* Re: [PATCH v2] usb: core: Unregister device on component_add() failure
  2022-02-09 16:45 [PATCH v2] usb: core: Unregister device on component_add() failure Fabio M. De Francesco
@ 2022-02-10 14:29 ` Heikki Krogerus
  0 siblings, 0 replies; 2+ messages in thread
From: Heikki Krogerus @ 2022-02-10 14:29 UTC (permalink / raw)
  To: Fabio M. De Francesco
  Cc: Greg Kroah-Hartman, Rafael J. Wysocki, Andy Shevchenko,
	linux-usb, linux-kernel, syzbot+60df062e1c41940cae0f

On Wed, Feb 09, 2022 at 05:45:00PM +0100, Fabio M. De Francesco wrote:
> Commit 8c67d06f3fd9 ("usb: Link the ports to the connectors they are
> attached to") creates a link to the USB Type-C connector for every new
> port that is added when possible. If component_add() fails,
> usb_hub_create_port_device() prints a warning but does not unregister
> the device and does not return errors to the callers.
> 
> Syzbot reported a "WARNING in component_del()".
> 
> Fix this issue in usb_hub_create_port_device by calling device_unregister()
> and returning the errors from component_add().
> 
> Reported-and-tested-by: syzbot+60df062e1c41940cae0f@syzkaller.appspotmail.com
> Fixes: 8c67d06f3fd9 ("usb: Link the ports to the connectors they are attached to")
> Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>

FWIW:

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
> 
> v1->v2: Move find_and_link_peer() soon after the 'if' test for "retval", 
> 	as suggested by Heikki Krogerus with his review of v1.
> 
>  drivers/usb/core/port.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/usb/core/port.c b/drivers/usb/core/port.c
> index c2bbf97a79be..d5bc36ca5b1f 100644
> --- a/drivers/usb/core/port.c
> +++ b/drivers/usb/core/port.c
> @@ -602,11 +602,14 @@ int usb_hub_create_port_device(struct usb_hub *hub, int port1)
>  		return retval;
>  	}
>  
> -	find_and_link_peer(hub, port1);
> -
>  	retval = component_add(&port_dev->dev, &connector_ops);
> -	if (retval)
> +	if (retval) {
>  		dev_warn(&port_dev->dev, "failed to add component\n");
> +		device_unregister(&port_dev->dev);
> +		return retval;
> +	}
> +
> +	find_and_link_peer(hub, port1);
>  
>  	/*
>  	 * Enable runtime pm and hold a refernce that hub_configure()
> -- 
> 2.34.1

-- 
heikki

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

end of thread, other threads:[~2022-02-10 14:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-09 16:45 [PATCH v2] usb: core: Unregister device on component_add() failure Fabio M. De Francesco
2022-02-10 14:29 ` Heikki Krogerus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®