Skip to content

Commit

Permalink
usb: gadget: uvc: giveback vb2 buffer on req complete
Browse files Browse the repository at this point in the history
commit 9b969f9 upstream.

On uvc_video_encode_isoc_sg the mapped vb2 buffer is returned
to early. Only after the last usb_request worked with the buffer
it is allowed to give it back to vb2. This patch fixes that.

Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
Link: https://lore.kernel.org/r/20220402232744.3622565-3-m.grzeschik@pengutronix.de
Cc: Dan Vacura <w36195@motorola.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
mgrzeschik authored and gregkh committed Oct 29, 2022
1 parent aee340d commit db11d8c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions drivers/usb/gadget/function/uvc.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ struct uvc_request {
struct uvc_video *video;
struct sg_table sgt;
u8 header[UVCG_REQUEST_HEADER_LEN];
struct uvc_buffer *last_buf;
};

struct uvc_video {
Expand Down
2 changes: 0 additions & 2 deletions drivers/usb/gadget/function/uvc_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,6 @@ void uvcg_complete_buffer(struct uvc_video_queue *queue,
return;
}

list_del(&buf->queue);

buf->buf.field = V4L2_FIELD_NONE;
buf->buf.sequence = queue->sequence++;
buf->buf.vb2_buf.timestamp = ktime_get_ns();
Expand Down
11 changes: 10 additions & 1 deletion drivers/usb/gadget/function/uvc_video.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ uvc_video_encode_bulk(struct usb_request *req, struct uvc_video *video,
if (buf->bytesused == video->queue.buf_used) {
video->queue.buf_used = 0;
buf->state = UVC_BUF_STATE_DONE;
list_del(&buf->queue);
uvcg_complete_buffer(&video->queue, buf);
video->fid ^= UVC_STREAM_FID;

Expand Down Expand Up @@ -154,8 +155,9 @@ uvc_video_encode_isoc_sg(struct usb_request *req, struct uvc_video *video,
video->queue.buf_used = 0;
buf->state = UVC_BUF_STATE_DONE;
buf->offset = 0;
uvcg_complete_buffer(&video->queue, buf);
list_del(&buf->queue);
video->fid ^= UVC_STREAM_FID;
ureq->last_buf = buf;
}
}

Expand All @@ -181,6 +183,7 @@ uvc_video_encode_isoc(struct usb_request *req, struct uvc_video *video,
if (buf->bytesused == video->queue.buf_used) {
video->queue.buf_used = 0;
buf->state = UVC_BUF_STATE_DONE;
list_del(&buf->queue);
uvcg_complete_buffer(&video->queue, buf);
video->fid ^= UVC_STREAM_FID;
}
Expand Down Expand Up @@ -231,6 +234,11 @@ uvc_video_complete(struct usb_ep *ep, struct usb_request *req)
uvcg_queue_cancel(queue, 0);
}

if (ureq->last_buf) {
uvcg_complete_buffer(&video->queue, ureq->last_buf);
ureq->last_buf = NULL;
}

spin_lock_irqsave(&video->req_lock, flags);
list_add_tail(&req->list, &video->req_free);
spin_unlock_irqrestore(&video->req_lock, flags);
Expand Down Expand Up @@ -298,6 +306,7 @@ uvc_video_alloc_requests(struct uvc_video *video)
video->ureq[i].req->complete = uvc_video_complete;
video->ureq[i].req->context = &video->ureq[i];
video->ureq[i].video = video;
video->ureq[i].last_buf = NULL;

list_add_tail(&video->ureq[i].req->list, &video->req_free);
/* req_size/PAGE_SIZE + 1 for overruns and + 1 for header */
Expand Down

0 comments on commit db11d8c

Please sign in to comment.