Skip to content

Commit

Permalink
usb: core: Unregister device on component_add() failure
Browse files Browse the repository at this point in the history
Commit 8c67d06 ("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().

Fixes: 8c67d06 ("usb: Link the ports to the connectors they are attached to")
Reported-and-tested-by: syzbot+60df062e1c41940cae0f@syzkaller.appspotmail.com
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
Link: https://lore.kernel.org/r/20220209164500.8769-1-fmdefrancesco@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Fabio M. De Francesco authored and Greg Kroah-Hartman committed Feb 11, 2022
1 parent 57bc3d3 commit c853685
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions drivers/usb/core/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit c853685

Please sign in to comment.