Commit 58da4e57 authored by Michal Grzeschik's avatar Michal Grzeschik Committed by Greg Kroah-Hartman
Browse files

usb: gadget: uvc: rework complete handler



We refactor the complete handler since the return path with the
locking are really difficult to follow. Just simplify the function by
switching the logic return it on an disabled endpoint early. This way
the second level of indentation can be removed.

Signed-off-by: default avatarMichael Grzeschik <m.grzeschik@pengutronix.de>
Link: https://lore.kernel.org/r/20240214-uvc-gadget-cleanup-v1-3-de6d78780459@pengutronix.de


Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 5e7ea65d
Loading
Loading
Loading
Loading
+48 −47
Original line number Diff line number Diff line
@@ -370,6 +370,7 @@ uvc_video_complete(struct usb_ep *ep, struct usb_request *req)
	struct uvc_video *video = ureq->video;
	struct uvc_video_queue *queue = &video->queue;
	struct uvc_buffer *last_buf;
	struct usb_request *to_queue = req;
	unsigned long flags;
	bool is_bulk = video->max_payload_size;
	int ret = 0;
@@ -425,7 +426,14 @@ uvc_video_complete(struct usb_ep *ep, struct usb_request *req)
	 * we're still streaming before queueing the usb_request
	 * back to req_free
	 */
	if (video->is_enabled) {
	if (!video->is_enabled) {
		uvc_video_free_request(ureq, ep);
		spin_unlock_irqrestore(&video->req_lock, flags);
		uvcg_queue_cancel(queue, 0);

		return;
	}

	/*
	 * Here we check whether any request is available in the ready
	 * list. If it is, queue it to the ep and add the current
@@ -436,8 +444,6 @@ uvc_video_complete(struct usb_ep *ep, struct usb_request *req)
	 * be a situation where the req_free list is completely out of
	 * requests and cannot recover.
	 */
		struct usb_request *to_queue = req;

	to_queue->length = 0;
	if (!list_empty(&video->req_ready)) {
		to_queue = list_first_entry(&video->req_ready,
@@ -471,13 +477,8 @@ uvc_video_complete(struct usb_ep *ep, struct usb_request *req)
		 */
		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