Linux Media Controller development
 help / color / mirror / Atom feed
From: Ezequiel Garcia <ezequiel@collabora.com>
To: linux-media@vger.kernel.org
Cc: Hans Verkuil <hans.verkuil@cisco.com>,
	kernel@collabora.com, Ezequiel Garcia <ezequiel@collabora.com>
Subject: [PATCH v4 09/17] davinci_vpfe: Add video_device and vb2_queue locks
Date: Fri, 15 Jun 2018 16:07:29 -0300	[thread overview]
Message-ID: <20180615190737.24139-10-ezequiel@collabora.com> (raw)
In-Reply-To: <20180615190737.24139-1-ezequiel@collabora.com>

Currently, this driver does not serialize its video4linux
ioctls, which is a bug, as race conditions might appear.

In addition, video_device and vb2_queue locks are now both
mandatory. Add them, and implement wait_prepare and
wait_finish.

To stay on the safe side, this commit uses a single mutex
for both locks. Better latency can be obtained by separating
these if needed.

Signed-off-by: Ezequiel Garcia <ezequiel@collabora.com>
---
 drivers/staging/media/davinci_vpfe/vpfe_video.c | 6 +++++-
 drivers/staging/media/davinci_vpfe/vpfe_video.h | 2 +-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c b/drivers/staging/media/davinci_vpfe/vpfe_video.c
index 390fc98d07dd..1269a983455e 100644
--- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
+++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
@@ -1312,6 +1312,8 @@ static const struct vb2_ops video_qops = {
 	.stop_streaming		= vpfe_stop_streaming,
 	.buf_cleanup		= vpfe_buf_cleanup,
 	.buf_queue		= vpfe_buffer_queue,
+	.wait_prepare		= vb2_ops_wait_prepare,
+	.wait_finish		= vb2_ops_wait_finish,
 };
 
 /*
@@ -1357,6 +1359,7 @@ static int vpfe_reqbufs(struct file *file, void *priv,
 	q->buf_struct_size = sizeof(struct vpfe_cap_buffer);
 	q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
 	q->dev = vpfe_dev->pdev;
+	q->lock = &video->lock;
 
 	ret = vb2_queue_init(q);
 	if (ret) {
@@ -1598,17 +1601,18 @@ int vpfe_video_init(struct vpfe_video_device *video, const char *name)
 		return -EINVAL;
 	}
 	/* Initialize field of video device */
+	mutex_init(&video->lock);
 	video->video_dev.release = video_device_release;
 	video->video_dev.fops = &vpfe_fops;
 	video->video_dev.ioctl_ops = &vpfe_ioctl_ops;
 	video->video_dev.minor = -1;
 	video->video_dev.tvnorms = 0;
+	video->video_dev.lock = &video->lock;
 	snprintf(video->video_dev.name, sizeof(video->video_dev.name),
 		 "DAVINCI VIDEO %s %s", name, direction);
 
 	spin_lock_init(&video->irqlock);
 	spin_lock_init(&video->dma_queue_lock);
-	mutex_init(&video->lock);
 	ret = media_entity_pads_init(&video->video_dev.entity,
 				1, &video->pad);
 	if (ret < 0)
diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.h b/drivers/staging/media/davinci_vpfe/vpfe_video.h
index 22136d3dadcb..4bbd219e8329 100644
--- a/drivers/staging/media/davinci_vpfe/vpfe_video.h
+++ b/drivers/staging/media/davinci_vpfe/vpfe_video.h
@@ -128,7 +128,7 @@ struct vpfe_video_device {
 	spinlock_t				irqlock;
 	/* IRQ lock for DMA queue */
 	spinlock_t				dma_queue_lock;
-	/* lock used to access this structure */
+	/* lock used to serialize all video4linux ioctls */
 	struct mutex				lock;
 	/* number of users performing IO */
 	u32					io_usrs;
-- 
2.17.1

  parent reply	other threads:[~2018-06-15 19:08 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-15 19:07 [PATCH v4 00/17] v4l2 core: push ioctl lock down to ioctl handler Ezequiel Garcia
2018-06-15 19:07 ` [PATCH v4 01/17] v4l2-ioctl.c: use correct vb2_queue lock for m2m devices Ezequiel Garcia
2018-06-15 19:07 ` [PATCH v4 02/17] sta2x11: Add video_device and vb2_queue locks Ezequiel Garcia
2018-06-15 19:07 ` [PATCH v4 03/17] omap4iss: Add vb2_queue lock Ezequiel Garcia
2018-07-02  8:28   ` Hans Verkuil
2018-07-06 15:24     ` Ezequiel Garcia
2018-06-15 19:07 ` [PATCH v4 04/17] omap3isp: " Ezequiel Garcia
2018-06-18  7:31   ` Hans Verkuil
2018-06-20 17:42     ` [PATCH v5 " Ezequiel Garcia
2018-06-21  8:18       ` Hans Verkuil
2018-06-22  3:51         ` Ezequiel Garcia
2018-06-22  3:53       ` [PATCH v6 " Ezequiel Garcia
2018-07-02 16:49         ` Laurent Pinchart
2018-07-06 15:11           ` Ezequiel Garcia
2018-06-15 19:07 ` [PATCH v4 05/17] mtk-mdp: Add locks for capture and output vb2_queues Ezequiel Garcia
2018-06-15 19:07 ` [PATCH v4 06/17] s5p-g2d: Implement wait_prepare and wait_finish Ezequiel Garcia
2018-06-15 19:07 ` [PATCH v4 07/17] staging: bcm2835-camera: Provide lock for vb2_queue Ezequiel Garcia
2018-06-15 19:07 ` [PATCH v4 08/17] venus: Add video_device and vb2_queue locks Ezequiel Garcia
2018-06-15 19:07 ` Ezequiel Garcia [this message]
2018-06-15 19:07 ` [PATCH v4 10/17] mx_emmaprp: Implement wait_prepare and wait_finish Ezequiel Garcia
2018-06-15 19:07 ` [PATCH v4 11/17] m2m-deinterlace: " Ezequiel Garcia
2018-06-15 19:07 ` [PATCH v4 12/17] stk1160: Set the vb2_queue lock before calling vb2_queue_init Ezequiel Garcia
2018-06-15 19:07 ` [PATCH v4 13/17] dvb-core: Provide lock for vb2_queue Ezequiel Garcia
2018-06-15 19:07 ` [PATCH v4 14/17] videobuf2-core: require q->lock Ezequiel Garcia
2018-06-15 19:07 ` [PATCH v4 15/17] videobuf2: assume q->lock is always set Ezequiel Garcia
2018-06-15 19:07 ` [PATCH v4 16/17] v4l2-ioctl.c: assume queue->lock " Ezequiel Garcia
2018-06-15 19:07 ` [PATCH v4 17/17] media: Remove wait_{prepare, finish} Ezequiel Garcia
2018-06-29 18:12 ` [PATCH v4 00/17] v4l2 core: push ioctl lock down to ioctl handler Ezequiel Garcia

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=20180615190737.24139-10-ezequiel@collabora.com \
    --to=ezequiel@collabora.com \
    --cc=hans.verkuil@cisco.com \
    --cc=kernel@collabora.com \
    --cc=linux-media@vger.kernel.org \
    /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