diff mbox series

[2/2] usb: gadget: uvc: Remove nested locking

Message ID 20231215210746.821494-2-arakesh@google.com (mailing list archive)
State Superseded
Headers show
Series [1/2] usb: gadget: uvc: Fix use are free during STREAMOFF | expand

Commit Message

Avichal Rakesh Dec. 15, 2023, 9:07 p.m. UTC
When handling error status from uvcg_video_usb_req_queue,
uvc_video_complete currently calls uvcg_queue_cancel with
video->req_lock held. uvcg_queue_cancel internally locks
queue->irqlock, which nests queue->irqlock inside
video->req_lock. This isn't a functional bug at the
moment, but does open up possibilities for ABBA
deadlocks in the future.

This patch fixes the accidental nesting by dropping
video->req_lock before calling uvcg_queue_cancel.

Signed-off-by: Avichal Rakesh <arakesh@google.com>
---
 drivers/usb/gadget/function/uvc_video.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Greg KH Jan. 4, 2024, 2:19 p.m. UTC | #1
On Fri, Dec 15, 2023 at 01:07:45PM -0800, Avichal Rakesh wrote:
> When handling error status from uvcg_video_usb_req_queue,
> uvc_video_complete currently calls uvcg_queue_cancel with
> video->req_lock held. uvcg_queue_cancel internally locks
> queue->irqlock, which nests queue->irqlock inside
> video->req_lock. This isn't a functional bug at the
> moment, but does open up possibilities for ABBA
> deadlocks in the future.
> 
> This patch fixes the accidental nesting by dropping
> video->req_lock before calling uvcg_queue_cancel.
> 
> Signed-off-by: Avichal Rakesh <arakesh@google.com>
> ---
>  drivers/usb/gadget/function/uvc_video.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)

Again, what commit does this fix?

thanks,

greg k-h
diff mbox series

Patch

diff --git a/drivers/usb/gadget/function/uvc_video.c b/drivers/usb/gadget/function/uvc_video.c
index e5db1be14ca3..d15b9b4c4fcc 100644
--- a/drivers/usb/gadget/function/uvc_video.c
+++ b/drivers/usb/gadget/function/uvc_video.c
@@ -469,13 +469,15 @@  uvc_video_complete(struct usb_ep *ep, struct usb_request *req)
 			 * Put request back in req_free for it to be cleaned
 			 * up later.
 			 */
-			uvcg_queue_cancel(queue, 0);
 			list_add_tail(&to_queue->list, &video->req_free);
 		}
 	} else {
 		uvc_video_free_request(ureq, ep);
+		ret = 0;
 	}
 	spin_unlock_irqrestore(&video->req_lock, flags);
+	if (ret < 0)
+		uvcg_queue_cancel(queue, 0);
 }
 
 static int