From: Alexandre Courbot <acourbot@chromium.org>
To: Mauro Carvalho Chehab <mchehab@kernel.org>,
Hans Verkuil <hverkuil@xs4all.nl>,
Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
Pawel Osciak <posciak@chromium.org>,
Marek Szyprowski <m.szyprowski@samsung.com>,
Tomasz Figa <tfiga@chromium.org>,
Sakari Ailus <sakari.ailus@linux.intel.com>,
Gustavo Padovan <gustavo.padovan@collabora.com>
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
Alexandre Courbot <acourbot@chromium.org>
Subject: [RFC PATCH 4/8] media: vb2: add support for requests in QBUF ioctl
Date: Fri, 26 Jan 2018 15:02:12 +0900 [thread overview]
Message-ID: <20180126060216.147918-5-acourbot@chromium.org> (raw)
In-Reply-To: <20180126060216.147918-1-acourbot@chromium.org>
Support the request argument of the QBUF ioctl.
Signed-off-by: Alexandre Courbot <acourbot@chromium.org>
---
drivers/media/v4l2-core/v4l2-ioctl.c | 79 +++++++++++++++++++++++++++++++++++-
1 file changed, 78 insertions(+), 1 deletion(-)
diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
index fdd2f784c264..66f2bda4a279 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -29,6 +29,7 @@
#include <media/v4l2-device.h>
#include <media/videobuf2-v4l2.h>
#include <media/v4l2-mc.h>
+#include <media/media-request.h>
#include <trace/events/v4l2.h>
@@ -965,6 +966,67 @@ static int check_fmt(struct file *file, enum v4l2_buf_type type)
return -EINVAL;
}
+/*
+ * Validate that a given request can be used during an ioctl.
+ *
+ * When using the request API, request file descriptors must be matched against
+ * the actual request object. User-space can pass any file descriptor, so we
+ * need to make sure the call is valid before going further.
+ *
+ * This function looks up the request and associated data and performs the
+ * following sanity checks:
+ *
+ * * Make sure that the entity belongs to the media_device managing the passed
+ * request,
+ * * Make sure that the entity data (if any) is associated to the current file
+ * handler.
+ *
+ * This function returns a pointer to the valid request, or and error code in
+ * case of failure. When successful, a reference to the request is acquired and
+ * must be properly released by the caller.
+ */
+#ifdef CONFIG_MEDIA_CONTROLLER
+static struct media_request *
+check_request(int request, struct file *file, void *fh)
+{
+ struct media_request *req = NULL;
+ struct video_device *vfd = video_devdata(file);
+ struct v4l2_fh *vfh =
+ test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) ? fh : NULL;
+ struct media_entity *entity = &vfd->entity;
+ struct media_request_entity_data *data;
+
+ if (!entity)
+ return ERR_PTR(-EINVAL);
+
+ req = media_request_get_from_fd(request);
+ if (!req)
+ return ERR_PTR(-EINVAL);
+
+ /* Validate that the entity belongs to the correct media_device */
+ if (vfd->v4l2_dev->mdev->req_mgr != req->mgr) {
+ media_request_put(req);
+ return ERR_PTR(-EINVAL);
+ }
+
+ /* Validate that the entity's data belongs to the correct fh */
+ data = media_request_get_entity_data(req, entity, vfh);
+ if (IS_ERR(data)) {
+ media_request_put(req);
+ return ERR_PTR(PTR_ERR(data));
+ }
+
+ return req;
+}
+#else /* CONFIG_MEDIA_CONTROLLER */
+static struct media_request *
+check_request(int request, struct file *file, void *fh)
+{
+ return ERR_PTR(-ENOSYS);
+}
+
+#endif /* CONFIG_MEDIA_CONTROLLER */
+
static void v4l_sanitize_format(struct v4l2_format *fmt)
{
unsigned int offset;
@@ -1902,10 +1964,25 @@ static int v4l_querybuf(const struct v4l2_ioctl_ops *ops,
static int v4l_qbuf(const struct v4l2_ioctl_ops *ops,
struct file *file, void *fh, void *arg)
{
+ struct media_request *req = NULL;
struct v4l2_buffer *p = arg;
int ret = check_fmt(file, p->type);
- return ret ? ret : ops->vidioc_qbuf(file, fh, p);
+ if (ret)
+ return ret;
+
+ if (p->request_fd > 0) {
+ req = check_request(p->request_fd, file, fh);
+ if (IS_ERR(req))
+ return PTR_ERR(req);
+ }
+
+ ret = ops->vidioc_qbuf(file, fh, p);
+
+ if (req)
+ media_request_put(req);
+
+ return ret;
}
static int v4l_dqbuf(const struct v4l2_ioctl_ops *ops,
--
2.16.0.rc1.238.g530d649a79-goog
next prev parent reply other threads:[~2018-01-26 6:02 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-26 6:02 [RFC PATCH 0/8] [media] Request API, take three Alexandre Courbot
2018-01-26 6:02 ` [RFC PATCH 1/8] media: add request API core and UAPI Alexandre Courbot
2018-01-26 6:02 ` [RFC PATCH 2/8] videodev2.h: Add request field to v4l2_buffer Alexandre Courbot
2018-01-26 6:02 ` [RFC PATCH 3/8] media: videobuf2: add support for requests Alexandre Courbot
2018-01-31 12:19 ` Sakari Ailus
2018-01-26 6:02 ` Alexandre Courbot [this message]
2018-01-26 6:02 ` [RFC PATCH 5/8] media: Document the media request API Alexandre Courbot
2018-01-29 16:04 ` Hans Verkuil
2018-01-30 6:31 ` Alexandre Courbot
2018-01-26 6:02 ` [RFC PATCH 6/8] v4l2: document the request API interface Alexandre Courbot
2018-01-26 20:40 ` Randy Dunlap
2018-01-26 21:44 ` Nicolas Dufresne
2018-01-29 16:03 ` Hans Verkuil
2018-01-30 6:31 ` Alexandre Courbot
2018-01-31 8:26 ` Hans Verkuil
2018-02-06 22:19 ` Sakari Ailus
2018-01-26 6:02 ` [RFC PATCH 7/8] media: vim2m: add media device Alexandre Courbot
2018-01-26 6:02 ` [RFC PATCH 8/8] media: vim2m: add request support Alexandre Courbot
2018-01-29 11:21 ` [RFC PATCH 0/8] [media] Request API, take three Hans Verkuil
2018-01-30 6:31 ` Alexandre Courbot
2018-01-31 7:50 ` Hans Verkuil
2018-01-31 8:10 ` Tomasz Figa
2018-01-31 8:47 ` Hans Verkuil
2018-01-31 9:46 ` Tomasz Figa
2018-01-31 16:16 ` Hans Verkuil
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=20180126060216.147918-5-acourbot@chromium.org \
--to=acourbot@chromium.org \
--cc=gustavo.padovan@collabora.com \
--cc=hverkuil@xs4all.nl \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=mchehab@kernel.org \
--cc=posciak@chromium.org \
--cc=sakari.ailus@linux.intel.com \
--cc=tfiga@chromium.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
all inboxes | Powered by JetHome®