Commit 15b7336e authored by Alan Stern's avatar Alan Stern Committed by Greg Kroah-Hartman

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: default avatarAlan Stern <stern@rowland.harvard.edu>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent b977a306
...@@ -1464,11 +1464,10 @@ static int hub_configure(struct usb_hub *hub, ...@@ -1464,11 +1464,10 @@ static int hub_configure(struct usb_hub *hub,
* and battery-powered root hubs (may provide just 8 mA). * and battery-powered root hubs (may provide just 8 mA).
*/ */
ret = usb_get_status(hdev, USB_RECIP_DEVICE, 0, &hubstatus); ret = usb_get_status(hdev, USB_RECIP_DEVICE, 0, &hubstatus);
if (ret < 2) { if (ret) {
message = "can't get hub status"; message = "can't get hub status";
goto fail; goto fail;
} }
le16_to_cpus(&hubstatus);
hcd = bus_to_hcd(hdev->bus); hcd = bus_to_hcd(hdev->bus);
if (hdev == hdev->bus->root_hub) { if (hdev == hdev->bus->root_hub) {
if (hcd->power_budget > 0) if (hcd->power_budget > 0)
...@@ -3101,8 +3100,6 @@ static int finish_port_resume(struct usb_device *udev) ...@@ -3101,8 +3100,6 @@ static int finish_port_resume(struct usb_device *udev)
if (status == 0) { if (status == 0) {
devstatus = 0; devstatus = 0;
status = usb_get_status(udev, USB_RECIP_DEVICE, 0, &devstatus); status = usb_get_status(udev, USB_RECIP_DEVICE, 0, &devstatus);
if (status >= 0)
status = (status > 0 ? 0 : -ENODEV);
/* If a normal resume failed, try doing a reset-resume */ /* If a normal resume failed, try doing a reset-resume */
if (status && !udev->reset_resume && udev->persist_enabled) { if (status && !udev->reset_resume && udev->persist_enabled) {
...@@ -3123,7 +3120,6 @@ static int finish_port_resume(struct usb_device *udev) ...@@ -3123,7 +3120,6 @@ static int finish_port_resume(struct usb_device *udev)
*/ */
} else if (udev->actconfig && !udev->reset_resume) { } else if (udev->actconfig && !udev->reset_resume) {
if (!hub_is_superspeed(udev->parent)) { if (!hub_is_superspeed(udev->parent)) {
le16_to_cpus(&devstatus);
if (devstatus & (1 << USB_DEVICE_REMOTE_WAKEUP)) if (devstatus & (1 << USB_DEVICE_REMOTE_WAKEUP))
status = usb_control_msg(udev, status = usb_control_msg(udev,
usb_sndctrlpipe(udev, 0), usb_sndctrlpipe(udev, 0),
...@@ -3135,7 +3131,6 @@ static int finish_port_resume(struct usb_device *udev) ...@@ -3135,7 +3131,6 @@ static int finish_port_resume(struct usb_device *udev)
} else { } else {
status = usb_get_status(udev, USB_RECIP_INTERFACE, 0, status = usb_get_status(udev, USB_RECIP_INTERFACE, 0,
&devstatus); &devstatus);
le16_to_cpus(&devstatus);
if (!status && devstatus & (USB_INTRF_STAT_FUNC_RW_CAP if (!status && devstatus & (USB_INTRF_STAT_FUNC_RW_CAP
| USB_INTRF_STAT_FUNC_RW)) | USB_INTRF_STAT_FUNC_RW))
status = status =
...@@ -4481,11 +4476,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1, ...@@ -4481,11 +4476,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
status = usb_get_status(udev, USB_RECIP_DEVICE, 0, status = usb_get_status(udev, USB_RECIP_DEVICE, 0,
&devstat); &devstat);
if (status < 2) { if (status) {
dev_dbg(&udev->dev, "get status %d ?\n", status); dev_dbg(&udev->dev, "get status %d ?\n", status);
goto loop_disable; goto loop_disable;
} }
le16_to_cpus(&devstat);
if ((devstat & (1 << USB_DEVICE_SELF_POWERED)) == 0) { if ((devstat & (1 << USB_DEVICE_SELF_POWERED)) == 0) {
dev_err(&udev->dev, dev_err(&udev->dev,
"can't connect bus-powered hub " "can't connect bus-powered hub "
......
...@@ -934,13 +934,13 @@ int usb_get_device_descriptor(struct usb_device *dev, unsigned int size) ...@@ -934,13 +934,13 @@ int usb_get_device_descriptor(struct usb_device *dev, unsigned int size)
* *
* This call is synchronous, and may not be used in an interrupt context. * This call is synchronous, and may not be used in an interrupt context.
* *
* Returns the number of bytes received on success, or else the status code * Returns 0 and the status value in *@data (in host byte order) on success,
* returned by the underlying usb_control_msg() call. * or else the status code from the underlying usb_control_msg() call.
*/ */
int usb_get_status(struct usb_device *dev, int type, int target, void *data) int usb_get_status(struct usb_device *dev, int type, int target, void *data)
{ {
int ret; int ret;
u16 *status = kmalloc(sizeof(*status), GFP_KERNEL); __le16 *status = kmalloc(sizeof(*status), GFP_KERNEL);
if (!status) if (!status)
return -ENOMEM; return -ENOMEM;
...@@ -949,7 +949,12 @@ int usb_get_status(struct usb_device *dev, int type, int target, void *data) ...@@ -949,7 +949,12 @@ int usb_get_status(struct usb_device *dev, int type, int target, void *data)
USB_REQ_GET_STATUS, USB_DIR_IN | type, 0, target, status, USB_REQ_GET_STATUS, USB_DIR_IN | type, 0, target, status,
sizeof(*status), USB_CTRL_GET_TIMEOUT); sizeof(*status), USB_CTRL_GET_TIMEOUT);
*(u16 *)data = *status; if (ret == 2) {
*(u16 *) data = le16_to_cpu(*status);
ret = 0;
} else if (ret >= 0) {
ret = -EIO;
}
kfree(status); kfree(status);
return ret; return ret;
} }
......
...@@ -747,9 +747,9 @@ static int ch9_postconfig(struct usbtest_dev *dev) ...@@ -747,9 +747,9 @@ static int ch9_postconfig(struct usbtest_dev *dev)
/* [9.4.5] get_status always works */ /* [9.4.5] get_status always works */
retval = usb_get_status(udev, USB_RECIP_DEVICE, 0, dev->buf); retval = usb_get_status(udev, USB_RECIP_DEVICE, 0, dev->buf);
if (retval != 2) { if (retval) {
dev_err(&iface->dev, "get dev status --> %d\n", retval); dev_err(&iface->dev, "get dev status --> %d\n", retval);
return (retval < 0) ? retval : -EDOM; return retval;
} }
/* FIXME configuration.bmAttributes says if we could try to set/clear /* FIXME configuration.bmAttributes says if we could try to set/clear
...@@ -758,9 +758,9 @@ static int ch9_postconfig(struct usbtest_dev *dev) ...@@ -758,9 +758,9 @@ static int ch9_postconfig(struct usbtest_dev *dev)
retval = usb_get_status(udev, USB_RECIP_INTERFACE, retval = usb_get_status(udev, USB_RECIP_INTERFACE,
iface->altsetting[0].desc.bInterfaceNumber, dev->buf); iface->altsetting[0].desc.bInterfaceNumber, dev->buf);
if (retval != 2) { if (retval) {
dev_err(&iface->dev, "get interface status --> %d\n", retval); dev_err(&iface->dev, "get interface status --> %d\n", retval);
return (retval < 0) ? retval : -EDOM; return retval;
} }
/* FIXME get status for each endpoint in the interface */ /* FIXME get status for each endpoint in the interface */
...@@ -1351,7 +1351,6 @@ static int verify_halted(struct usbtest_dev *tdev, int ep, struct urb *urb) ...@@ -1351,7 +1351,6 @@ static int verify_halted(struct usbtest_dev *tdev, int ep, struct urb *urb)
ep, retval); ep, retval);
return retval; return retval;
} }
le16_to_cpus(&status);
if (status != 1) { if (status != 1) {
ERROR(tdev, "ep %02x bogus status: %04x != 1\n", ep, status); ERROR(tdev, "ep %02x bogus status: %04x != 1\n", ep, status);
return -EINVAL; return -EINVAL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment