Show a patch.

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

{
    "id": 3313,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/3313/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/3313/",
    "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": "<20200324202844.1518292-3-jacopo@jmondi.org>",
    "date": "2020-03-24T20:28:42",
    "name": "[libcamera-devel,2/4] media: v4l2-dev: Add v4l2_device_register_ro_subdev_node()",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "7d52c349b27a9b8aad67aefab95add3acd6d3495",
    "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/3313/mbox/",
    "series": [
        {
            "id": 772,
            "url": "https://patchwork.libcamera.org/api/1.1/series/772/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=772",
            "date": "2020-03-24T20:28:40",
            "name": "media: Register read-only sub-dev devnode",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/772/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/3313/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/3313/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 8CF5660411\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 24 Mar 2020 21:25:56 +0100 (CET)",
            "from localhost.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 60155100010;\n\tTue, 24 Mar 2020 20:25:55 +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",
        "Date": "Tue, 24 Mar 2020 21:28:42 +0100",
        "Message-Id": "<20200324202844.1518292-3-jacopo@jmondi.org>",
        "X-Mailer": "git-send-email 2.25.1",
        "In-Reply-To": "<20200324202844.1518292-1-jacopo@jmondi.org>",
        "References": "<20200324202844.1518292-1-jacopo@jmondi.org>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH 2/4] 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": "Tue, 24 Mar 2020 20:25:56 -0000"
    },
    "content": "Add to the V4L2 code 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 | 16 +++++++++++++++-\n drivers/media/v4l2-core/v4l2-subdev.c | 19 +++++++++++++++++++\n include/media/v4l2-dev.h              |  7 +++++++\n include/media/v4l2-device.h           | 10 ++++++++++\n 4 files changed, 51 insertions(+), 1 deletion(-)",
    "diff": "diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c\nindex 63d6b147b21e..6f9dba36eda1 100644\n--- a/drivers/media/v4l2-core/v4l2-device.c\n+++ b/drivers/media/v4l2-core/v4l2-device.c\n@@ -188,7 +188,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@@ -217,6 +218,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\tvdev->flags |= V4L2_FL_RO_DEVNODE;\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@@ -254,8 +257,19 @@ int v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev)\n \n \treturn err;\n }\n+\n+int v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev)\n+{\n+\treturn __v4l2_device_register_subdev_nodes(v4l2_dev, false);\n+}\n EXPORT_SYMBOL_GPL(v4l2_device_register_subdev_nodes);\n \n+int v4l2_device_register_ro_subdev_nodes(struct v4l2_device *v4l2_dev)\n+{\n+\treturn __v4l2_device_register_subdev_nodes(v4l2_dev, true);\n+}\n+EXPORT_SYMBOL_GPL(v4l2_device_register_ro_subdev_nodes);\n+\n void v4l2_device_unregister_subdev(struct v4l2_subdev *sd)\n {\n \tstruct v4l2_device *v4l2_dev;\ndiff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c\nindex f725cd9b66b9..9247ee6c293f 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_devnode = !!(vdev->flags & V4L2_FL_RO_DEVNODE);\n \tint rval;\n #endif\n \n@@ -453,6 +454,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_devnode)\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@@ -480,6 +484,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_devnode)\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@@ -521,6 +528,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_devnode)\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@@ -544,6 +554,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_devnode)\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@@ -580,6 +593,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_devnode)\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@@ -588,6 +604,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_devnode)\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 48531e57cc5a..029873a338f2 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 e0b8f2602670..0df667ba9938 100644\n--- a/include/media/v4l2-device.h\n+++ b/include/media/v4l2-device.h\n@@ -183,6 +183,16 @@ void v4l2_device_unregister_subdev(struct v4l2_subdev *sd);\n int __must_check\n v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev);\n \n+/**\n+ * v4l2_device_register_ro_subdev_nodes - Registers read-only 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+ */\n+int __must_check\n+v4l2_device_register_ro_subdev_nodes(struct v4l2_device *v4l2_dev);\n+\n /**\n  * v4l2_subdev_notify - Sends a notification to v4l2_device.\n  *\n",
    "prefixes": [
        "libcamera-devel",
        "2/4"
    ]
}