hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/usb/core/message.c
....@@ -1039,39 +1039,34 @@
10391039 }
10401040
10411041 /*
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
10451044 * Context: !in_interrupt ()
1046
- *
1047
- * Updates the copy of the device descriptor stored in the device structure,
1048
- * which dedicates space for this purpose.
10491045 *
10501046 * Not exported, only for use by the core. If drivers really want to read
10511047 * the device descriptor directly, they can call usb_get_descriptor() with
10521048 * type = USB_DT_DEVICE and index = 0.
10531049 *
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.
10581052 */
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)
10601054 {
10611055 struct usb_device_descriptor *desc;
10621056 int ret;
10631057
1064
- if (size > sizeof(*desc))
1065
- return -EINVAL;
10661058 desc = kmalloc(sizeof(*desc), GFP_NOIO);
10671059 if (!desc)
1068
- return -ENOMEM;
1060
+ return ERR_PTR(-ENOMEM);
10691061
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
+
10711066 if (ret >= 0)
1072
- memcpy(&dev->descriptor, desc, size);
1067
+ ret = -EMSGSIZE;
10731068 kfree(desc);
1074
- return ret;
1069
+ return ERR_PTR(ret);
10751070 }
10761071
10771072 /*