usb: usb_parse_endpoint ignore reserved bits
PATCH v2 1/1 usb: usb_parse_endpoint ignore reserved bits
Reading bEndpointAddress the spec tells is
that
b7 is direction, which must be ignored
b6:4 are reserved which are to be set to zero b3:0 are the endpoint address
In order to be backwards compatible with possible future versions of USB we have to be ready with devices using those bits. That means that we also have to ignore them like we do with the direction bit.
In consequence the only illegal address you can encoding in four bits is endpoint zero, for which no descriptor must exist. Hence the check for exceeding the upper limit on endpoint addresses is removed.
V2: Improved commit log
--- drivers/usb/core/config.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/usb/core/config.c +4 -4
@@ -285,11 +285,11 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, goto skip_to_next_endpoint_or_interface_descriptor; } - i = d->bEndpointAddress & ~USB_ENDPOINT_DIR_MASK ; -if (i >=16 || i ==0 ) { + i = d->bEndpointAddress &0x0f ; +if (i ==0 ) {dev_notice (ddev,"config %d interface %d altsetting %d has an " -"invalid endpoint with address 0x%X, skipping\n" , - cfgno, inum, asnum, d->bEndpointAddress); +"invalid descriptor for the common control endpoint, skipping\n" , + cfgno, inum, asnum); goto skip_to_next_endpoint_or_interface_descriptor; }
Signature · 1 line
2.44.0
Greg KH
maintainerQuoted 17 lines · Oliver Neukum
Reading bEndpointAddress the spec tells is
thatb7 is direction, which must be ignored
b6:4 are reserved which are to be set to zero b3:0 are the endpoint addressIn order to be backwards compatible with possible future versions of USB we have to be ready with devices using those bits. That means that we also have to ignore them like we do with the direction bit.
In consequence the only illegal address you can encoding in four bits is endpoint zero, for which no descriptor must exist. Hence the check for exceeding the upper limit on endpoint addresses is removed.
Quoted 3 lines
Signed-off-by Oliver Neukum <[email protected]>V2: Improved commit log
Nit, "V2" goes below the --- line.
Quoted 9 lines
--- drivers/usb/core/config.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/usb/core/config.c +0
-0
drivers/usb/core/config.c static int usb_parse_endpoint(struct device *ddev, int cfgno, · line 288
Quoted 6 lines
drivers/usb/core/config.c +1
-2@@ -285,11 +285,11 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, goto skip_to_next_endpoint_or_interface_descriptor; } - i = d->bEndpointAddress & ~USB_ENDPOINT_DIR_MASK ; -if (i >=16 || i ==0 ) { + i = d->bEndpointAddress &0x0f ;
Using a #define here instead of 0x0f might be good, right?
thanks,
greg k-h
Quoted 29 lines · Oliver Neukum
Reading bEndpointAddress the spec tells is
thatb7 is direction, which must be ignored
b6:4 are reserved which are to be set to zero b3:0 are the endpoint addressIn order to be backwards compatible with possible future versions of USB we have to be ready with devices using those bits. That means that we also have to ignore them like we do with the direction bit.
In consequence the only illegal address you can encoding in four bits is endpoint zero, for which no descriptor must exist. Hence the check for exceeding the upper limit on endpoint addresses is removed.Signed-off-by Oliver Neukum <[email protected]>V2: Improved commit log
--- drivers/usb/core/config.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/usb/core/config.c +0
-0
drivers/usb/core/config.c static int usb_parse_endpoint(struct device *ddev, int cfgno, · line 288
Quoted 6 lines
drivers/usb/core/config.c +1
-2@@ -285,11 +285,11 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, goto skip_to_next_endpoint_or_interface_descriptor; } - i = d->bEndpointAddress & ~USB_ENDPOINT_DIR_MASK ; -if (i >=16 || i ==0 ) { + i = d->bEndpointAddress &0x0f ;
See my earlier reply. The 0x0f here should be USB_ENDPOINT_NUMBER_MASK. Or even better, you could use the usb_endpoint_num() inline routine.
drivers/usb/core/config.c static int usb_parse_endpoint(struct device *ddev, int cfgno, · line 291
Quoted 5 lines
drivers/usb/core/config.c +2
-2+if (i ==0 ) { dev_notice(ddev, "config %d interface %d altsetting %d has an " -"invalid endpoint with address 0x%X, skipping\n" , - cfgno, inum, asnum, d->bEndpointAddress); + "invalid descriptor for the common control endpoint, skipping\n",
"endpoint 0" would be simpler than "the common control endpoint".
Alan Stern
Quoted 7 lines
drivers/usb/core/config.c +1
-0+ cfgno, inum, asnum); goto skip_to_next_endpoint_or_interface_descriptor; }Signature · 1 line
2.44.0