Skip to content

Commit c853685

Browse files
xp4ns3gregkh
authored andcommitted
usb: core: Unregister device on component_add() failure
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: [email protected] Reviewed-by: Heikki Krogerus <[email protected]> Signed-off-by: Fabio M. De Francesco <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 57bc3d3 commit c853685

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

drivers/usb/core/port.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -602,11 +602,14 @@ int usb_hub_create_port_device(struct usb_hub *hub, int port1)
602602
return retval;
603603
}
604604

605-
find_and_link_peer(hub, port1);
606-
607605
retval = component_add(&port_dev->dev, &connector_ops);
608-
if (retval)
606+
if (retval) {
609607
dev_warn(&port_dev->dev, "failed to add component\n");
608+
device_unregister(&port_dev->dev);
609+
return retval;
610+
}
611+
612+
find_and_link_peer(hub, port1);
610613

611614
/*
612615
* Enable runtime pm and hold a refernce that hub_configure()

0 commit comments

Comments
 (0)