| .. | .. |
|---|
| 1039 | 1039 | } |
|---|
| 1040 | 1040 | |
|---|
| 1041 | 1041 | /* |
|---|
| 1042 | | - * usb_get_device_descriptor - (re)reads the device descriptor (usbcore) |
|---|
| 1043 | | - * @dev: the device whose device descriptor is being updated |
|---|
| 1044 | | - * @size: how much of the descriptor to read |
|---|
| 1042 | + * usb_get_device_descriptor - read the device descriptor |
|---|
| 1043 | + * @udev: the device whose device descriptor should be read |
|---|
| 1045 | 1044 | * Context: !in_interrupt () |
|---|
| 1046 | | - * |
|---|
| 1047 | | - * Updates the copy of the device descriptor stored in the device structure, |
|---|
| 1048 | | - * which dedicates space for this purpose. |
|---|
| 1049 | 1045 | * |
|---|
| 1050 | 1046 | * Not exported, only for use by the core. If drivers really want to read |
|---|
| 1051 | 1047 | * the device descriptor directly, they can call usb_get_descriptor() with |
|---|
| 1052 | 1048 | * type = USB_DT_DEVICE and index = 0. |
|---|
| 1053 | 1049 | * |
|---|
| 1054 | | - * This call is synchronous, and may not be used in an interrupt context. |
|---|
| 1055 | | - * |
|---|
| 1056 | | - * Return: The number of bytes received on success, or else the status code |
|---|
| 1057 | | - * returned by the underlying usb_control_msg() call. |
|---|
| 1050 | + * Returns: a pointer to a dynamically allocated usb_device_descriptor |
|---|
| 1051 | + * structure (which the caller must deallocate), or an ERR_PTR value. |
|---|
| 1058 | 1052 | */ |
|---|
| 1059 | | -int usb_get_device_descriptor(struct usb_device *dev, unsigned int size) |
|---|
| 1053 | +struct usb_device_descriptor *usb_get_device_descriptor(struct usb_device *udev) |
|---|
| 1060 | 1054 | { |
|---|
| 1061 | 1055 | struct usb_device_descriptor *desc; |
|---|
| 1062 | 1056 | int ret; |
|---|
| 1063 | 1057 | |
|---|
| 1064 | | - if (size > sizeof(*desc)) |
|---|
| 1065 | | - return -EINVAL; |
|---|
| 1066 | 1058 | desc = kmalloc(sizeof(*desc), GFP_NOIO); |
|---|
| 1067 | 1059 | if (!desc) |
|---|
| 1068 | | - return -ENOMEM; |
|---|
| 1060 | + return ERR_PTR(-ENOMEM); |
|---|
| 1069 | 1061 | |
|---|
| 1070 | | - ret = usb_get_descriptor(dev, USB_DT_DEVICE, 0, desc, size); |
|---|
| 1062 | + ret = usb_get_descriptor(udev, USB_DT_DEVICE, 0, desc, sizeof(*desc)); |
|---|
| 1063 | + if (ret == sizeof(*desc)) |
|---|
| 1064 | + return desc; |
|---|
| 1065 | + |
|---|
| 1071 | 1066 | if (ret >= 0) |
|---|
| 1072 | | - memcpy(&dev->descriptor, desc, size); |
|---|
| 1067 | + ret = -EMSGSIZE; |
|---|
| 1073 | 1068 | kfree(desc); |
|---|
| 1074 | | - return ret; |
|---|
| 1069 | + return ERR_PTR(ret); |
|---|
| 1075 | 1070 | } |
|---|
| 1076 | 1071 | |
|---|
| 1077 | 1072 | /* |
|---|