Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

usb: core: add a 'type' parameter to usb_get_status()

This new 'type' parameter will allows interested drivers to request
for PTM status or Standard status.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Felipe Balbi and committed by
Greg Kroah-Hartman
2e43f0fe d9e1e148

+43 -9
+40 -7
drivers/usb/core/message.c
··· 919 919 * usb_get_status - issues a GET_STATUS call 920 920 * @dev: the device whose status is being checked 921 921 * @recip: USB_RECIP_*; for device, interface, or endpoint 922 + * @type: USB_STATUS_TYPE_*; for standard or PTM status types 922 923 * @target: zero (for device), else interface or endpoint number 923 924 * @data: pointer to two bytes of bitmap data 924 925 * Context: !in_interrupt () ··· 938 937 * Returns 0 and the status value in *@data (in host byte order) on success, 939 938 * or else the status code from the underlying usb_control_msg() call. 940 939 */ 941 - int usb_get_status(struct usb_device *dev, int recip, int target, void *data) 940 + int usb_get_status(struct usb_device *dev, int recip, int type, int target, 941 + void *data) 942 942 { 943 943 int ret; 944 - __le16 *status = kmalloc(sizeof(*status), GFP_KERNEL); 944 + void *status; 945 + int length; 945 946 947 + switch (type) { 948 + case USB_STATUS_TYPE_STANDARD: 949 + length = 2; 950 + break; 951 + case USB_STATUS_TYPE_PTM: 952 + if (recip != USB_RECIP_DEVICE) 953 + return -EINVAL; 954 + 955 + length = 4; 956 + break; 957 + default: 958 + return -EINVAL; 959 + } 960 + 961 + status = kmalloc(length, GFP_KERNEL); 946 962 if (!status) 947 963 return -ENOMEM; 948 964 949 965 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), 950 966 USB_REQ_GET_STATUS, USB_DIR_IN | recip, USB_STATUS_TYPE_STANDARD, 951 - target, status, sizeof(*status), USB_CTRL_GET_TIMEOUT); 967 + target, status, length, USB_CTRL_GET_TIMEOUT); 952 968 953 - if (ret == 2) { 954 - *(u16 *) data = le16_to_cpu(*status); 955 - ret = 0; 956 - } else if (ret >= 0) { 969 + switch (ret) { 970 + case 4: 971 + if (type != USB_STATUS_TYPE_PTM) { 972 + ret = -EIO; 973 + break; 974 + } 975 + 976 + *(u32 *) data = le32_to_cpu(*(__le32 *) status); 977 + break; 978 + case 2: 979 + if (type != USB_STATUS_TYPE_STANDARD) { 980 + ret = -EIO; 981 + break; 982 + } 983 + 984 + *(u16 *) data = le16_to_cpu(*(__le16 *) status); 985 + break; 986 + default: 957 987 ret = -EIO; 958 988 } 989 + 959 990 kfree(status); 960 991 return ret; 961 992 }
+3 -2
include/linux/usb.h
··· 1766 1766 extern int usb_get_descriptor(struct usb_device *dev, unsigned char desctype, 1767 1767 unsigned char descindex, void *buf, int size); 1768 1768 extern int usb_get_status(struct usb_device *dev, 1769 - int recip, int target, void *data); 1769 + int recip, int type, int target, void *data); 1770 1770 1771 1771 static inline int usb_get_std_status(struct usb_device *dev, 1772 1772 int recip, int target, void *data) 1773 1773 { 1774 - return usb_get_status(dev, recip, target, data); 1774 + return usb_get_status(dev, recip, USB_STATUS_TYPE_STANDARD, target, 1775 + data); 1775 1776 } 1776 1777 1777 1778 extern int usb_string(struct usb_device *dev, int index,