From 4bff0a0553b739427834ef7669621f08ee84dec0 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Tue, 15 Jul 2014 15:19:53 +0200 Subject: USB: host: implement usb_remove_device Signed-off-by: Sascha Hauer --- 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 39cadb55ff..144442a4ca 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 7c69e102ad..faf509ec9d 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 3e79407d78..a0c05506dd 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 */ -- cgit v1.2.3