All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] usb: ehci: Use endpoint in URB to get maxpacket
@ 2022-08-24 19:38 Khalid Masum
  2022-08-25 14:18 ` Alan Stern
  0 siblings, 1 reply; 2+ messages in thread
From: Khalid Masum @ 2022-08-24 19:38 UTC (permalink / raw)
  To: Alan Stern, Greg Kroah-Hartman, linux-usb, linux-kernel
  Cc: Jack Pham, Manu Gautam, Khalid Masum

usb_maxpacket() looks up the endpoint number in the pipe which can fail
if the interface or configuration changes before the routine is called.
This is unexpected and may even cause a modulo by zero afterwards.

So use usb_endpoint_maxp() routine which uses the endpoint stored in URB
to get the maxpacket.

Addresses-Coverity: 744857 ("Division or modulo by zero")
Addresses-Coverity: 1487371 ("Division or modulo by zero")
Suggested-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Khalid Masum <khalid.masum.92@gmail.com>
---
Changes since v1:
 - Update commit description
 - Use usb_endpoint_maxp() instead of checking whether getting maxpacket
   failed
 - Link: https://lore.kernel.org/lkml/20220823182758.13401-1-khalid.masum.92@gmail.com/

 drivers/usb/host/ehci-q.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c
index 807e64991e3e..666f5c4db25a 100644
--- a/drivers/usb/host/ehci-q.c
+++ b/drivers/usb/host/ehci-q.c
@@ -645,7 +645,7 @@ qh_urb_transaction (
 		token |= (1 /* "in" */ << 8);
 	/* else it's already initted to "out" pid (0 << 8) */
 
-	maxpacket = usb_maxpacket(urb->dev, urb->pipe);
+	maxpacket = usb_endpoint_maxp(&urb->ep->desc);
 
 	/*
 	 * buffer gets wrapped in one or more qtds;
@@ -1218,7 +1218,7 @@ static int ehci_submit_single_step_set_feature(
 
 	token |= (1 /* "in" */ << 8);  /*This is IN stage*/
 
-	maxpacket = usb_maxpacket(urb->dev, urb->pipe);
+	maxpacket = usb_endpoint_maxp(&urb->ep->desc);
 
 	qtd_fill(ehci, qtd, buf, len, token, maxpacket);
 
-- 
2.37.1


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

* Re: [PATCH v2] usb: ehci: Use endpoint in URB to get maxpacket
  2022-08-24 19:38 [PATCH v2] usb: ehci: Use endpoint in URB to get maxpacket Khalid Masum
@ 2022-08-25 14:18 ` Alan Stern
  0 siblings, 0 replies; 2+ messages in thread
From: Alan Stern @ 2022-08-25 14:18 UTC (permalink / raw)
  To: Khalid Masum
  Cc: Greg Kroah-Hartman, linux-usb, linux-kernel, Jack Pham, Manu Gautam

On Thu, Aug 25, 2022 at 01:38:13AM +0600, Khalid Masum wrote:
> usb_maxpacket() looks up the endpoint number in the pipe which can fail
> if the interface or configuration changes before the routine is called.
> This is unexpected and may even cause a modulo by zero afterwards.
> 
> So use usb_endpoint_maxp() routine which uses the endpoint stored in URB
> to get the maxpacket.
> 
> Addresses-Coverity: 744857 ("Division or modulo by zero")
> Addresses-Coverity: 1487371 ("Division or modulo by zero")
> Suggested-by: Alan Stern <stern@rowland.harvard.edu>
> Signed-off-by: Khalid Masum <khalid.masum.92@gmail.com>
> ---
> Changes since v1:
>  - Update commit description
>  - Use usb_endpoint_maxp() instead of checking whether getting maxpacket
>    failed
>  - Link: https://lore.kernel.org/lkml/20220823182758.13401-1-khalid.masum.92@gmail.com/
> 
>  drivers/usb/host/ehci-q.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c
> index 807e64991e3e..666f5c4db25a 100644
> --- a/drivers/usb/host/ehci-q.c
> +++ b/drivers/usb/host/ehci-q.c
> @@ -645,7 +645,7 @@ qh_urb_transaction (
>  		token |= (1 /* "in" */ << 8);
>  	/* else it's already initted to "out" pid (0 << 8) */
>  
> -	maxpacket = usb_maxpacket(urb->dev, urb->pipe);
> +	maxpacket = usb_endpoint_maxp(&urb->ep->desc);
>  
>  	/*
>  	 * buffer gets wrapped in one or more qtds;
> @@ -1218,7 +1218,7 @@ static int ehci_submit_single_step_set_feature(
>  
>  	token |= (1 /* "in" */ << 8);  /*This is IN stage*/
>  
> -	maxpacket = usb_maxpacket(urb->dev, urb->pipe);
> +	maxpacket = usb_endpoint_maxp(&urb->ep->desc);
>  
>  	qtd_fill(ehci, qtd, buf, len, token, maxpacket);

Acked-by: Alan Stern <stern@rowland.harvard.edu>

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

end of thread, other threads:[~2022-08-25 14:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-24 19:38 [PATCH v2] usb: ehci: Use endpoint in URB to get maxpacket Khalid Masum
2022-08-25 14:18 ` 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.