mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH next] fixup! usb: xhci: reset endpoint on USB stall
@ 2024-03-01  7:44 Ahmad Fatoum
  2024-03-01  9:18 ` Sascha Hauer
  2024-03-01  9:19 ` Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2024-03-01  7:44 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

usb: xhci: call dma_unmap_single in all error paths

A new early exit for stalled USB was added that resets the endpoint
before returning an error code to the caller.

This unintentionally happened before unmapping the buffer, which is
detected by CONFIG_DMA_API_DEBUG:

  usb2-0: Resetting EP 0...
  WARNING: dwc3 2f00000.usb@2f00000.of: from-device mapping 0xbdf96680+0xff: duplicate mapping

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/usb/host/xhci-ring.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 5f68bc7c2f35..691d9c7463ad 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -1045,15 +1045,16 @@ int xhci_ctrl_tx(struct usb_device *udev, unsigned long pipe,
 
 	record_transfer_result(udev, event, length);
 	xhci_acknowledge_event(ctrl);
-	if (udev->status == USB_ST_STALLED) {
-		reset_ep(udev, ep_index, timeout_ms);
-		return -EPIPE;
-	}
 
 	/* Invalidate buffer to make it available to usb-core */
 	if (length > 0)
 		dma_unmap_single(ctrl->host.hw_dev, map, length, direction);
 
+	if (udev->status == USB_ST_STALLED) {
+		reset_ep(udev, ep_index, timeout_ms);
+		return -EPIPE;
+	}
+
 	if (GET_COMP_CODE(le32_to_cpu(event->trans_event.transfer_len))
 			== COMP_SHORT_TX) {
 		/* Short data stage, clear up additional status stage event */
-- 
2.39.2




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

* Re: [PATCH next] fixup! usb: xhci: reset endpoint on USB stall
  2024-03-01  7:44 [PATCH next] fixup! usb: xhci: reset endpoint on USB stall Ahmad Fatoum
@ 2024-03-01  9:18 ` Sascha Hauer
  2024-03-01  9:19 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2024-03-01  9:18 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Fri, Mar 01, 2024 at 08:44:00AM +0100, Ahmad Fatoum wrote:
> usb: xhci: call dma_unmap_single in all error paths
> 
> A new early exit for stalled USB was added that resets the endpoint
> before returning an error code to the caller.
> 
> This unintentionally happened before unmapping the buffer, which is
> detected by CONFIG_DMA_API_DEBUG:
> 
>   usb2-0: Resetting EP 0...
>   WARNING: dwc3 2f00000.usb@2f00000.of: from-device mapping 0xbdf96680+0xff: duplicate mapping
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  drivers/usb/host/xhci-ring.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)

The patch is already in master, so I applied the fix there.

Sascha

> 
> diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
> index 5f68bc7c2f35..691d9c7463ad 100644
> --- a/drivers/usb/host/xhci-ring.c
> +++ b/drivers/usb/host/xhci-ring.c
> @@ -1045,15 +1045,16 @@ int xhci_ctrl_tx(struct usb_device *udev, unsigned long pipe,
>  
>  	record_transfer_result(udev, event, length);
>  	xhci_acknowledge_event(ctrl);
> -	if (udev->status == USB_ST_STALLED) {
> -		reset_ep(udev, ep_index, timeout_ms);
> -		return -EPIPE;
> -	}
>  
>  	/* Invalidate buffer to make it available to usb-core */
>  	if (length > 0)
>  		dma_unmap_single(ctrl->host.hw_dev, map, length, direction);
>  
> +	if (udev->status == USB_ST_STALLED) {
> +		reset_ep(udev, ep_index, timeout_ms);
> +		return -EPIPE;
> +	}
> +
>  	if (GET_COMP_CODE(le32_to_cpu(event->trans_event.transfer_len))
>  			== COMP_SHORT_TX) {
>  		/* Short data stage, clear up additional status stage event */
> -- 
> 2.39.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



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

* Re: [PATCH next] fixup! usb: xhci: reset endpoint on USB stall
  2024-03-01  7:44 [PATCH next] fixup! usb: xhci: reset endpoint on USB stall Ahmad Fatoum
  2024-03-01  9:18 ` Sascha Hauer
@ 2024-03-01  9:19 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2024-03-01  9:19 UTC (permalink / raw)
  To: barebox, Ahmad Fatoum


On Fri, 01 Mar 2024 08:44:00 +0100, Ahmad Fatoum wrote:
> usb: xhci: call dma_unmap_single in all error paths
> 
> A new early exit for stalled USB was added that resets the endpoint
> before returning an error code to the caller.
> 
> This unintentionally happened before unmapping the buffer, which is
> detected by CONFIG_DMA_API_DEBUG:
> 
> [...]

Applied, thanks!

[1/1] fixup! usb: xhci: reset endpoint on USB stall
      https://git.pengutronix.de/cgit/barebox/commit/?id=aed18e44bbd9 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




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

end of thread, other threads:[~2024-03-01  9:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-01  7:44 [PATCH next] fixup! usb: xhci: reset endpoint on USB stall Ahmad Fatoum
2024-03-01  9:18 ` Sascha Hauer
2024-03-01  9:19 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox