Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: ezequiel at collabora.com (Ezequiel Garcia)
Subject: [PATCH v4 1/6] mem2mem: Require capture and output mutexes to match
Date: Thu,  2 Aug 2018 17:48:45 -0300	[thread overview]
Message-ID: <20180802204850.31633-2-ezequiel@collabora.com> (raw)
In-Reply-To: <20180802204850.31633-1-ezequiel@collabora.com>

Currently, all the mem2mem driver either use a single mutex
to lock the capture and output videobuf2 queues, or don't
set any mutex.

This means the mutexes match, and so the mem2mem framework
is able to set the m2m context lock.

Enforce this by making it mandatory for drivers to set
the same capture and output mutex, or not set any mutex at all.

Signed-off-by: Ezequiel Garcia <ezequiel at collabora.com>
---
 drivers/media/v4l2-core/v4l2-mem2mem.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-mem2mem.c b/drivers/media/v4l2-core/v4l2-mem2mem.c
index 0a93c5b173c2..b7005894292c 100644
--- a/drivers/media/v4l2-core/v4l2-mem2mem.c
+++ b/drivers/media/v4l2-core/v4l2-mem2mem.c
@@ -887,12 +887,14 @@ struct v4l2_m2m_ctx *v4l2_m2m_ctx_init(struct v4l2_m2m_dev *m2m_dev,
 	if (ret)
 		goto err;
 	/*
-	 * If both queues use same mutex assign it as the common buffer
-	 * queues lock to the m2m context. This lock is used in the
-	 * v4l2_m2m_ioctl_* helpers.
+	 * Both queues should use same the mutex to lock the m2m context.
+	 * This lock is used in some v4l2_m2m_* helpers.
 	 */
-	if (out_q_ctx->q.lock == cap_q_ctx->q.lock)
-		m2m_ctx->q_lock = out_q_ctx->q.lock;
+	if (WARN_ON(out_q_ctx->q.lock != cap_q_ctx->q.lock)) {
+		ret = -EINVAL;
+		goto err;
+	}
+	m2m_ctx->q_lock = out_q_ctx->q.lock;
 
 	return m2m_ctx;
 err:
-- 
2.18.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kselftest" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

WARNING: multiple messages have this Message-ID (diff)
From: ezequiel@collabora.com (Ezequiel Garcia)
Subject: [PATCH v4 1/6] mem2mem: Require capture and output mutexes to match
Date: Thu,  2 Aug 2018 17:48:45 -0300	[thread overview]
Message-ID: <20180802204850.31633-2-ezequiel@collabora.com> (raw)
Message-ID: <20180802204845.bWsJKwY0o7QgIsu9ryMCFU4J0QMxfC5Bb6z5AH4DWMc@z> (raw)
In-Reply-To: <20180802204850.31633-1-ezequiel@collabora.com>

Currently, all the mem2mem driver either use a single mutex
to lock the capture and output videobuf2 queues, or don't
set any mutex.

This means the mutexes match, and so the mem2mem framework
is able to set the m2m context lock.

Enforce this by making it mandatory for drivers to set
the same capture and output mutex, or not set any mutex at all.

Signed-off-by: Ezequiel Garcia <ezequiel at collabora.com>
---
 drivers/media/v4l2-core/v4l2-mem2mem.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-mem2mem.c b/drivers/media/v4l2-core/v4l2-mem2mem.c
index 0a93c5b173c2..b7005894292c 100644
--- a/drivers/media/v4l2-core/v4l2-mem2mem.c
+++ b/drivers/media/v4l2-core/v4l2-mem2mem.c
@@ -887,12 +887,14 @@ struct v4l2_m2m_ctx *v4l2_m2m_ctx_init(struct v4l2_m2m_dev *m2m_dev,
 	if (ret)
 		goto err;
 	/*
-	 * If both queues use same mutex assign it as the common buffer
-	 * queues lock to the m2m context. This lock is used in the
-	 * v4l2_m2m_ioctl_* helpers.
+	 * Both queues should use same the mutex to lock the m2m context.
+	 * This lock is used in some v4l2_m2m_* helpers.
 	 */
-	if (out_q_ctx->q.lock == cap_q_ctx->q.lock)
-		m2m_ctx->q_lock = out_q_ctx->q.lock;
+	if (WARN_ON(out_q_ctx->q.lock != cap_q_ctx->q.lock)) {
+		ret = -EINVAL;
+		goto err;
+	}
+	m2m_ctx->q_lock = out_q_ctx->q.lock;
 
 	return m2m_ctx;
 err:
-- 
2.18.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kselftest" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2018-08-02 20:48 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-02 20:48 [PATCH v4 0/6] Make sure .device_run is always called in non-atomic context ezequiel
2018-08-02 20:48 ` Ezequiel Garcia
2018-08-02 20:48 ` ezequiel [this message]
2018-08-02 20:48   ` [PATCH v4 1/6] mem2mem: Require capture and output mutexes to match Ezequiel Garcia
2018-08-02 20:48 ` [PATCH v4 2/6] v4l2-ioctl.c: simplify locking for m2m devices ezequiel
2018-08-02 20:48   ` Ezequiel Garcia
2018-08-02 20:48 ` [PATCH v4 3/6] v4l2-mem2mem: Avoid v4l2_m2m_prepare_buf from scheduling a job ezequiel
2018-08-02 20:48   ` Ezequiel Garcia
2018-08-02 20:48 ` [PATCH v4 4/6] v4l2-mem2mem: Simplify exiting the function in __v4l2_m2m_try_schedule ezequiel
2018-08-02 20:48   ` Ezequiel Garcia
2018-08-02 20:48 ` [PATCH v4 5/6] v4l2-mem2mem: Avoid calling .device_run in v4l2_m2m_job_finish ezequiel
2018-08-02 20:48   ` Ezequiel Garcia
2018-08-02 20:48 ` [PATCH v4 6/6] selftests: media_tests: Add a memory-to-memory concurrent stress test ezequiel
2018-08-02 20:48   ` Ezequiel Garcia
2018-08-31 13:35 ` [PATCH v4 0/6] Make sure .device_run is always called in non-atomic context ezequiel
2018-08-31 13:35   ` 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=20180802204850.31633-2-ezequiel@collabora.com \
    --to=linux-kselftest@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