From patchwork Fri Aug 23 12:15:30 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Hans Verkuil (hansverk)" X-Patchwork-Id: 2848744 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 195E4BF546 for ; Fri, 23 Aug 2013 12:15:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9D643201FE for ; Fri, 23 Aug 2013 12:15:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A16E6201D3 for ; Fri, 23 Aug 2013 12:15:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753476Ab3HWMPf (ORCPT ); Fri, 23 Aug 2013 08:15:35 -0400 Received: from ams-iport-3.cisco.com ([144.254.224.146]:41001 "EHLO ams-iport-3.cisco.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752296Ab3HWMPf (ORCPT ); Fri, 23 Aug 2013 08:15:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cisco.com; i=@cisco.com; l=4579; q=dns/txt; s=iport; t=1377260134; x=1378469734; h=message-id:date:from:mime-version:to:cc:subject: references:in-reply-to:content-transfer-encoding; bh=1IyTGuBWAXDaBeuVVX2DYYV5VsyIMw0YWbiZNwD/954=; b=EXEIl8L8/WrI8eIUGTErptjpapYbb4NUoNQK2m7J1KOpu35iGnI6XXFg 8F0VITb/b2Fa9mV75JHIx0Tt6vor71b1XFbuslMrZH3HrlAV22/5OtbKg xFbFN92tJ4iZT5S+3oRyRLnjK28Br9v4uq3Kv4C5e8QXAblp5nhSf3hqg g=; X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AioFAAlRF1KQ/khR/2dsb2JhbABagwfBBIEfFnSCJQEBBCdRARAsFg8JAwIBAgFFEwEFAgKIDLZ+jxuBSweEFgOXZoYqhAGHL4MhOoEt X-IronPort-AV: E=Sophos;i="4.89,941,1367971200"; d="scan'208";a="16964681" Received: from ams-core-1.cisco.com ([144.254.72.81]) by ams-iport-3.cisco.com with ESMTP; 23 Aug 2013 12:15:33 +0000 Received: from [10.61.200.28] ([10.61.200.28]) (authenticated bits=0) by ams-core-1.cisco.com (8.14.5/8.14.5) with ESMTP id r7NCFUfL029775 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 23 Aug 2013 12:15:31 GMT Message-ID: <52175262.3040702@cisco.com> Date: Fri, 23 Aug 2013 14:15:30 +0200 From: Hans Verkuil User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130821 Icedove/17.0.8 MIME-Version: 1.0 To: linux-media@vger.kernel.org CC: ismael.luceno@corp.bluecherry.net, pete@sensoray.com, sakari.ailus@iki.fi, sylvester.nawrocki@gmail.com, laurent.pinchart@ideasonboard.com Subject: [RFCv4 PATCH] v4l2-compat-ioctl32: add g/s_matrix support. References: <1377166464-27448-1-git-send-email-hverkuil@xs4all.nl> <8b4d154fc2351c7c1f2999bfec665011dd0afdb9.1377166147.git.hans.verkuil@cisco.com> In-Reply-To: <8b4d154fc2351c7c1f2999bfec665011dd0afdb9.1377166147.git.hans.verkuil@cisco.com> X-Authenticated-User: hansverk Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-17.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY, USER_IN_DEF_DKIM_WL autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Update of RFCv3 PATCH 03/10 from the "Matrix and Motion Detection support" patch series. This time I've actually tested it, and as a bonus found a bug in the G/S_SUBDEV_EDID32 handling as well. Regards, Hans [PATCH] v4l2-compat-ioctl32: add g/s_matrix support. Also fix a copy_to_user bug in put_v4l2_subdev_edid32(): the user and kernel pointers were used the wrong way around. Signed-off-by: Hans Verkuil Acked-by: Sakari Ailus --- drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 50 ++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c index 8f7a6a4..8fb3e86 100644 --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c @@ -772,11 +772,40 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde put_user(kp->start_block, &up->start_block) || put_user(kp->blocks, &up->blocks) || put_user(tmp, &up->edid) || - copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved))) + copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved))) return -EFAULT; return 0; } +struct v4l2_matrix32 { + __u32 type; + struct v4l2_rect rect; + compat_caddr_t matrix; + __u32 reserved[16]; +} __attribute__ ((packed)); + +static int get_v4l2_matrix32(struct v4l2_matrix *kp, struct v4l2_matrix32 __user *up) +{ + u32 tmp; + + if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_matrix32)) || + get_user(kp->type, &up->type) || + copy_from_user(&kp->rect, &up->rect, sizeof(up->rect)) || + get_user(tmp, &up->matrix) || + copy_from_user(kp->reserved, up->reserved, sizeof(kp->reserved))) + return -EFAULT; + kp->matrix = compat_ptr(tmp); + return 0; +} + +static int put_v4l2_matrix32(struct v4l2_matrix *kp, struct v4l2_matrix32 __user *up) +{ + if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_matrix32)) || + copy_to_user(&up->rect, &kp->rect, sizeof(up->rect)) || + copy_to_user(up->reserved, kp->reserved, sizeof(up->reserved))) + return -EFAULT; + return 0; +} #define VIDIOC_G_FMT32 _IOWR('V', 4, struct v4l2_format32) #define VIDIOC_S_FMT32 _IOWR('V', 5, struct v4l2_format32) @@ -796,6 +825,8 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde #define VIDIOC_DQEVENT32 _IOR ('V', 89, struct v4l2_event32) #define VIDIOC_CREATE_BUFS32 _IOWR('V', 92, struct v4l2_create_buffers32) #define VIDIOC_PREPARE_BUF32 _IOWR('V', 93, struct v4l2_buffer32) +#define VIDIOC_G_MATRIX32 _IOWR('V', 104, struct v4l2_matrix32) +#define VIDIOC_S_MATRIX32 _IOWR('V', 105, struct v4l2_matrix32) #define VIDIOC_OVERLAY32 _IOW ('V', 14, s32) #define VIDIOC_STREAMON32 _IOW ('V', 18, s32) @@ -817,6 +848,7 @@ static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long ar struct v4l2_event v2ev; struct v4l2_create_buffers v2crt; struct v4l2_subdev_edid v2edid; + struct v4l2_matrix v2matrix; unsigned long vx; int vi; } karg; @@ -851,6 +883,8 @@ static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long ar case VIDIOC_PREPARE_BUF32: cmd = VIDIOC_PREPARE_BUF; break; case VIDIOC_SUBDEV_G_EDID32: cmd = VIDIOC_SUBDEV_G_EDID; break; case VIDIOC_SUBDEV_S_EDID32: cmd = VIDIOC_SUBDEV_S_EDID; break; + case VIDIOC_G_MATRIX32: cmd = VIDIOC_G_MATRIX; break; + case VIDIOC_S_MATRIX32: cmd = VIDIOC_S_MATRIX; break; } switch (cmd) { @@ -922,6 +956,12 @@ static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long ar case VIDIOC_DQEVENT: compatible_arg = 0; break; + + case VIDIOC_G_MATRIX: + case VIDIOC_S_MATRIX: + err = get_v4l2_matrix32(&karg.v2matrix, up); + compatible_arg = 0; + break; } if (err) return err; @@ -994,6 +1034,11 @@ static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long ar case VIDIOC_ENUMINPUT: err = put_v4l2_input32(&karg.v2i, up); break; + + case VIDIOC_G_MATRIX: + case VIDIOC_S_MATRIX: + err = put_v4l2_matrix32(&karg.v2matrix, up); + break; } return err; } @@ -1089,6 +1134,9 @@ long v4l2_compat_ioctl32(struct file *file, unsigned int cmd, unsigned long arg) case VIDIOC_ENUM_FREQ_BANDS: case VIDIOC_SUBDEV_G_EDID32: case VIDIOC_SUBDEV_S_EDID32: + case VIDIOC_QUERY_MATRIX: + case VIDIOC_G_MATRIX32: + case VIDIOC_S_MATRIX32: ret = do_video_ioctl(file, cmd, arg); break;