{"id":3609,"url":"https://patchwork.libcamera.org/api/patches/3609/?format=json","web_url":"https://patchwork.libcamera.org/patch/3609/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20200429085855.186273-1-jacopo@jmondi.org>","date":"2020-04-29T08:58:55","name":"[libcamera-devel,v5.1] media: v4l2-subdev: Guard whole fops and ioctl hdlr","commit_ref":null,"pull_url":null,"state":"superseded","archived":true,"hash":"f75154964e7df04e4c0ed49e75a4f6f98022f8ab","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":{"id":15,"url":"https://patchwork.libcamera.org/api/users/15/?format=json","username":"jmondi","first_name":"Jacopo","last_name":"Mondi","email":"jacopo@jmondi.org"},"mbox":"https://patchwork.libcamera.org/patch/3609/mbox/","series":[{"id":850,"url":"https://patchwork.libcamera.org/api/series/850/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=850","date":"2020-04-29T08:58:55","name":"[libcamera-devel,v5.1] media: v4l2-subdev: Guard whole fops and ioctl hdlr","version":1,"mbox":"https://patchwork.libcamera.org/series/850/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/3609/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/3609/checks/","tags":{},"headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net\n\t[217.70.183.198])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id CE2E5601B8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 29 Apr 2020 10:55:51 +0200 (CEST)","from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay6-d.mail.gandi.net (Postfix) with ESMTPSA id 6E784C000E;\n\tWed, 29 Apr 2020 08:55:49 +0000 (UTC)"],"X-Originating-IP":"2.224.242.101","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":"Wed, 29 Apr 2020 10:58:55 +0200","Message-Id":"<20200429085855.186273-1-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.26.1","In-Reply-To":"<20200428210609.6793-5-jacopo@jmondi.org>","References":"<20200428210609.6793-5-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v5.1] media: v4l2-subdev: Guard whole fops\n\tand ioctl hdlr","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":"Wed, 29 Apr 2020 08:55:52 -0000"},"content":"A sub-device device node can be registered in user space only if the\nCONFIG_V4L2_SUBDEV_API Kconfig option is selected. Currently the\nopen/close file operations and the ioctl handler have some parts of their\nimplementations guarded by #if defined(CONFIG_V4L2_SUBDEV_API), while\nthey are actually not accessible without a video device node registered\nto user space.\n\nGuard the whole open, close and ioctl handler and provide stubs if the\nV4L2_SUBDEV_API Kconfig option is not selected.\n\nThis slightly reduces the kernel size when the option is not selected\nand simplifies the file ops and ioctl implementations.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\nA different approach compared to v5, which was anyway buggy and not a proper\nsolution.\n\nSending out for comments, while waiting for consensus on v5 [5/6] (reserved\nspace in the ioctl argument vs versioning based on structure size)\n\nCompile tested with and without V4L2_SUBDEV_API Kconfig option enabled and\nwith drivers that depends on it built-in or as modules.\n\n---\n drivers/media/v4l2-core/v4l2-subdev.c | 39 +++++++++++++++++++++------\n 1 file changed, 31 insertions(+), 8 deletions(-)\n\n--\n2.26.1","diff":"diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c\nindex 1dc263c2ca0a..6fef52880c99 100644\n--- a/drivers/media/v4l2-core/v4l2-subdev.c\n+++ b/drivers/media/v4l2-core/v4l2-subdev.c\n@@ -22,24 +22,22 @@\n #include <media/v4l2-fh.h>\n #include <media/v4l2-event.h>\n\n+#if defined(CONFIG_V4L2_SUBDEV_API)\n static int subdev_fh_init(struct v4l2_subdev_fh *fh, struct v4l2_subdev *sd)\n {\n-#if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)\n \tif (sd->entity.num_pads) {\n \t\tfh->pad = v4l2_subdev_alloc_pad_config(sd);\n \t\tif (fh->pad == NULL)\n \t\t\treturn -ENOMEM;\n \t}\n-#endif\n+\n \treturn 0;\n }\n\n static void subdev_fh_free(struct v4l2_subdev_fh *fh)\n {\n-#if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)\n \tv4l2_subdev_free_pad_config(fh->pad);\n \tfh->pad = NULL;\n-#endif\n }\n\n static int subdev_open(struct file *file)\n@@ -111,6 +109,17 @@ static int subdev_close(struct file *file)\n\n \treturn 0;\n }\n+#else /* CONFIG_V4L2_SUBDEV_API */\n+static int subdev_open(struct file *file)\n+{\n+\treturn 0;\n+}\n+\n+static int subdev_close(struct file *file)\n+{\n+\treturn 0;\n+}\n+#endif /* CONFIG_V4L2_SUBDEV_API */\n\n static inline int check_which(u32 which)\n {\n@@ -324,15 +333,14 @@ const struct v4l2_subdev_ops v4l2_subdev_call_wrappers = {\n };\n EXPORT_SYMBOL(v4l2_subdev_call_wrappers);\n\n+#if defined(CONFIG_V4L2_SUBDEV_API)\n static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg)\n {\n \tstruct video_device *vdev = video_devdata(file);\n \tstruct v4l2_subdev *sd = vdev_to_v4l2_subdev(vdev);\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 \tswitch (cmd) {\n@@ -466,7 +474,6 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg)\n \t\treturn ret;\n \t}\n\n-#if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)\n \tcase VIDIOC_SUBDEV_G_FMT: {\n \t\tstruct v4l2_subdev_format *format = arg;\n\n@@ -646,7 +653,7 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg)\n\n \tcase VIDIOC_SUBDEV_QUERYSTD:\n \t\treturn v4l2_subdev_call(sd, video, querystd, arg);\n-#endif\n+\n \tdefault:\n \t\treturn v4l2_subdev_call(sd, core, ioctl, cmd, arg);\n \t}\n@@ -686,6 +693,22 @@ static long subdev_compat_ioctl32(struct file *file, unsigned int cmd,\n }\n #endif\n\n+#else /* CONFIG_V4L2_SUBDEV_API */\n+static long subdev_ioctl(struct file *file, unsigned int cmd,\n+\tunsigned long arg)\n+{\n+\treturn 0;\n+}\n+\n+#ifdef CONFIG_COMPAT\n+static long subdev_compat_ioctl32(struct file *file, unsigned int cmd,\n+\tunsigned long arg)\n+{\n+\treturn 0;\n+}\n+#endif\n+#endif /* CONFIG_V4L2_SUBDEV_API */\n+\n static __poll_t subdev_poll(struct file *file, poll_table *wait)\n {\n \tstruct video_device *vdev = video_devdata(file);\n","prefixes":["libcamera-devel","v5.1"]}