public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH] usb: gadget: uvc: Prevent smmu fault in unstopped stream uvc teardown
@ 2026-01-05  5:07 Udipto Goswami
  2026-01-05  8:51 ` Udipto Goswami
  2026-01-05 15:55 ` Alan Stern
  0 siblings, 2 replies; 9+ messages in thread
From: Udipto Goswami @ 2026-01-05  5:07 UTC (permalink / raw)
  To: Frederic Weisbecker, Greg Kroah-Hartman; +Cc: linux-usb, Udipto Goswami

When switching USB compositions while the camera is streaming, an SMMU
fault can occur because dwc3_remove_requests() unmaps buffers via
dwc3_gadget_giveback() while the controller hardware is still performing
DMA operations on subsequent requests in the started_list.

Fix this by adding a delay in uvc_video_complete() when handling the first
-ESHUTDOWN event  (detected by checking !UVC_QUEUE_DISCONNECTED) to allow
the controller to  complete in-flight DMA and drain its FIFO before
dwc3_remove_requests()  proceeds to unmap remaining buffers,
preventing the SMMU translation fault.

Signed-off-by: Udipto Goswami <udipto.goswami@oss.qualcomm.com>
---
 drivers/usb/gadget/function/uvc_video.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/usb/gadget/function/uvc_video.c b/drivers/usb/gadget/function/uvc_video.c
index fb77b0b21790..04724bd44ab9 100644
--- a/drivers/usb/gadget/function/uvc_video.c
+++ b/drivers/usb/gadget/function/uvc_video.c
@@ -366,7 +366,15 @@ uvc_video_complete(struct usb_ep *ep, struct usb_request *req)
 
 	case -ESHUTDOWN:	/* disconnect from host. */
 		uvcg_dbg(&video->uvc->func, "VS request cancelled.\n");
+		if (!(queue->flags & UVC_QUEUE_DISCONNECTED))
+			delay = 1;
 		uvcg_queue_cancel(queue, 1);
+		if (delay) {
+			if (in_interrupt() || irqs_disabled() || in_atomic())
+				 mdelay(1);
+			else
+				msleep(50);
+		}
 		break;
 
 	default:
-- 
2.34.1


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

end of thread, other threads:[~2026-01-09  1:43 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-05  5:07 [RFC PATCH] usb: gadget: uvc: Prevent smmu fault in unstopped stream uvc teardown Udipto Goswami
2026-01-05  8:51 ` Udipto Goswami
2026-01-05  9:45   ` Selvarasu Ganesan
2026-01-06 10:40     ` Udipto Goswami
2026-01-05 15:55 ` Alan Stern
2026-01-06 10:43   ` Udipto Goswami
2026-01-06 16:53     ` Alan Stern
2026-01-07  4:40       ` Udipto Goswami
2026-01-09  1:42         ` Thinh Nguyen

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