From patchwork Thu Nov 1 23:31:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 10664755 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AEB13109C for ; Thu, 1 Nov 2018 23:33:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A25B22C4D2 for ; Thu, 1 Nov 2018 23:33:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 96CD92C554; Thu, 1 Nov 2018 23:33:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 34D522C4D2 for ; Thu, 1 Nov 2018 23:33:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728331AbeKBIiM (ORCPT ); Fri, 2 Nov 2018 04:38:12 -0400 Received: from bin-mail-out-05.binero.net ([195.74.38.228]:40163 "EHLO bin-mail-out-05.binero.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728326AbeKBIiM (ORCPT ); Fri, 2 Nov 2018 04:38:12 -0400 X-Halon-ID: 76d5c23a-de2e-11e8-9adf-005056917a89 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by bin-vsp-out-01.atm.binero.net (Halon) with ESMTPA id 76d5c23a-de2e-11e8-9adf-005056917a89; Fri, 02 Nov 2018 00:32:58 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: Laurent Pinchart , Sakari Ailus , Benoit Parrot , linux-media@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, =?utf-8?q?Niklas_S=C3=B6derlund?= Subject: [PATCH v2 17/30] v4l: subdev: compat: Implement handling for VIDIOC_SUBDEV_[GS]_ROUTING Date: Fri, 2 Nov 2018 00:31:31 +0100 Message-Id: <20181101233144.31507-18-niklas.soderlund+renesas@ragnatech.se> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181101233144.31507-1-niklas.soderlund+renesas@ragnatech.se> References: <20181101233144.31507-1-niklas.soderlund+renesas@ragnatech.se> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Sakari Ailus Implement compat IOCTL handling for VIDIOC_SUBDEV_G_ROUTING and VIDIOC_SUBDEV_S_ROUTING IOCTLs. Signed-off-by: Sakari Ailus Signed-off-by: Niklas Söderlund --- drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c index 6481212fda772c73..83af332763f41a6b 100644 --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c @@ -1045,6 +1045,66 @@ static int put_v4l2_event32(struct v4l2_event __user *p64, return 0; } +struct v4l2_subdev_routing32 { + compat_caddr_t routes; + __u32 num_routes; + __u32 reserved[5]; +}; + +static int get_v4l2_subdev_routing(struct v4l2_subdev_routing __user *p64, + struct v4l2_subdev_routing32 __user *p32) +{ + struct v4l2_subdev_route __user *routes; + compat_caddr_t p; + u32 num_routes; + + if (!access_ok(VERIFY_READ, p32, sizeof(*p32)) || + get_user(p, &p32->routes) || + get_user(num_routes, &p32->num_routes) || + put_user(num_routes, &p64->num_routes) || + copy_in_user(&p64->reserved, &p32->reserved, + sizeof(p64->reserved)) || + num_routes > U32_MAX / sizeof(*p64->routes)) + return -EFAULT; + + routes = compat_ptr(p); + + if (!access_ok(VERIFY_READ, routes, + num_routes * sizeof(*p64->routes))) + return -EFAULT; + + if (put_user((__force struct v4l2_subdev_route *)routes, + &p64->routes)) + return -EFAULT; + + return 0; +} + +static int put_v4l2_subdev_routing(struct v4l2_subdev_routing __user *p64, + struct v4l2_subdev_routing32 __user *p32) +{ + struct v4l2_subdev_route __user *routes; + compat_caddr_t p; + u32 num_routes; + + if (!access_ok(VERIFY_WRITE, p32, sizeof(*p32)) || + get_user(p, &p32->routes) || + get_user(num_routes, &p64->num_routes) || + put_user(num_routes, &p32->num_routes) || + copy_in_user(&p32->reserved, &p64->reserved, + sizeof(p64->reserved)) || + num_routes > U32_MAX / sizeof(*p64->routes)) + return -EFAULT; + + routes = compat_ptr(p); + + if (!access_ok(VERIFY_WRITE, routes, + num_routes * sizeof(*p64->routes))) + return -EFAULT; + + return 0; +} + struct v4l2_edid32 { __u32 pad; __u32 start_block; @@ -1117,6 +1177,8 @@ static int put_v4l2_edid32(struct v4l2_edid __user *p64, #define VIDIOC_STREAMOFF32 _IOW ('V', 19, s32) #define VIDIOC_G_INPUT32 _IOR ('V', 38, s32) #define VIDIOC_S_INPUT32 _IOWR('V', 39, s32) +#define VIDIOC_SUBDEV_G_ROUTING32 _IOWR('V', 38, struct v4l2_subdev_routing32) +#define VIDIOC_SUBDEV_S_ROUTING32 _IOWR('V', 39, struct v4l2_subdev_routing32) #define VIDIOC_G_OUTPUT32 _IOR ('V', 46, s32) #define VIDIOC_S_OUTPUT32 _IOWR('V', 47, s32) @@ -1195,6 +1257,8 @@ static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long ar case VIDIOC_STREAMOFF32: cmd = VIDIOC_STREAMOFF; break; case VIDIOC_G_INPUT32: cmd = VIDIOC_G_INPUT; break; case VIDIOC_S_INPUT32: cmd = VIDIOC_S_INPUT; break; + case VIDIOC_SUBDEV_G_ROUTING32: cmd = VIDIOC_SUBDEV_G_ROUTING; break; + case VIDIOC_SUBDEV_S_ROUTING32: cmd = VIDIOC_SUBDEV_S_ROUTING; break; case VIDIOC_G_OUTPUT32: cmd = VIDIOC_G_OUTPUT; break; case VIDIOC_S_OUTPUT32: cmd = VIDIOC_S_OUTPUT; break; case VIDIOC_CREATE_BUFS32: cmd = VIDIOC_CREATE_BUFS; break; @@ -1227,6 +1291,15 @@ static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long ar compatible_arg = 0; break; + case VIDIOC_SUBDEV_G_ROUTING: + case VIDIOC_SUBDEV_S_ROUTING: + err = alloc_userspace(sizeof(struct v4l2_subdev_routing), + 0, &new_p64); + if (!err) + err = get_v4l2_subdev_routing(new_p64, p32); + compatible_arg = 0; + break; + case VIDIOC_G_EDID: case VIDIOC_S_EDID: err = alloc_userspace(sizeof(struct v4l2_edid), 0, &new_p64); @@ -1368,6 +1441,10 @@ static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long ar if (put_v4l2_edid32(new_p64, p32)) err = -EFAULT; break; + case VIDIOC_SUBDEV_G_ROUTING: + case VIDIOC_SUBDEV_S_ROUTING: + err = put_v4l2_subdev_routing(new_p64, p32); + break; } if (err) return err;