diff options
Diffstat (limited to 'drivers/usb/core/message.c')
-rw-r--r-- | drivers/usb/core/message.c | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c index 1673e5d08926..4d59d927ae3e 100644 --- a/drivers/usb/core/message.c +++ b/drivers/usb/core/message.c @@ -1039,35 +1039,40 @@ char *usb_cache_string(struct usb_device *udev, int index) } /* - * usb_get_device_descriptor - read the device descriptor - * @udev: the device whose device descriptor should be read + * usb_get_device_descriptor - (re)reads the device descriptor (usbcore) + * @dev: the device whose device descriptor is being updated + * @size: how much of the descriptor to read * * Context: task context, might sleep. * + * Updates the copy of the device descriptor stored in the device structure, + * which dedicates space for this purpose. + * * Not exported, only for use by the core. If drivers really want to read * the device descriptor directly, they can call usb_get_descriptor() with * type = USB_DT_DEVICE and index = 0. * - * Returns: a pointer to a dynamically allocated usb_device_descriptor - * structure (which the caller must deallocate), or an ERR_PTR value. + * This call is synchronous, and may not be used in an interrupt context. + * + * Return: The number of bytes received on success, or else the status code + * returned by the underlying usb_control_msg() call. */ -struct usb_device_descriptor *usb_get_device_descriptor(struct usb_device *udev) +int usb_get_device_descriptor(struct usb_device *dev, unsigned int size) { struct usb_device_descriptor *desc; int ret; + if (size > sizeof(*desc)) + return -EINVAL; desc = kmalloc(sizeof(*desc), GFP_NOIO); if (!desc) - return ERR_PTR(-ENOMEM); - - ret = usb_get_descriptor(udev, USB_DT_DEVICE, 0, desc, sizeof(*desc)); - if (ret == sizeof(*desc)) - return desc; + return -ENOMEM; + ret = usb_get_descriptor(dev, USB_DT_DEVICE, 0, desc, size); if (ret >= 0) - ret = -EMSGSIZE; + memcpy(&dev->descriptor, desc, size); kfree(desc); - return ERR_PTR(ret); + return ret; } /* |