From: Kieran Bingham <kieran@ksquared.org.uk>
To: Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
linux-media@vger.kernel.org
Cc: Guennadi Liakhovetski <g.liakhovetski@gmx.de>,
Olivier BRAUN <olivier.braun@stereolabs.com>,
Troy Kisky <troy.kisky@boundarydevices.com>,
Randy Dunlap <rdunlap@infradead.org>,
Philipp Zabel <philipp.zabel@gmail.com>,
Ezequiel Garcia <ezequiel@collabora.com>,
Kieran Bingham <kieran.bingham@ideasonboard.com>
Subject: [PATCH v5 3/9] media: uvcvideo: Protect queue internals with helper
Date: Tue, 6 Nov 2018 21:27:14 +0000 [thread overview]
Message-ID: <eb1273df174234111a73f2ef6f2a05834175a086.1541534872.git-series.kieran.bingham@ideasonboard.com> (raw)
In-Reply-To: <cover.dd42d667a7f7505b3639149635ef3a0b1431f280.1541534872.git-series.kieran.bingham@ideasonboard.com>
In-Reply-To: <cover.dd42d667a7f7505b3639149635ef3a0b1431f280.1541534872.git-series.kieran.bingham@ideasonboard.com>
From: Kieran Bingham <kieran.bingham@ideasonboard.com>
The URB completion operation obtains the current buffer by reading
directly into the queue internal interface.
Protect this queue abstraction by providing a helper
uvc_queue_get_current_buffer() which can be used by both the decode
task, and the uvc_queue_next_buffer() functions.
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
v2:
- Fix coding style of conditional statements
v3:
- No change
v4:
- Rebase on top of linux-media/master (v4.16-rc4, metadata additions)
drivers/media/usb/uvc/uvc_queue.c | 33 +++++++++++++++++++++++++++-----
drivers/media/usb/uvc/uvc_video.c | 6 +-----
drivers/media/usb/uvc/uvcvideo.h | 1 +-
3 files changed, 30 insertions(+), 10 deletions(-)
diff --git a/drivers/media/usb/uvc/uvc_queue.c b/drivers/media/usb/uvc/uvc_queue.c
index 8964e16f2b22..74f9483911d0 100644
--- a/drivers/media/usb/uvc/uvc_queue.c
+++ b/drivers/media/usb/uvc/uvc_queue.c
@@ -430,6 +430,33 @@ void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect)
spin_unlock_irqrestore(&queue->irqlock, flags);
}
+/*
+ * uvc_queue_get_current_buffer: Obtain the current working output buffer
+ *
+ * Buffers may span multiple packets, and even URBs, therefore the active buffer
+ * remains on the queue until the EOF marker.
+ */
+static struct uvc_buffer *
+__uvc_queue_get_current_buffer(struct uvc_video_queue *queue)
+{
+ if (list_empty(&queue->irqqueue))
+ return NULL;
+
+ return list_first_entry(&queue->irqqueue, struct uvc_buffer, queue);
+}
+
+struct uvc_buffer *uvc_queue_get_current_buffer(struct uvc_video_queue *queue)
+{
+ struct uvc_buffer *nextbuf;
+ unsigned long flags;
+
+ spin_lock_irqsave(&queue->irqlock, flags);
+ nextbuf = __uvc_queue_get_current_buffer(queue);
+ spin_unlock_irqrestore(&queue->irqlock, flags);
+
+ return nextbuf;
+}
+
struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue,
struct uvc_buffer *buf)
{
@@ -446,11 +473,7 @@ struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue,
spin_lock_irqsave(&queue->irqlock, flags);
list_del(&buf->queue);
- if (!list_empty(&queue->irqqueue))
- nextbuf = list_first_entry(&queue->irqqueue, struct uvc_buffer,
- queue);
- else
- nextbuf = NULL;
+ nextbuf = __uvc_queue_get_current_buffer(queue);
spin_unlock_irqrestore(&queue->irqlock, flags);
buf->state = buf->error ? UVC_BUF_STATE_ERROR : UVC_BUF_STATE_DONE;
diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
index 6d4384695964..7a7779e1b466 100644
--- a/drivers/media/usb/uvc/uvc_video.c
+++ b/drivers/media/usb/uvc/uvc_video.c
@@ -1484,11 +1484,7 @@ static void uvc_video_complete(struct urb *urb)
return;
}
- spin_lock_irqsave(&queue->irqlock, flags);
- if (!list_empty(&queue->irqqueue))
- buf = list_first_entry(&queue->irqqueue, struct uvc_buffer,
- queue);
- spin_unlock_irqrestore(&queue->irqlock, flags);
+ buf = uvc_queue_get_current_buffer(queue);
if (vb2_qmeta) {
spin_lock_irqsave(&qmeta->irqlock, flags);
diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h
index f7f8db6fc91a..bdb6d8daedab 100644
--- a/drivers/media/usb/uvc/uvcvideo.h
+++ b/drivers/media/usb/uvc/uvcvideo.h
@@ -725,6 +725,7 @@ int uvc_queue_streamoff(struct uvc_video_queue *queue, enum v4l2_buf_type type);
void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect);
struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue,
struct uvc_buffer *buf);
+struct uvc_buffer *uvc_queue_get_current_buffer(struct uvc_video_queue *queue);
int uvc_queue_mmap(struct uvc_video_queue *queue,
struct vm_area_struct *vma);
__poll_t uvc_queue_poll(struct uvc_video_queue *queue, struct file *file,
--
git-series 0.9.1
next prev parent reply other threads:[~2018-11-07 6:54 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-06 21:27 [PATCH v5 0/9] Asynchronous UVC Kieran Bingham
2018-11-06 21:27 ` [PATCH v5 1/9] media: uvcvideo: Refactor URB descriptors Kieran Bingham
2018-11-06 21:27 ` [PATCH v5 2/9] media: uvcvideo: Convert decode functions to use new context structure Kieran Bingham
2018-11-06 21:27 ` Kieran Bingham [this message]
2018-11-06 21:27 ` [PATCH v5 4/9] media: uvcvideo: queue: Simplify spin-lock usage Kieran Bingham
2018-11-06 21:27 ` [PATCH v5 5/9] media: uvcvideo: queue: Support asynchronous buffer handling Kieran Bingham
2018-11-06 22:38 ` Laurent Pinchart
2018-11-06 21:27 ` [PATCH v5 6/9] media: uvcvideo: Move decode processing to process context Kieran Bingham
2018-11-06 22:58 ` Laurent Pinchart
2018-11-07 12:22 ` Kieran Bingham
2018-11-06 21:27 ` [PATCH v5 7/9] media: uvcvideo: Split uvc_video_enable into two Kieran Bingham
2018-11-06 23:08 ` Laurent Pinchart
2018-11-07 12:20 ` Kieran Bingham
2018-11-06 21:27 ` [PATCH v5 8/9] media: uvcvideo: Rename uvc_{un,}init_video() Kieran Bingham
2018-11-06 23:13 ` Laurent Pinchart
2018-11-07 14:30 ` Kieran Bingham
2018-11-07 20:25 ` Laurent Pinchart
2018-11-09 15:41 ` Philipp Zabel
2018-11-09 16:08 ` Kieran Bingham
2018-11-06 21:27 ` [PATCH v5 9/9] media: uvcvideo: Utilise for_each_uvc_urb iterator Kieran Bingham
2018-11-06 23:21 ` Laurent Pinchart
2018-11-07 13:50 ` Kieran Bingham
2018-11-06 23:31 ` [PATCH v5 0/9] Asynchronous UVC Laurent Pinchart
2018-11-08 17:01 ` Laurent Pinchart
2018-11-09 13:25 ` Kieran Bingham
2018-11-27 20:17 ` Pavel Machek
2018-11-27 21:48 ` Laurent Pinchart
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=eb1273df174234111a73f2ef6f2a05834175a086.1541534872.git-series.kieran.bingham@ideasonboard.com \
--to=kieran@ksquared.org.uk \
--cc=ezequiel@collabora.com \
--cc=g.liakhovetski@gmx.de \
--cc=kieran.bingham@ideasonboard.com \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-media@vger.kernel.org \
--cc=olivier.braun@stereolabs.com \
--cc=philipp.zabel@gmail.com \
--cc=rdunlap@infradead.org \
--cc=troy.kisky@boundarydevices.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).