From patchwork Wed Jul 28 10:06:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dafna Hirschfeld X-Patchwork-Id: 12405325 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 21486C432BE for ; Wed, 28 Jul 2021 10:06:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 05BFF60FC0 for ; Wed, 28 Jul 2021 10:06:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234186AbhG1KGg (ORCPT ); Wed, 28 Jul 2021 06:06:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232539AbhG1KGf (ORCPT ); Wed, 28 Jul 2021 06:06:35 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 839B9C061757 for ; Wed, 28 Jul 2021 03:06:34 -0700 (PDT) Received: from guri.fritz.box (unknown [IPv6:2a02:810a:880:f54:2423:b21a:aa05:1a51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: dafna) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 5FDC51F435D5; Wed, 28 Jul 2021 11:06:32 +0100 (BST) From: Dafna Hirschfeld To: linux-media@vger.kernel.org Cc: laurent.pinchart@ideasonboard.com, dafna.hirschfeld@collabora.com, helen.koike@collabora.com, ezequiel@collabora.com, hverkuil@xs4all.nl, kernel@collabora.com, dafna3@gmail.com, sakari.ailus@linux.intel.com, mchehab@kernel.org, tfiga@chromium.org, enric.balletbo@collabora.com, acourbot@chromium.org, hsinyi@chromium.org, eizan@chromium.org Subject: [PATCH 1/3] media: v4l2-core: move the code that copies v4l2_event_time32 to a function Date: Wed, 28 Jul 2021 12:06:22 +0200 Message-Id: <20210728100624.16129-2-dafna.hirschfeld@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210728100624.16129-1-dafna.hirschfeld@collabora.com> References: <20210728100624.16129-1-dafna.hirschfeld@collabora.com> Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Move the code that copies v4l2_event_time32 to function "put_v4l2_event_time32". This function will also be used for the case of 64-bit kernel other than x86_64 in later commits. Signed-off-by: Dafna Hirschfeld --- drivers/media/v4l2-core/v4l2-ioctl.c | 41 +++++++++++++++++----------- include/media/v4l2-ioctl.h | 6 ++++ 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c index 05d5db3d85e5..24bdb2383595 100644 --- a/drivers/media/v4l2-core/v4l2-ioctl.c +++ b/drivers/media/v4l2-core/v4l2-ioctl.c @@ -3167,6 +3167,28 @@ static int video_get_user(void __user *arg, void *parg, return err; } +int put_v4l2_event_time32(void *parg, void __user *arg) +{ + struct v4l2_event *ev = parg; + struct v4l2_event_time32 ev32; + + memset(&ev32, 0, sizeof(ev32)); + + ev32.type = ev->type; + ev32.pending = ev->pending; + ev32.sequence = ev->sequence; + ev32.timestamp.tv_sec = ev->timestamp.tv_sec; + ev32.timestamp.tv_nsec = ev->timestamp.tv_nsec; + ev32.id = ev->id; + + memcpy(&ev32.u, &ev->u, sizeof(ev->u)); + memcpy(&ev32.reserved, &ev->reserved, sizeof(ev->reserved)); + + if (copy_to_user(arg, &ev32, sizeof(ev32))) + return -EFAULT; + return 0; +} + static int video_put_user(void __user *arg, void *parg, unsigned int real_cmd, unsigned int cmd) { @@ -3186,23 +3208,10 @@ static int video_put_user(void __user *arg, void *parg, #if !defined(CONFIG_64BIT) && defined(CONFIG_COMPAT_32BIT_TIME) switch (cmd) { case VIDIOC_DQEVENT_TIME32: { - struct v4l2_event *ev = parg; - struct v4l2_event_time32 ev32; - - memset(&ev32, 0, sizeof(ev32)); + int ret = put_v4l2_event_time32(parg, arg); - ev32.type = ev->type; - ev32.pending = ev->pending; - ev32.sequence = ev->sequence; - ev32.timestamp.tv_sec = ev->timestamp.tv_sec; - ev32.timestamp.tv_nsec = ev->timestamp.tv_nsec; - ev32.id = ev->id; - - memcpy(&ev32.u, &ev->u, sizeof(ev->u)); - memcpy(&ev32.reserved, &ev->reserved, sizeof(ev->reserved)); - - if (copy_to_user(arg, &ev32, sizeof(ev32))) - return -EFAULT; + if (ret) + return ret; break; } case VIDIOC_QUERYBUF_TIME32: diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h index edb733f21604..0c209bbbc76f 100644 --- a/include/media/v4l2-ioctl.h +++ b/include/media/v4l2-ioctl.h @@ -784,6 +784,12 @@ struct v4l2_buffer_time32 { __u32 reserved; }; }; + +/* + * This function is used to copy the struct v4l2_event_time32 to userspace + */ +int put_v4l2_event_time32(void *parg, void __user *arg); + #define VIDIOC_QUERYBUF_TIME32 _IOWR('V', 9, struct v4l2_buffer_time32) #define VIDIOC_QBUF_TIME32 _IOWR('V', 15, struct v4l2_buffer_time32) #define VIDIOC_DQBUF_TIME32 _IOWR('V', 17, struct v4l2_buffer_time32) From patchwork Wed Jul 28 10:06:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dafna Hirschfeld X-Patchwork-Id: 12405327 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6F6B6C4320A for ; Wed, 28 Jul 2021 10:06:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 55CC860FC0 for ; Wed, 28 Jul 2021 10:06:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234354AbhG1KGg (ORCPT ); Wed, 28 Jul 2021 06:06:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233513AbhG1KGg (ORCPT ); Wed, 28 Jul 2021 06:06:36 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CCF78C061757 for ; Wed, 28 Jul 2021 03:06:34 -0700 (PDT) Received: from guri.fritz.box (unknown [IPv6:2a02:810a:880:f54:2423:b21a:aa05:1a51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: dafna) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 018A71F435D7; Wed, 28 Jul 2021 11:06:32 +0100 (BST) From: Dafna Hirschfeld To: linux-media@vger.kernel.org Cc: laurent.pinchart@ideasonboard.com, dafna.hirschfeld@collabora.com, helen.koike@collabora.com, ezequiel@collabora.com, hverkuil@xs4all.nl, kernel@collabora.com, dafna3@gmail.com, sakari.ailus@linux.intel.com, mchehab@kernel.org, tfiga@chromium.org, enric.balletbo@collabora.com, acourbot@chromium.org, hsinyi@chromium.org, eizan@chromium.org Subject: [PATCH 2/3] media: v4l2-core: combine code chunks under macro condition together Date: Wed, 28 Jul 2021 12:06:23 +0200 Message-Id: <20210728100624.16129-3-dafna.hirschfeld@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210728100624.16129-1-dafna.hirschfeld@collabora.com> References: <20210728100624.16129-1-dafna.hirschfeld@collabora.com> Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The struct v4l2_event32_time32 and the function put_v4l2_event32_time32 are both defined under the condition 'ifdef CONFIG_COMPAT_32BIT_TIME'. In order to make the code more readable, move both definitions under one 'ifdef'. Signed-off-by: Dafna Hirschfeld --- drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c index 47aff3b19742..5623003a9705 100644 --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c @@ -765,21 +765,6 @@ struct v4l2_event32 { __u32 reserved[8]; }; -#ifdef CONFIG_COMPAT_32BIT_TIME -struct v4l2_event32_time32 { - __u32 type; - union { - compat_s64 value64; - __u8 data[64]; - } u; - __u32 pending; - __u32 sequence; - struct old_timespec32 timestamp; - __u32 id; - __u32 reserved[8]; -}; -#endif - static int put_v4l2_event32(struct v4l2_event *p64, struct v4l2_event32 __user *p32) { @@ -796,6 +781,19 @@ static int put_v4l2_event32(struct v4l2_event *p64, } #ifdef CONFIG_COMPAT_32BIT_TIME +struct v4l2_event32_time32 { + __u32 type; + union { + compat_s64 value64; + __u8 data[64]; + } u; + __u32 pending; + __u32 sequence; + struct old_timespec32 timestamp; + __u32 id; + __u32 reserved[8]; +}; + static int put_v4l2_event32_time32(struct v4l2_event *p64, struct v4l2_event32_time32 __user *p32) { @@ -811,7 +809,7 @@ static int put_v4l2_event32_time32(struct v4l2_event *p64, return 0; } #endif -#endif +#endif /* CONFIG_X86_64 */ struct v4l2_edid32 { __u32 pad; From patchwork Wed Jul 28 10:06:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dafna Hirschfeld X-Patchwork-Id: 12405329 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D4DFFC43214 for ; Wed, 28 Jul 2021 10:06:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BB2DE60FC0 for ; Wed, 28 Jul 2021 10:06:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235656AbhG1KGh (ORCPT ); Wed, 28 Jul 2021 06:06:37 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:40286 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231907AbhG1KGg (ORCPT ); Wed, 28 Jul 2021 06:06:36 -0400 Received: from guri.fritz.box (unknown [IPv6:2a02:810a:880:f54:2423:b21a:aa05:1a51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: dafna) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 9891D1F435DD; Wed, 28 Jul 2021 11:06:33 +0100 (BST) From: Dafna Hirschfeld To: linux-media@vger.kernel.org Cc: laurent.pinchart@ideasonboard.com, dafna.hirschfeld@collabora.com, helen.koike@collabora.com, ezequiel@collabora.com, hverkuil@xs4all.nl, kernel@collabora.com, dafna3@gmail.com, sakari.ailus@linux.intel.com, mchehab@kernel.org, tfiga@chromium.org, enric.balletbo@collabora.com, acourbot@chromium.org, hsinyi@chromium.org, eizan@chromium.org Subject: [PATCH 3/3] media: v4l2-ctl: Add support to VIDIOC_DQEVENT_TIME32 on non x86_64 arch Date: Wed, 28 Jul 2021 12:06:24 +0200 Message-Id: <20210728100624.16129-4-dafna.hirschfeld@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210728100624.16129-1-dafna.hirschfeld@collabora.com> References: <20210728100624.16129-1-dafna.hirschfeld@collabora.com> Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Currently, if the ioctl VIDIOC_DQEVENT_TIME32 is called on e.g. Arm-64 the function 'v4l2_compat_translate_cmd' doesn't have a 'translation' for the cmd and so 'cmd' is returned as is. This cause a failure '-ENOTTY' in __video_do_ioctl. This patch fixes it by defining VIDIOC_DQEVENT32_TIME32 to be VIDIOC_DQEVENT_TIME32 for non x86-64 arch and translates it to VIDIOC_DQEVENT. In addition, add a call to put_v4l2_event_time32 to copy the data to userspace for non x86-64 arch Signed-off-by: Dafna Hirschfeld --- drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 21 ++++++++++++------- include/media/v4l2-ioctl.h | 3 +++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c index 5623003a9705..20a80880d9b7 100644 --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c @@ -871,9 +871,13 @@ static int put_v4l2_edid32(struct v4l2_edid *p64, #define VIDIOC_QUERYBUF32_TIME32 _IOWR('V', 9, struct v4l2_buffer32_time32) #define VIDIOC_QBUF32_TIME32 _IOWR('V', 15, struct v4l2_buffer32_time32) #define VIDIOC_DQBUF32_TIME32 _IOWR('V', 17, struct v4l2_buffer32_time32) + #ifdef CONFIG_X86_64 #define VIDIOC_DQEVENT32_TIME32 _IOR ('V', 89, struct v4l2_event32_time32) +#else +#define VIDIOC_DQEVENT32_TIME32 VIDIOC_DQEVENT_TIME32 #endif + #define VIDIOC_PREPARE_BUF32_TIME32 _IOWR('V', 93, struct v4l2_buffer32_time32) #endif @@ -899,6 +903,8 @@ unsigned int v4l2_compat_translate_cmd(unsigned int cmd) return VIDIOC_DQBUF; case VIDIOC_PREPARE_BUF32_TIME32: return VIDIOC_PREPARE_BUF; + case VIDIOC_DQEVENT32_TIME32: + return VIDIOC_DQEVENT; #endif case VIDIOC_QUERYBUF32: return VIDIOC_QUERYBUF; @@ -927,10 +933,6 @@ unsigned int v4l2_compat_translate_cmd(unsigned int cmd) #ifdef CONFIG_X86_64 case VIDIOC_DQEVENT32: return VIDIOC_DQEVENT; -#ifdef CONFIG_COMPAT_32BIT_TIME - case VIDIOC_DQEVENT32_TIME32: - return VIDIOC_DQEVENT; -#endif #endif } return cmd; @@ -996,6 +998,13 @@ int v4l2_compat_put_user(void __user *arg, void *parg, unsigned int cmd) case VIDIOC_DQBUF32_TIME32: case VIDIOC_PREPARE_BUF32_TIME32: return put_v4l2_buffer32_time32(parg, arg); + case VIDIOC_DQEVENT32_TIME32: +#ifdef CONFIG_X86_64 + return put_v4l2_event32_time32(parg, arg); +#else + return put_v4l2_event_time32(parg, arg); +#endif + #endif case VIDIOC_QUERYBUF32: case VIDIOC_QBUF32: @@ -1023,10 +1032,6 @@ int v4l2_compat_put_user(void __user *arg, void *parg, unsigned int cmd) #ifdef CONFIG_X86_64 case VIDIOC_DQEVENT32: return put_v4l2_event32(parg, arg); -#ifdef CONFIG_COMPAT_32BIT_TIME - case VIDIOC_DQEVENT32_TIME32: - return put_v4l2_event32_time32(parg, arg); -#endif #endif } return 0; diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h index 0c209bbbc76f..3840a3ea384c 100644 --- a/include/media/v4l2-ioctl.h +++ b/include/media/v4l2-ioctl.h @@ -786,7 +786,10 @@ struct v4l2_buffer_time32 { }; /* + * For architectures other than x86_64, the struct v4l2_event32_time32 + * is the same as v4l2_event_time32. * This function is used to copy the struct v4l2_event_time32 to userspace + * if either the kernel is not 64-bit or if the architecture is other than x86_64. */ int put_v4l2_event_time32(void *parg, void __user *arg);