From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: "Fabio M. De Francesco" <fmdefrancesco@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
syzbot+60df062e1c41940cae0f@syzkaller.appspotmail.com
Subject: Re: [PATCH] usb: core: Unregister device on component_add() failure
Date: Wed, 9 Feb 2022 16:00:09 +0200 [thread overview]
Message-ID: <YgPI6RQd/9I4/51p@kuha.fi.intel.com> (raw)
In-Reply-To: <20220208170048.24718-1-fmdefrancesco@gmail.com>
On Tue, Feb 08, 2022 at 06:00:48PM +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-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>
> ---
> drivers/usb/core/port.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/usb/core/port.c b/drivers/usb/core/port.c
> index c2bbf97a79be..8455b235976a 100644
> --- a/drivers/usb/core/port.c
> +++ b/drivers/usb/core/port.c
> @@ -605,8 +605,11 @@ int usb_hub_create_port_device(struct usb_hub *hub, int port1)
> 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;
You didn't remove the peer links. Either remove them here separately,
or alternatively you can also just shuffle the code so that you only
create those links after the component_add() call:
diff --git a/drivers/usb/core/port.c b/drivers/usb/core/port.c
index c2bbf97a79bec..d5bc36ca5b1f7 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()
thanks,
--
heikki
next prev parent reply other threads:[~2022-02-09 14:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-08 17:00 [PATCH] usb: core: Unregister device on component_add() failure Fabio M. De Francesco
2022-02-09 14:00 ` Heikki Krogerus [this message]
2022-02-09 16:30 ` Fabio M. De Francesco
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YgPI6RQd/9I4/51p@kuha.fi.intel.com \
--to=heikki.krogerus@linux.intel.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=fmdefrancesco@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=rafael.j.wysocki@intel.com \
--cc=syzbot+60df062e1c41940cae0f@syzkaller.appspotmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).