All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCHv2] usb: usb_parse_endpoint ignore reserved bits
@ 2024-04-18 11:02 Oliver Neukum
  2024-04-18 13:00 ` Greg KH
  2024-04-18 15:51 ` Alan Stern
  0 siblings, 2 replies; 3+ messages in thread
From: Oliver Neukum @ 2024-04-18 11:02 UTC (permalink / raw)
  To: gregkh, stern, linux-usb; +Cc: Oliver Neukum

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.

Signed-off-by: Oliver Neukum <oneukum@suse.com>

V2: Improved commit log
---
 drivers/usb/core/config.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c
index 8fd4208d17db..43c5ed256e6e 100644
--- a/drivers/usb/core/config.c
+++ b/drivers/usb/core/config.c
@@ -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;
 	}
 
-- 
2.44.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCHv2] usb: usb_parse_endpoint ignore reserved bits
  2024-04-18 11:02 [PATCHv2] usb: usb_parse_endpoint ignore reserved bits Oliver Neukum
@ 2024-04-18 13:00 ` Greg KH
  2024-04-18 15:51 ` Alan Stern
  1 sibling, 0 replies; 3+ messages in thread
From: Greg KH @ 2024-04-18 13:00 UTC (permalink / raw)
  To: Oliver Neukum; +Cc: gregkh, stern, linux-usb

On Thu, Apr 18, 2024 at 01:02:21PM +0200, Oliver Neukum wrote:
> 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.
> 
> Signed-off-by: Oliver Neukum <oneukum@suse.com>
> 
> V2: Improved commit log

Nit, "V2" goes below the --- line.

> ---
>  drivers/usb/core/config.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c
> index 8fd4208d17db..43c5ed256e6e 100644
> --- a/drivers/usb/core/config.c
> +++ b/drivers/usb/core/config.c
> @@ -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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCHv2] usb: usb_parse_endpoint ignore reserved bits
  2024-04-18 11:02 [PATCHv2] usb: usb_parse_endpoint ignore reserved bits Oliver Neukum
  2024-04-18 13:00 ` Greg KH
@ 2024-04-18 15:51 ` Alan Stern
  1 sibling, 0 replies; 3+ messages in thread
From: Alan Stern @ 2024-04-18 15:51 UTC (permalink / raw)
  To: Oliver Neukum; +Cc: gregkh, linux-usb

On Thu, Apr 18, 2024 at 01:02:21PM +0200, Oliver Neukum wrote:
> 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.
> 
> Signed-off-by: Oliver Neukum <oneukum@suse.com>
> 
> V2: Improved commit log
> ---
>  drivers/usb/core/config.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c
> index 8fd4208d17db..43c5ed256e6e 100644
> --- a/drivers/usb/core/config.c
> +++ b/drivers/usb/core/config.c
> @@ -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.

> +	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

> +		    cfgno, inum, asnum);
>  		goto skip_to_next_endpoint_or_interface_descriptor;
>  	}
>  
> -- 
> 2.44.0
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-04-18 15:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-18 11:02 [PATCHv2] usb: usb_parse_endpoint ignore reserved bits Oliver Neukum
2024-04-18 13:00 ` Greg KH
2024-04-18 15:51 ` Alan Stern

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.