aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Stern <stern@rowland.harvard.edu>2012-10-19 11:03:02 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-10-24 17:51:21 -0400
commit969ddcfc95c9a1849114fb72466d2fdea70f1d48 (patch)
treee5322bb7b06e99461d96bf1091cf74230e811714
parentd39dbc8918be0e6bb850592e334203c9114c0e77 (diff)
USB: hub_for_each_child should skip unconnected ports
This patch (as1619) improves the interface to the "hub_for_each_child" macro. The name clearly suggests that the macro iterates over child devices; it does not suggest that the loop will also iterate over unnconnected ports. The patch changes the macro so that it will skip over unconnected ports and iterate only the actual child devices. The two existing call sites are updated to avoid testing for a NULL child pointer, which is now unnecessary. Signed-off-by: Alan Stern <stern@rowland.harvard.edu> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/usb/core/devices.c18
-rw-r--r--drivers/usb/host/r8a66597-hcd.c6
-rw-r--r--include/linux/usb.h5
3 files changed, 13 insertions, 16 deletions
diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
index f460de31acee..cbacea933b18 100644
--- a/drivers/usb/core/devices.c
+++ b/drivers/usb/core/devices.c
@@ -591,16 +591,14 @@ static ssize_t usb_device_dump(char __user **buffer, size_t *nbytes,
591 591
592 /* Now look at all of this device's children. */ 592 /* Now look at all of this device's children. */
593 usb_hub_for_each_child(usbdev, chix, childdev) { 593 usb_hub_for_each_child(usbdev, chix, childdev) {
594 if (childdev) { 594 usb_lock_device(childdev);
595 usb_lock_device(childdev); 595 ret = usb_device_dump(buffer, nbytes, skip_bytes,
596 ret = usb_device_dump(buffer, nbytes, skip_bytes, 596 file_offset, childdev, bus,
597 file_offset, childdev, bus, 597 level + 1, chix - 1, ++cnt);
598 level + 1, chix - 1, ++cnt); 598 usb_unlock_device(childdev);
599 usb_unlock_device(childdev); 599 if (ret == -EFAULT)
600 if (ret == -EFAULT) 600 return total_written;
601 return total_written; 601 total_written += ret;
602 total_written += ret;
603 }
604 } 602 }
605 return total_written; 603 return total_written;
606} 604}
diff --git a/drivers/usb/host/r8a66597-hcd.c b/drivers/usb/host/r8a66597-hcd.c
index fcc09e5ec0ad..b3eea0ba97a9 100644
--- a/drivers/usb/host/r8a66597-hcd.c
+++ b/drivers/usb/host/r8a66597-hcd.c
@@ -2036,10 +2036,8 @@ static void collect_usb_address_map(struct usb_device *udev, unsigned long *map)
2036 udev->parent->descriptor.bDeviceClass == USB_CLASS_HUB) 2036 udev->parent->descriptor.bDeviceClass == USB_CLASS_HUB)
2037 map[udev->devnum/32] |= (1 << (udev->devnum % 32)); 2037 map[udev->devnum/32] |= (1 << (udev->devnum % 32));
2038 2038
2039 usb_hub_for_each_child(udev, chix, childdev) { 2039 usb_hub_for_each_child(udev, chix, childdev)
2040 if (childdev) 2040 collect_usb_address_map(childdev, map);
2041 collect_usb_address_map(childdev, map);
2042 }
2043} 2041}
2044 2042
2045/* this function must be called with interrupt disabled */ 2043/* this function must be called with interrupt disabled */
diff --git a/include/linux/usb.h b/include/linux/usb.h
index f92cdf0c1457..5df7c87b277f 100644
--- a/include/linux/usb.h
+++ b/include/linux/usb.h
@@ -588,8 +588,9 @@ extern struct usb_device *usb_hub_find_child(struct usb_device *hdev,
588 */ 588 */
589#define usb_hub_for_each_child(hdev, port1, child) \ 589#define usb_hub_for_each_child(hdev, port1, child) \
590 for (port1 = 1, child = usb_hub_find_child(hdev, port1); \ 590 for (port1 = 1, child = usb_hub_find_child(hdev, port1); \
591 port1 <= hdev->maxchild; \ 591 port1 <= hdev->maxchild; \
592 child = usb_hub_find_child(hdev, ++port1)) 592 child = usb_hub_find_child(hdev, ++port1)) \
593 if (!child) continue; else
593 594
594/* USB device locking */ 595/* USB device locking */
595#define usb_lock_device(udev) device_lock(&(udev)->dev) 596#define usb_lock_device(udev) device_lock(&(udev)->dev)