[PATCH 10/12] USB: host: implement usb_remove_device

Sascha Hauer s.hauer at pengutronix.de
Sat Jul 19 02:16:05 PDT 2014


Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/usb/core/hub.c |  1 +
 drivers/usb/core/usb.c | 19 +++++++++++++++++++
 drivers/usb/core/usb.h |  1 +
 3 files changed, 21 insertions(+)

diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 39cadb5..144442a 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -189,6 +189,7 @@ static void usb_hub_port_connect_change(struct usb_device *dev, int port)
 	if (((!(portstatus & USB_PORT_STAT_CONNECTION)) &&
 	     (!(portstatus & USB_PORT_STAT_ENABLE))) || (dev->children[port])) {
 		dev_dbg(&dev->dev, "usb_disconnect(&hub->children[port]);\n");
+		usb_remove_device(dev->children[port]);
 		/* Return now if nothing is connected */
 		if (!(portstatus & USB_PORT_STAT_CONNECTION))
 			return;
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index 7c69e10..faf509e 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -455,6 +455,25 @@ err_out:
 	return err;
 }
 
+void usb_remove_device(struct usb_device *usbdev)
+{
+	int i, ret;
+
+	for (i = 0; i < usbdev->maxchild; i++) {
+		if (usbdev->children[i])
+			usb_remove_device(usbdev->children[i]);
+	}
+
+	dev_info(&usbdev->dev, "removing\n");
+
+	ret = unregister_device(&usbdev->dev);
+	if (ret)
+		dev_err(&usbdev->dev, "failed to unregister\n");
+
+	usbdev->parent->children[usbdev->portnr - 1] = NULL;
+	free(usbdev);
+}
+
 struct usb_device *usb_alloc_new_device(void)
 {
 	struct usb_device *usbdev = xzalloc(sizeof (*usbdev));
diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h
index 3e79407..a0c0550 100644
--- a/drivers/usb/core/usb.h
+++ b/drivers/usb/core/usb.h
@@ -3,5 +3,6 @@
 
 struct usb_device *usb_alloc_new_device(void);
 int usb_new_device(struct usb_device *dev);
+void usb_remove_device(struct usb_device *dev);
 
 #endif /* __CORE_USB_H */
-- 
2.0.1




More information about the barebox mailing list