summaryrefslogtreecommitdiffstats
path: root/drivers/usb/core
diff options
context:
space:
mode:
authorLan Tianyu <tianyu.lan@intel.com>2013-01-19 18:53:33 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-01-21 01:10:46 +0100
commitfde26380315d7d57816efc143b7924c82dba764d (patch)
treefd715e34b12903d40f0f30b7c8b7359ab8e31826 /drivers/usb/core
parentusb: Add "portX/connect_type" attribute to expose usb port's connect type (diff)
downloadlinux-fde26380315d7d57816efc143b7924c82dba764d.tar.xz
linux-fde26380315d7d57816efc143b7924c82dba764d.zip
usb: Create link files between child device and usb port device.
To show the relationship between usb port and child device, add link file "port" under usb device's sysfs directoy and "device" under usb port device's sysfs directory. They are linked to each other. Acked-by: Alan Stern <stern@rowland.harvard.edu> Signed-off-by: Lan Tianyu <tianyu.lan@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/usb/core')
-rw-r--r--drivers/usb/core/hub.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index f6ff1302f343..cfdd4eecc5a9 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -1989,6 +1989,14 @@ void usb_disconnect(struct usb_device **pdev)
usb_disable_device(udev, 0);
usb_hcd_synchronize_unlinks(udev);
+ if (udev->parent) {
+ struct usb_port *port_dev =
+ hdev_to_hub(udev->parent)->ports[udev->portnum - 1];
+
+ sysfs_remove_link(&udev->dev.kobj, "port");
+ sysfs_remove_link(&port_dev->dev.kobj, "device");
+ }
+
usb_remove_ep_devs(&udev->ep0);
usb_unlock_device(udev);
@@ -2281,6 +2289,24 @@ int usb_new_device(struct usb_device *udev)
goto fail;
}
+ /* Create link files between child device and usb port device. */
+ if (udev->parent) {
+ struct usb_port *port_dev =
+ hdev_to_hub(udev->parent)->ports[udev->portnum - 1];
+
+ err = sysfs_create_link(&udev->dev.kobj,
+ &port_dev->dev.kobj, "port");
+ if (err)
+ goto fail;
+
+ err = sysfs_create_link(&port_dev->dev.kobj,
+ &udev->dev.kobj, "device");
+ if (err) {
+ sysfs_remove_link(&udev->dev.kobj, "port");
+ goto fail;
+ }
+ }
+
(void) usb_create_ep_devs(&udev->dev, &udev->ep0, udev);
usb_mark_last_busy(udev);
pm_runtime_put_sync_autosuspend(&udev->dev);