diff options
Diffstat (limited to 'drivers/usb')
-rw-r--r-- | drivers/usb/core/port.c | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/drivers/usb/core/port.c b/drivers/usb/core/port.c index aea54e8dfe47..40c3ac173e9e 100644 --- a/drivers/usb/core/port.c +++ b/drivers/usb/core/port.c @@ -157,10 +157,12 @@ static struct device_driver usb_port_driver = { .owner = THIS_MODULE, }; -static void link_peers(struct usb_port *left, struct usb_port *right) +static int link_peers(struct usb_port *left, struct usb_port *right) { + int rc; + if (left->peer == right && right->peer == left) - return; + return 0; if (left->peer || right->peer) { struct usb_port *lpeer = left->peer; @@ -170,11 +172,36 @@ static void link_peers(struct usb_port *left, struct usb_port *right) dev_name(&left->dev), dev_name(&right->dev), dev_name(&left->dev), lpeer, dev_name(&right->dev), rpeer); - return; + return -EBUSY; + } + + rc = sysfs_create_link(&left->dev.kobj, &right->dev.kobj, "peer"); + if (rc) + return rc; + rc = sysfs_create_link(&right->dev.kobj, &left->dev.kobj, "peer"); + if (rc) { + sysfs_remove_link(&left->dev.kobj, "peer"); + return rc; } left->peer = right; right->peer = left; + + return 0; +} + +static void link_peers_report(struct usb_port *left, struct usb_port *right) +{ + int rc; + + rc = link_peers(left, right); + if (rc == 0) { + dev_dbg(&left->dev, "peered to %s\n", dev_name(&right->dev)); + } else { + dev_warn(&left->dev, "failed to peer to %s (%d)\n", + dev_name(&right->dev), rc); + pr_warn_once("usb: port power management may be unreliable\n"); + } } static void unlink_peers(struct usb_port *left, struct usb_port *right) @@ -183,7 +210,9 @@ static void unlink_peers(struct usb_port *left, struct usb_port *right) "%s and %s are not peers?\n", dev_name(&left->dev), dev_name(&right->dev)); + sysfs_remove_link(&left->dev.kobj, "peer"); right->peer = NULL; + sysfs_remove_link(&right->dev.kobj, "peer"); left->peer = NULL; } @@ -212,7 +241,7 @@ static int match_location(struct usb_device *peer_hdev, void *p) for (port1 = 1; port1 <= peer_hdev->maxchild; port1++) { peer = peer_hub->ports[port1 - 1]; if (peer && peer->location == port_dev->location) { - link_peers(port_dev, peer); + link_peers_report(port_dev, peer); return 1; /* done */ } } @@ -275,7 +304,7 @@ static void find_and_link_peer(struct usb_hub *hub, int port1) */ peer = peer_hub->ports[port1 - 1]; if (peer && peer->location == 0) - link_peers(port_dev, peer); + link_peers_report(port_dev, peer); } int usb_hub_create_port_device(struct usb_hub *hub, int port1) |