Commit 15b7336e02d998720c5ace47036f7e539365bb05

Authored by Alan Stern
Committed by Greg Kroah-Hartman
1 parent b977a3068a

USB: simplify the interface of usb_get_status()

This patch simplifies the interface presented by usb_get_status().
Instead of forcing callers to check for the proper data length and
convert the status value to host byte order, the function will now
do these things itself.

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Showing 3 changed files with 15 additions and 17 deletions Side-by-side Diff

drivers/usb/core/hub.c
... ... @@ -1464,11 +1464,10 @@
1464 1464 * and battery-powered root hubs (may provide just 8 mA).
1465 1465 */
1466 1466 ret = usb_get_status(hdev, USB_RECIP_DEVICE, 0, &hubstatus);
1467   - if (ret < 2) {
  1467 + if (ret) {
1468 1468 message = "can't get hub status";
1469 1469 goto fail;
1470 1470 }
1471   - le16_to_cpus(&hubstatus);
1472 1471 hcd = bus_to_hcd(hdev->bus);
1473 1472 if (hdev == hdev->bus->root_hub) {
1474 1473 if (hcd->power_budget > 0)
... ... @@ -3101,8 +3100,6 @@
3101 3100 if (status == 0) {
3102 3101 devstatus = 0;
3103 3102 status = usb_get_status(udev, USB_RECIP_DEVICE, 0, &devstatus);
3104   - if (status >= 0)
3105   - status = (status > 0 ? 0 : -ENODEV);
3106 3103  
3107 3104 /* If a normal resume failed, try doing a reset-resume */
3108 3105 if (status && !udev->reset_resume && udev->persist_enabled) {
... ... @@ -3123,7 +3120,6 @@
3123 3120 */
3124 3121 } else if (udev->actconfig && !udev->reset_resume) {
3125 3122 if (!hub_is_superspeed(udev->parent)) {
3126   - le16_to_cpus(&devstatus);
3127 3123 if (devstatus & (1 << USB_DEVICE_REMOTE_WAKEUP))
3128 3124 status = usb_control_msg(udev,
3129 3125 usb_sndctrlpipe(udev, 0),
... ... @@ -3135,7 +3131,6 @@
3135 3131 } else {
3136 3132 status = usb_get_status(udev, USB_RECIP_INTERFACE, 0,
3137 3133 &devstatus);
3138   - le16_to_cpus(&devstatus);
3139 3134 if (!status && devstatus & (USB_INTRF_STAT_FUNC_RW_CAP
3140 3135 | USB_INTRF_STAT_FUNC_RW))
3141 3136 status =
3142 3137  
... ... @@ -4481,11 +4476,10 @@
4481 4476  
4482 4477 status = usb_get_status(udev, USB_RECIP_DEVICE, 0,
4483 4478 &devstat);
4484   - if (status < 2) {
  4479 + if (status) {
4485 4480 dev_dbg(&udev->dev, "get status %d ?\n", status);
4486 4481 goto loop_disable;
4487 4482 }
4488   - le16_to_cpus(&devstat);
4489 4483 if ((devstat & (1 << USB_DEVICE_SELF_POWERED)) == 0) {
4490 4484 dev_err(&udev->dev,
4491 4485 "can't connect bus-powered hub "
drivers/usb/core/message.c
... ... @@ -934,13 +934,13 @@
934 934 *
935 935 * This call is synchronous, and may not be used in an interrupt context.
936 936 *
937   - * Returns the number of bytes received on success, or else the status code
938   - * returned by the underlying usb_control_msg() call.
  937 + * Returns 0 and the status value in *@data (in host byte order) on success,
  938 + * or else the status code from the underlying usb_control_msg() call.
939 939 */
940 940 int usb_get_status(struct usb_device *dev, int type, int target, void *data)
941 941 {
942 942 int ret;
943   - u16 *status = kmalloc(sizeof(*status), GFP_KERNEL);
  943 + __le16 *status = kmalloc(sizeof(*status), GFP_KERNEL);
944 944  
945 945 if (!status)
946 946 return -ENOMEM;
... ... @@ -949,7 +949,12 @@
949 949 USB_REQ_GET_STATUS, USB_DIR_IN | type, 0, target, status,
950 950 sizeof(*status), USB_CTRL_GET_TIMEOUT);
951 951  
952   - *(u16 *)data = *status;
  952 + if (ret == 2) {
  953 + *(u16 *) data = le16_to_cpu(*status);
  954 + ret = 0;
  955 + } else if (ret >= 0) {
  956 + ret = -EIO;
  957 + }
953 958 kfree(status);
954 959 return ret;
955 960 }
drivers/usb/misc/usbtest.c
... ... @@ -747,9 +747,9 @@
747 747  
748 748 /* [9.4.5] get_status always works */
749 749 retval = usb_get_status(udev, USB_RECIP_DEVICE, 0, dev->buf);
750   - if (retval != 2) {
  750 + if (retval) {
751 751 dev_err(&iface->dev, "get dev status --> %d\n", retval);
752   - return (retval < 0) ? retval : -EDOM;
  752 + return retval;
753 753 }
754 754  
755 755 /* FIXME configuration.bmAttributes says if we could try to set/clear
756 756  
... ... @@ -758,9 +758,9 @@
758 758  
759 759 retval = usb_get_status(udev, USB_RECIP_INTERFACE,
760 760 iface->altsetting[0].desc.bInterfaceNumber, dev->buf);
761   - if (retval != 2) {
  761 + if (retval) {
762 762 dev_err(&iface->dev, "get interface status --> %d\n", retval);
763   - return (retval < 0) ? retval : -EDOM;
  763 + return retval;
764 764 }
765 765 /* FIXME get status for each endpoint in the interface */
766 766  
... ... @@ -1351,7 +1351,6 @@
1351 1351 ep, retval);
1352 1352 return retval;
1353 1353 }
1354   - le16_to_cpus(&status);
1355 1354 if (status != 1) {
1356 1355 ERROR(tdev, "ep %02x bogus status: %04x != 1\n", ep, status);
1357 1356 return -EINVAL;