USB: fix gathering of interface associations
PATCH 1/1 USB: fix gathering of interface associations
TEAC's UD-H01 (and probably other devices) have a gap in the interface number allocation of their descriptors:
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 220
bNumInterfaces 3
[...]
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
[...]
Interface Association:
bLength 8
bDescriptorType 11
bFirstInterface 2
bInterfaceCount 2
bFunctionClass 1 Audio
bFunctionSubClass 0
bFunctionProtocol 32
iFunction 4
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 2
bAlternateSetting 0
[...]Once a configuration is selected, usb_set_configuration() walks the known interfaces of a given configuration and calls find_iad() on each of them to set the interface association pointer the interface is included in.
The problem here is that the loop variable is taken for the interface number in the comparison logic that gathers the association. Which is fine as long as the descriptors are sane.
In the case above, however, the logic gets out of sync and the interface association fields of all interfaces beyond the interface number gap are wrong.
Fix this by passing the interface's bInterfaceNumber to find_iad() instead.
---
This patch has been tested on a virtual USB device emulated in QEMU. I'm still waiting for test results based on real hardware, but the bug is rather obvious is and the fix really simple.
Daniel
drivers/usb/core/message.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/usb/core/message.c +2 -1
@@ -1838,7 +1838,6 @@ free_interfaces: intfc = cp->intf_cache[i]; intf->altsetting = intfc->altsetting; intf->num_altsetting = intfc->num_altsetting; - intf->intf_assoc =find_iad (dev, cp, i);kref_get (&intfc->ref); alt =usb_altnum_to_altsetting (intf,0 );
@@ -1851,6 +1850,8 @@ free_interfaces:if (!alt) alt = &intf->altsetting[0 ]; + intf->intf_assoc = +find_iad (dev, cp, alt->desc.bInterfaceNumber); intf->cur_altsetting = alt;usb_enable_interface (dev, intf, true); intf->dev.parent = &dev->dev;
Signature · 1 line
1.7.10.2
Daniel Mack
Tested-by Sergio TabanelliQuoted 2 lines · Daniel Mack
TEAC's UD-H01 (and probably other devices) have a gap in the interface number allocation of their descriptors:
I now got a report from Sergio Tabanelli who tried this patch on real hardware, and he confirmed the fix. I added some more people to the patch description and copied stable@ as well.
Greg, can can this go through your tree?
Daniel
Quoted 48 lines
Configuration Descriptor:
bLength 9 bDescriptorType 2 wTotalLength 220 bNumInterfaces 3 [...] Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 0 bAlternateSetting 0 [...] Interface Association: bLength 8 bDescriptorType 11 bFirstInterface 2 bInterfaceCount 2 bFunctionClass 1 Audio bFunctionSubClass 0 bFunctionProtocol 32 iFunction 4 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 2 bAlternateSetting 0 [...]Once a configuration is selected,
usb_set_configuration()walks the known interfaces of a given configuration and callsfind_iad()on each of them to set the interface association pointer the interface is included in.The problem here is that the loop variable is taken for the interface number in the comparison logic that gathers the association. Which is fine as long as the descriptors are sane.
In the case above, however, the logic gets out of sync and the interface association fields of all interfaces beyond the interface number gap are wrong.
Fix this by passing the interface's bInterfaceNumber to
find_iad()instead.Signed-off-by Daniel Mack <[email protected]>Reported-by bEN <[email protected]>Reported-by Ivan Perrone <[email protected]>
Quoted 8 lines
---
This patch has been tested on a virtual USB device emulated in QEMU. I'm still waiting for test results based on real hardware, but the bug is rather obvious is and the fix really simple.
Daniel
Frombc5818593a73dfe895b329cd5f6c95b72d641e9eMon Sep 17 00:00:00 2001
From: Daniel Mack <[email protected]>
Date: Sun, 10 Jun 2012 22:31:15 +0200
Subject: [PATCH] USB: fix gathering of interface associations
TEAC's UD-H01 (and probably other devices) have a gap in the interface number allocation in their descriptors:
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 220
bNumInterfaces 3
[...]
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
[...]
Interface Association:
bLength 8
bDescriptorType 11
bFirstInterface 2
bInterfaceCount 2
bFunctionClass 1 Audio
bFunctionSubClass 0
bFunctionProtocol 32
iFunction 4
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 2
bAlternateSetting 0
[...]Once a configuration is selected on this device, usb_set_configuration() walks the known interfaces of a given configuration and calls find_iad() on each of them to set the interface association pointer the interface is included in.
The problem here is that the loop varibale index is taken for the interface number in the comparison logic that gathers the association. Which is fine as long as the descriptors are sane.
In the case above, however, the logic gets out of sync and the interface association fields of all interfaces beyond the interface number gap are wrong.
Fix this by passing the interface's bInterfaceNumber to find_iad() instead.
--- drivers/usb/core/message.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/usb/core/message.c +2 -1
@@ -1838,7 +1838,6 @@ free_interfaces: intfc = cp->intf_cache[i]; intf->altsetting = intfc->altsetting; intf->num_altsetting = intfc->num_altsetting; - intf->intf_assoc =find_iad (dev, cp, i);kref_get (&intfc->ref); alt =usb_altnum_to_altsetting (intf,0 );
@@ -1851,6 +1850,8 @@ free_interfaces:if (!alt) alt = &intf->altsetting[0 ]; + intf->intf_assoc = +find_iad (dev, cp, alt->desc.bInterfaceNumber); intf->cur_altsetting = alt;usb_enable_interface (dev, intf, true); intf->dev.parent = &dev->dev;
Signature · 1 line
1.7.10.2
Quoted 7 lines · Daniel Mack
Quoted 2 lines · Daniel Mack
TEAC's UD-H01 (and probably other devices) have a gap in the interface number allocation of their descriptors:
I now got a report from Sergio Tabanelli who tried this patch on real hardware, and he confirmed the fix. I added some more people to the patch description and copied stable@ as well.
Daniel,
just for information, I only can try the patch on real hardware (TEAC UD-H01) during this week-end.
btw, thanks a lot for your effort on this patch.
bEN
Quoted 9 lines · Daniel Mack
Quoted 2 lines · Daniel Mack
TEAC's UD-H01 (and probably other devices) have a gap in the interface number allocation of their descriptors:
I now got a report from Sergio Tabanelli who tried this patch on real hardware, and he confirmed the fix. I added some more people to the patch description and copied stable@ as well.
Greg, can can this go through your tree?
Yup, I'll take it now, thanks.
greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 7 lines · Daniel Mack
Quoted 2 lines · Daniel Mack
TEAC's UD-H01 (and probably other devices) have a gap in the interface number allocation of their descriptors:
I now got a report from Sergio Tabanelli who tried this patch on real hardware, and he confirmed the fix. I added some more people to the patch description and copied stable@ as well.
Your patch just tested here on real hardware (TEAC UD-H01), I confirm it
works: interface is registered (despite UD-H01's buggy descriptors).
Thanks!
bEN