From: Sakari Ailus <sakari.ailus@linux.intel.com>
To: linux-media@vger.kernel.org
Cc: hverkuil@xs4all.nl, laurent.pinchart@ideasonboard.com,
mchehab@s-opensource.com
Subject: [PATCH v5 1/4] media: Determine early whether an IOCTL is supported
Date: Fri, 16 Sep 2016 14:49:05 +0300 [thread overview]
Message-ID: <1474026548-28829-2-git-send-email-sakari.ailus@linux.intel.com> (raw)
In-Reply-To: <1474026548-28829-1-git-send-email-sakari.ailus@linux.intel.com>
Preparation for refactoring media IOCTL handling to unify common parts.
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
---
drivers/media/media-device.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 1795abe..f321264 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -419,6 +419,22 @@ static long media_device_get_topology(struct media_device *mdev,
return 0;
}
+#define MEDIA_IOC(__cmd) \
+ [_IOC_NR(MEDIA_IOC_##__cmd)] = { .cmd = MEDIA_IOC_##__cmd }
+
+/* the table is indexed by _IOC_NR(cmd) */
+struct media_ioctl_info {
+ unsigned int cmd;
+};
+
+static const struct media_ioctl_info ioctl_info[] = {
+ MEDIA_IOC(DEVICE_INFO),
+ MEDIA_IOC(ENUM_ENTITIES),
+ MEDIA_IOC(ENUM_LINKS),
+ MEDIA_IOC(SETUP_LINK),
+ MEDIA_IOC(G_TOPOLOGY),
+};
+
static long media_device_ioctl(struct file *filp, unsigned int cmd,
unsigned long arg)
{
@@ -426,6 +442,10 @@ static long media_device_ioctl(struct file *filp, unsigned int cmd,
struct media_device *dev = devnode->media_dev;
long ret;
+ if (_IOC_NR(cmd) >= ARRAY_SIZE(ioctl_info)
+ || ioctl_info[_IOC_NR(cmd)].cmd != cmd)
+ return -ENOIOCTLCMD;
+
mutex_lock(&dev->graph_mutex);
switch (cmd) {
case MEDIA_IOC_DEVICE_INFO:
--
2.7.4
next prev parent reply other threads:[~2016-09-16 11:50 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-16 11:49 [PATCH v5 0/4] Refactor media IOCTL handling Sakari Ailus
2016-09-16 11:49 ` Sakari Ailus [this message]
2016-09-16 11:49 ` [PATCH v5 2/4] media: Unify IOCTL handler calling Sakari Ailus
2016-09-16 11:49 ` [PATCH v5 3/4] media: Refactor copying IOCTL arguments from and to user space Sakari Ailus
2016-09-16 11:49 ` [PATCH v5 4/4] media: Add flags to tell whether to take graph mutex for an IOCTL Sakari Ailus
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=1474026548-28829-2-git-send-email-sakari.ailus@linux.intel.com \
--to=sakari.ailus@linux.intel.com \
--cc=hverkuil@xs4all.nl \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@s-opensource.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).