Patch Detail
Show a patch.
GET /api/1.1/patches/3489/?format=api
{ "id": 3489, "url": "https://patchwork.libcamera.org/api/1.1/patches/3489/?format=api", "web_url": "https://patchwork.libcamera.org/patch/3489/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20200418103216.140572-4-jacopo@jmondi.org>", "date": "2020-04-18T10:32:14", "name": "[libcamera-devel,v4,3/5] media: v4l2-dev: Add v4l2_device_register_ro_subdev_node()", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "65fc9322ab473b6211b87d97cfc1aa5e9ab581ad", "submitter": { "id": 3, "url": "https://patchwork.libcamera.org/api/1.1/people/3/?format=api", "name": "Jacopo Mondi", "email": "jacopo@jmondi.org" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/3489/mbox/", "series": [ { "id": 816, "url": "https://patchwork.libcamera.org/api/1.1/series/816/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=816", "date": "2020-04-18T10:32:11", "name": "media: Register read-only sub-dev devnode", "version": 4, "mbox": "https://patchwork.libcamera.org/series/816/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/3489/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/3489/checks/", "tags": {}, "headers": { "Return-Path": "<jacopo@jmondi.org>", "Received": [ "from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net\n\t[217.70.183.195])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 33F1C60401\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 18 Apr 2020 12:29:44 +0200 (CEST)", "from uno.homenet.telecomitalia.it (unknown [87.13.136.104])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay3-d.mail.gandi.net (Postfix) with ESMTPSA id CD0AD60007;\n\tSat, 18 Apr 2020 10:29:38 +0000 (UTC)" ], "X-Originating-IP": "87.13.136.104", "From": "Jacopo Mondi <jacopo@jmondi.org>", "To": "linux-media@vger.kernel.org,\n\tlibcamera-devel@lists.libcamera.org", "Cc": "Jacopo Mondi <jacopo@jmondi.org>, mchehab@kernel.org,\n\thverkuil-cisco@xs4all.nl, sakari.ailus@linux.intel.com,\n\tandrey.konovalov@linaro.org, laurent.pinchart@ideasonboard.com", "Date": "Sat, 18 Apr 2020 12:32:14 +0200", "Message-Id": "<20200418103216.140572-4-jacopo@jmondi.org>", "X-Mailer": "git-send-email 2.26.1", "In-Reply-To": "<20200418103216.140572-1-jacopo@jmondi.org>", "References": "<20200418103216.140572-1-jacopo@jmondi.org>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v4 3/5] media: v4l2-dev: Add\n\tv4l2_device_register_ro_subdev_node()", "X-BeenThere": "libcamera-devel@lists.libcamera.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "<libcamera-devel.lists.libcamera.org>", "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>", "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>", "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>", "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>", "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>", "X-List-Received-Date": "Sat, 18 Apr 2020 10:29:44 -0000" }, "content": "Add to the V4L2 core a function to register device nodes for video\nsubdevices in read-only mode.\n\nRegistering a device node in read-only mode is useful to expose to\nuserspace the current sub-device configuration, without allowing\napplication to change it by using the V4L2 subdevice ioctls.\n\nAcked-by: Sakari Ailus <sakari.ailus@linux.intel.com>\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n drivers/media/v4l2-core/v4l2-device.c | 7 ++--\n drivers/media/v4l2-core/v4l2-subdev.c | 19 ++++++++++\n include/media/v4l2-dev.h | 7 ++++\n include/media/v4l2-device.h | 50 ++++++++++++++++++++++++---\n 4 files changed, 77 insertions(+), 6 deletions(-)", "diff": "diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c\nindex c69941214bb2..de4287251a89 100644\n--- a/drivers/media/v4l2-core/v4l2-device.c\n+++ b/drivers/media/v4l2-core/v4l2-device.c\n@@ -186,7 +186,8 @@ static void v4l2_device_release_subdev_node(struct video_device *vdev)\n \tkfree(vdev);\n }\n \n-int v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev)\n+int __v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev,\n+\t\t\t\t\tbool read_only)\n {\n \tstruct video_device *vdev;\n \tstruct v4l2_subdev *sd;\n@@ -215,6 +216,8 @@ int v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev)\n \t\tvdev->fops = &v4l2_subdev_fops;\n \t\tvdev->release = v4l2_device_release_subdev_node;\n \t\tvdev->ctrl_handler = sd->ctrl_handler;\n+\t\tif (read_only)\n+\t\t\tset_bit(V4L2_FL_SUBDEV_RO_DEVNODE, &vdev->flags);\n \t\terr = __video_register_device(vdev, VFL_TYPE_SUBDEV, -1, 1,\n \t\t\t\t\t sd->owner);\n \t\tif (err < 0) {\n@@ -252,7 +255,7 @@ int v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev)\n \n \treturn err;\n }\n-EXPORT_SYMBOL_GPL(v4l2_device_register_subdev_nodes);\n+EXPORT_SYMBOL_GPL(__v4l2_device_register_subdev_nodes);\n \n void v4l2_device_unregister_subdev(struct v4l2_subdev *sd)\n {\ndiff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c\nindex a376b351135f..1dc263c2ca0a 100644\n--- a/drivers/media/v4l2-core/v4l2-subdev.c\n+++ b/drivers/media/v4l2-core/v4l2-subdev.c\n@@ -331,6 +331,7 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg)\n \tstruct v4l2_fh *vfh = file->private_data;\n #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)\n \tstruct v4l2_subdev_fh *subdev_fh = to_v4l2_subdev_fh(vfh);\n+\tbool ro_subdev = test_bit(V4L2_FL_SUBDEV_RO_DEVNODE, &vdev->flags);\n #endif\n \tint rval;\n \n@@ -477,6 +478,9 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg)\n \tcase VIDIOC_SUBDEV_S_FMT: {\n \t\tstruct v4l2_subdev_format *format = arg;\n \n+\t\tif (format->which != V4L2_SUBDEV_FORMAT_TRY && ro_subdev)\n+\t\t\treturn -EPERM;\n+\n \t\tmemset(format->reserved, 0, sizeof(format->reserved));\n \t\tmemset(format->format.reserved, 0, sizeof(format->format.reserved));\n \t\treturn v4l2_subdev_call(sd, pad, set_fmt, subdev_fh->pad, format);\n@@ -504,6 +508,9 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg)\n \t\tstruct v4l2_subdev_crop *crop = arg;\n \t\tstruct v4l2_subdev_selection sel;\n \n+\t\tif (crop->which != V4L2_SUBDEV_FORMAT_TRY && ro_subdev)\n+\t\t\treturn -EPERM;\n+\n \t\tmemset(crop->reserved, 0, sizeof(crop->reserved));\n \t\tmemset(&sel, 0, sizeof(sel));\n \t\tsel.which = crop->which;\n@@ -545,6 +552,9 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg)\n \tcase VIDIOC_SUBDEV_S_FRAME_INTERVAL: {\n \t\tstruct v4l2_subdev_frame_interval *fi = arg;\n \n+\t\tif (ro_subdev)\n+\t\t\treturn -EPERM;\n+\n \t\tmemset(fi->reserved, 0, sizeof(fi->reserved));\n \t\treturn v4l2_subdev_call(sd, video, s_frame_interval, arg);\n \t}\n@@ -568,6 +578,9 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg)\n \tcase VIDIOC_SUBDEV_S_SELECTION: {\n \t\tstruct v4l2_subdev_selection *sel = arg;\n \n+\t\tif (sel->which != V4L2_SUBDEV_FORMAT_TRY && ro_subdev)\n+\t\t\treturn -EPERM;\n+\n \t\tmemset(sel->reserved, 0, sizeof(sel->reserved));\n \t\treturn v4l2_subdev_call(\n \t\t\tsd, pad, set_selection, subdev_fh->pad, sel);\n@@ -604,6 +617,9 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg)\n \t\treturn v4l2_subdev_call(sd, video, g_dv_timings, arg);\n \n \tcase VIDIOC_SUBDEV_S_DV_TIMINGS:\n+\t\tif (ro_subdev)\n+\t\t\treturn -EPERM;\n+\n \t\treturn v4l2_subdev_call(sd, video, s_dv_timings, arg);\n \n \tcase VIDIOC_SUBDEV_G_STD:\n@@ -612,6 +628,9 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg)\n \tcase VIDIOC_SUBDEV_S_STD: {\n \t\tv4l2_std_id *std = arg;\n \n+\t\tif (ro_subdev)\n+\t\t\treturn -EPERM;\n+\n \t\treturn v4l2_subdev_call(sd, video, s_std, *std);\n \t}\n \ndiff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h\nindex 4602c15ff878..ad2d41952442 100644\n--- a/include/media/v4l2-dev.h\n+++ b/include/media/v4l2-dev.h\n@@ -82,11 +82,18 @@ struct v4l2_ctrl_handler;\n *\tbut the old crop API will still work as expected in order to preserve\n *\tbackwards compatibility.\n *\tNever set this flag for new drivers.\n+ * @V4L2_FL_SUBDEV_RO_DEVNODE:\n+ *\tindicates that the video device node is registered in read-only mode.\n+ *\tThe flag only applies to device nodes registered for sub-devices, it is\n+ *\tset by the core when the sub-devices device nodes are registered with\n+ *\tv4l2_device_register_ro_subdev_nodes() and used by the sub-device ioctl\n+ *\thandler to restrict access to some ioctl calls.\n */\n enum v4l2_video_device_flags {\n \tV4L2_FL_REGISTERED\t\t= 0,\n \tV4L2_FL_USES_V4L2_FH\t\t= 1,\n \tV4L2_FL_QUIRK_INVERTED_CROP\t= 2,\n+\tV4L2_FL_SUBDEV_RO_DEVNODE\t= 3,\n };\n \n /* Priority helper functions */\ndiff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h\nindex 7c912b7d2870..64ec4de948e9 100644\n--- a/include/media/v4l2-device.h\n+++ b/include/media/v4l2-device.h\n@@ -174,14 +174,56 @@ int __must_check v4l2_device_register_subdev(struct v4l2_device *v4l2_dev,\n void v4l2_device_unregister_subdev(struct v4l2_subdev *sd);\n \n /**\n- * v4l2_device_register_subdev_nodes - Registers device nodes for all subdevs\n- *\tof the v4l2 device that are marked with\n- *\tthe %V4L2_SUBDEV_FL_HAS_DEVNODE flag.\n+ * __v4l2_device_register_ro_subdev_nodes - Registers device nodes for\n+ * all subdevs of the v4l2 device that are marked with the\n+ * %V4L2_SUBDEV_FL_HAS_DEVNODE flag.\n *\n * @v4l2_dev: pointer to struct v4l2_device\n+ * @read_only: subdevices read-only flag. True to register the subdevices\n+ *\tdevice nodes in read-only mode, false to allow full access to the\n+ *\tsubdevice userspace API.\n */\n int __must_check\n-v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev);\n+__v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev,\n+\t\t\t\t bool read_only);\n+\n+/**\n+ * v4l2_device_register_subdev_nodes - Registers subdevices device nodes with\n+ *\tunrestricted access to the subdevice userspace operations\n+ *\n+ * Internally calls __v4l2_device_register_subdev_nodes(). See its documentation\n+ * for more details.\n+ *\n+ * @v4l2_dev: pointer to struct v4l2_device\n+ */\n+static inline int __must_check\n+v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev)\n+{\n+#if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)\n+\treturn __v4l2_device_register_subdev_nodes(v4l2_dev, false);\n+#else\n+\treturn 0;\n+#endif\n+}\n+\n+/**\n+ * v4l2_device_register_ro_subdev_nodes - Registers subdevices device nodes\n+ *\tin read-only mode\n+ *\n+ * Internally calls __v4l2_device_register_subdev_nodes(). See its documentation\n+ * for more details.\n+ *\n+ * @v4l2_dev: pointer to struct v4l2_device\n+ */\n+static inline int __must_check\n+v4l2_device_register_ro_subdev_nodes(struct v4l2_device *v4l2_dev)\n+{\n+#if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)\n+\treturn __v4l2_device_register_subdev_nodes(v4l2_dev, true);\n+#else\n+\treturn 0;\n+#endif\n+}\n \n /**\n * v4l2_subdev_notify - Sends a notification to v4l2_device.\n", "prefixes": [ "libcamera-devel", "v4", "3/5" ] }