Skip to contentSkip to conversation

usb: core: drop unnecessary le16_to_cpu() conversion

PATCH Applied Antony Pavlov 2 participants 2 messages Oct 2, 2015 USB

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: core: drop unnecessary le16_to_cpu() conversion

In drivers/usb/core/usb.c we already have le16_to_cpus() conversion just after usb_get_descriptor():

    390     /* correct le values */
    391     le16_to_cpus(&dev->descriptor->bcdUSB);
    392     le16_to_cpus(&dev->descriptor->idVendor);
    393     le16_to_cpus(&dev->descriptor->idProduct);
    394     le16_to_cpus(&dev->descriptor->bcdDevice);

so no additional idVendor/idProduct descriptor fields le16_to_cpu() conversion is needed after that.

On the big-endian machines extra le16_to_cpu() conversion leads to wrong idVendor/idProduct USB device parameters values (e.g. see devinfo <usb-device> output), and to a much more serious problem: idVendor/idProduct-based USB device detection does not work.

---
 drivers/usb/core/usb.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/usb/core/usb.c +4 -4
index f8d6014..a3fb1e8 100644
@@ -445,9 +445,9 @@ int usb_new_device(struct usb_device *dev)
 	dev_add_param_fixed(&dev->dev, "Product", dev->prod);
 	dev_add_param_fixed(&dev->dev, "SerialNumber", dev->serial);
 	dev_add_param_int_ro(&dev->dev, "idVendor",
-			le16_to_cpu(dev->descriptor->idVendor), "%04x");
+			dev->descriptor->idVendor, "%04x");
 	dev_add_param_int_ro(&dev->dev, "idProduct",
-			le16_to_cpu(dev->descriptor->idProduct), "%04x");
+			dev->descriptor->idProduct, "%04x");
 	list_add_tail(&dev->list, &usb_device_list);
 	dev_count++;
 
@@ -938,11 +938,11 @@ int usb_driver_register(struct usb_driver *drv)
 static int usb_match_device(struct usb_device *dev, const struct usb_device_id *id)
 {
 	if ((id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) &&
-	    id->idVendor != le16_to_cpu(dev->descriptor->idVendor))
+	    id->idVendor != dev->descriptor->idVendor)
 		return 0;
 
 	if ((id->match_flags & USB_DEVICE_ID_MATCH_PRODUCT) &&
-	    id->idProduct != le16_to_cpu(dev->descriptor->idProduct))
+	    id->idProduct != dev->descriptor->idProduct)
 		return 0;
 
 	return 1;
Signature · 7 lines
2.6.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Applied
#1 lore raw
Quoted 18 lines · Antony Pavlov

In drivers/usb/core/usb.c we already have le16_to_cpus() conversion just after usb_get_descriptor():

    390     /* correct le values */
    391     le16_to_cpus(&dev->descriptor->bcdUSB);
    392     le16_to_cpus(&dev->descriptor->idVendor);
    393     le16_to_cpus(&dev->descriptor->idProduct);
    394     le16_to_cpus(&dev->descriptor->bcdDevice);

so no additional idVendor/idProduct descriptor fields le16_to_cpu() conversion is needed after that.

On the big-endian machines extra le16_to_cpu() conversion leads to wrong idVendor/idProduct USB device parameters values (e.g. see devinfo <usb-device> output), and to a much more serious problem: idVendor/idProduct-based USB device detection does not work.

Quoted 4 lines
---
 drivers/usb/core/usb.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Applied, thanks

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox