Show a patch.

GET /api/1.1/patches/3362/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 3362,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/3362/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/3362/",
    "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": "<20200327223522.506832-4-jacopo@jmondi.org>",
    "date": "2020-03-27T22:35:22",
    "name": "[libcamera-devel,v2,3/3] media: v4l2-dev: Add v4l2_device_register_ro_subdev_node()",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "90f2d7a87122ef994d9ffa1106915f96a6aae01d",
    "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/3362/mbox/",
    "series": [
        {
            "id": 789,
            "url": "https://patchwork.libcamera.org/api/1.1/series/789/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=789",
            "date": "2020-03-27T22:35:19",
            "name": "media: Register read-only sub-dev devnode",
            "version": 3,
            "mbox": "https://patchwork.libcamera.org/series/789/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/3362/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/3362/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<jacopo@jmondi.org>",
        "Received": [
            "from relay11.mail.gandi.net (relay11.mail.gandi.net\n\t[217.70.178.231])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id BA1436040E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 27 Mar 2020 23:32:39 +0100 (CET)",
            "from uno.localdomain (2-224-242-101.ip172.fastwebnet.it\n\t[2.224.242.101]) (Authenticated sender: jacopo@jmondi.org)\n\tby relay11.mail.gandi.net (Postfix) with ESMTPSA id 1798A10000A;\n\tFri, 27 Mar 2020 22:32:37 +0000 (UTC)"
        ],
        "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": "Fri, 27 Mar 2020 23:35:22 +0100",
        "Message-Id": "<20200327223522.506832-4-jacopo@jmondi.org>",
        "X-Mailer": "git-send-email 2.25.1",
        "In-Reply-To": "<20200327223522.506832-1-jacopo@jmondi.org>",
        "References": "<20200327223522.506832-1-jacopo@jmondi.org>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [v2 3/3] 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": "Fri, 27 Mar 2020 22:32:39 -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\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           | 42 ++++++++++++++++++++++++---\n 4 files changed, 69 insertions(+), 6 deletions(-)\n\n--\n2.25.1",
    "diff": "diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c\nindex c69941214bb2..4517a70379ce 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_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..87fea21919fc 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_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..bdbd953a976c 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_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_RO_DEVNODE\t\t= 3,\n };\n\n /* Priority helper functions */\ndiff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h\nindex 7c912b7d2870..c01aa9df70b5 100644\n--- a/include/media/v4l2-device.h\n+++ b/include/media/v4l2-device.h\n@@ -174,14 +174,48 @@ 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+\treturn __v4l2_device_register_subdev_nodes(v4l2_dev, false);\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+\treturn __v4l2_device_register_subdev_nodes(v4l2_dev, true);\n+}\n\n /**\n  * v4l2_subdev_notify - Sends a notification to v4l2_device.\n",
    "prefixes": [
        "libcamera-devel",
        "v2",
        "3/3"
    ]
}