Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp311381pxf; Thu, 18 Mar 2021 00:16:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxaO2rPQGpeu3nYmkY/NwT+xdMDn5fBnzocvtaYl/FxJm1v+roRdG1Iz+lJxhDps8ZA/MB1 X-Received: by 2002:a05:6402:b41:: with SMTP id bx1mr1892441edb.69.1616051819027; Thu, 18 Mar 2021 00:16:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616051819; cv=none; d=google.com; s=arc-20160816; b=yAsqOGmH1riEEGqpf3J7HNqTvptFIuGWOILTgDI6P2/JKpPkvOEp9qP6YqYMiVo+eI yKQcfrWqPg9EdBRTQq+ZFsr90NIzJqa5k9YZOQiow6vdlfUsRutPihNAUutCrNc3X33+ ts8N2cK22y0T1j1qtDAFHfb58W2xkDKeHwe+YzhpRyu/4k3CcHIgHKMehzx27lL/YfuE uLZ67H/9Vj8tKQVo9YiQIWYcpD+qU/Hy5SpEeVZ1XecN2J4S1+pjIdUOU1ikB2f6ZHkP RFyew6skFiWoUJafIc8a4qoahyYME0DlIgvNlnOx9s6Mwpu6enBz9xC0puc3EXeBP8ba OlnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=AlQSxDB4wmgR+CS/wX1VZjchpLMI9Lhy9x8Te1xxGcE=; b=M5reACNqO7BtpENky6Wtp9OBwp7UE7Xn+8AWpBC4mLo7sCzITXkGYSlnwTz2Yd48tR jmufT1jIndLk+CK7H0/pDjljFIxbaprgJu2iDoEcCuMADPjalkn0TMm4kHx+jVv4PkDJ KRcy9YbsbXVI7JPiJLqlKMNCymkPIFir7iPS0EI4GKAFyuV6cGMj6wMmS+yaE//0h4Lo DjfSbNOKi4XK7WQb5QCY4QsAkN4mCqWPd1cXIgqgtbcvNKk0bSRN2oG2do/u6mX3A/gx m5fGB4i1uegiUY6KJ4cZR0eJ8t+JZAVgtxSl57jQblx4G85rk7GM7RNWEKG2/JRXY+NE x1Ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xs4all.nl header.s=s2 header.b=ZGX1b2YK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id mj17si976014ejb.28.2021.03.18.00.16.37; Thu, 18 Mar 2021 00:16:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@xs4all.nl header.s=s2 header.b=ZGX1b2YK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229638AbhCRHPY (ORCPT + 99 others); Thu, 18 Mar 2021 03:15:24 -0400 Received: from lb1-smtp-cloud7.xs4all.net ([194.109.24.24]:43365 "EHLO lb1-smtp-cloud7.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229540AbhCRHO4 (ORCPT ); Thu, 18 Mar 2021 03:14:56 -0400 Received: from cust-b5b5937f ([IPv6:fc0c:c16d:66b8:757f:c639:739b:9d66:799d]) by smtp-cloud7.xs4all.net with ESMTPA id MmrqlHb9oDUxpMmrtlhxEO; Thu, 18 Mar 2021 08:14:54 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xs4all.nl; s=s2; t=1616051694; bh=AlQSxDB4wmgR+CS/wX1VZjchpLMI9Lhy9x8Te1xxGcE=; h=Subject:To:From:Message-ID:Date:MIME-Version:Content-Type:From: Subject; b=ZGX1b2YKzmP/QtJc7WQXN3Pvdo3p+ZHXMBYG4OV/SY6gYQDH2PVMmyOpGDaD2byGE C7oo8X9G0sbHWOnN35rVL4deytgYcERcp0NO1Ab6Lg/hsUk3qIghrtCVqqFPuEFS4f 4SV5Y40hp85Zmr6RTdl5d+Y0SFKu4LgTkbs6bqGQ583Vz7LfiHQAb7Ke4EZVxqi1wJ 1CD0dcVDRCPJD94T0R9+NaJroAuLJZYR8tzdEtZE58dQzqjV7s7f2WEEZ6Yp7ORwJe cm4m2OzY28+V+hhEd4uQx1N1+PDTP3p+xlvvbUincyZhR5xYmmz8swkj5c+n+nzbEv VGLfBdU9xu2IA== Subject: Re: [PATCH v6 01/17] media: v4l2-ioctl: check_ext_ctrls: Fix multiclass V4L2_CTRL_WHICH_DEF_VAL To: Ricardo Ribalda , Laurent Pinchart , Mauro Carvalho Chehab , Sergey Senozhatsky , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, tfiga@chromium.org Cc: stable@vger.kernel.org References: <20210317164511.39967-1-ribalda@chromium.org> <20210317164511.39967-2-ribalda@chromium.org> From: Hans Verkuil Message-ID: Date: Thu, 18 Mar 2021 08:14:50 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: <20210317164511.39967-2-ribalda@chromium.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-CMAE-Envelope: MS4xfIAK1Ru+FwUriGLVGEH3AndJIMBqxiQjEmJUzMZ8MNVFI8BNtc63mTCkcH2Dz5gyOkTH4Jgwfa9mYHAG8n3/whcPd9GjjizLalLnv9/XHwvDnu5b6sWP xVmXefPXlht1gSSWrRV6jxZaK9Dx0B9djZp1DsmDWlCNK+bOWcEEyKn8H1EmJMBIXR3SO4iN7qI6O8jp9JcQfVV6hAKxYoCqlAwiZDpx79RNQDK0BA+4qGhj 2uDrYqTg4+rPeXEp550rFCGgKmE18aXSAXKVP2zCErT3JB+SkyT9FNtn7emU5fpwTqmTOucx2VGZx6FA1ayzpdyPmNFqtLSSAIHPVEcbtpJ62jPdm/cF4sqe 2/WIdJ3ePF7Na/J60Ux+j17C3Gd7kSr/wVlgW8MOYgg4rmzVFjNqomYgmW5GpuCT9eXQLcWBT7ZHUwzF+ZQ3fWdgKQvpiQ0r0ujKl0qtNAOqamNwA0I= Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Ricardo, On 17/03/2021 17:44, Ricardo Ribalda wrote: > Drivers that do not use the ctrl-framework use this function instead. > > - Do not check for multiple classes when getting the DEF_VAL. > > Fixes v4l2-compliance: > Control ioctls (Input 0): > fail: v4l2-test-controls.cpp(813): doioctl(node, VIDIOC_G_EXT_CTRLS, &ctrls) > test VIDIOC_G/S/TRY_EXT_CTRLS: FAIL Can you merge patches 1-4 into a single patch? It's really one big fix since this code was never updated when new 'which' values were added. So keeping it together is, for once, actually preferred. You can add my: Reviewed-by: Hans Verkuil after these 4 patches are merged. It looks much nicer now. Regards, Hans > > Cc: stable@vger.kernel.org > Fixes: 6fa6f831f095 ("media: v4l2-ctrls: add core request support") > Suggested-by: Hans Verkuil > Signed-off-by: Ricardo Ribalda > Reviewed-by: Laurent Pinchart > --- > drivers/media/v4l2-core/v4l2-ioctl.c | 47 ++++++++++++++++------------ > 1 file changed, 27 insertions(+), 20 deletions(-) > > diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c > index 31d1342e61e8..403f957a1012 100644 > --- a/drivers/media/v4l2-core/v4l2-ioctl.c > +++ b/drivers/media/v4l2-core/v4l2-ioctl.c > @@ -908,7 +908,7 @@ static void v4l_print_default(const void *arg, bool write_only) > pr_cont("driver-specific ioctl\n"); > } > > -static int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv) > +static bool check_ext_ctrls(struct v4l2_ext_controls *c, unsigned long ioctl) > { > __u32 i; > > @@ -917,23 +917,30 @@ static int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv) > for (i = 0; i < c->count; i++) > c->controls[i].reserved2[0] = 0; > > - /* V4L2_CID_PRIVATE_BASE cannot be used as control class > - when using extended controls. > - Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL > - is it allowed for backwards compatibility. > - */ > - if (!allow_priv && c->which == V4L2_CID_PRIVATE_BASE) > - return 0; > - if (!c->which) > - return 1; > + switch (c->which) { > + case V4L2_CID_PRIVATE_BASE: > + /* > + * V4L2_CID_PRIVATE_BASE cannot be used as control class > + * when using extended controls. > + * Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL > + * is it allowed for backwards compatibility. > + */ > + if (ioctl == VIDIOC_G_CTRL || ioctl == VIDIOC_S_CROP) > + return false; > + break; > + case V4L2_CTRL_WHICH_DEF_VAL: > + case V4L2_CTRL_WHICH_CUR_VAL: > + return true; > + } > + > /* Check that all controls are from the same control class. */ > for (i = 0; i < c->count; i++) { > if (V4L2_CTRL_ID2WHICH(c->controls[i].id) != c->which) { > c->error_idx = i; > - return 0; > + return false; > } > } > - return 1; > + return true; > } > > static int check_fmt(struct file *file, enum v4l2_buf_type type) > @@ -2229,7 +2236,7 @@ static int v4l_g_ctrl(const struct v4l2_ioctl_ops *ops, > ctrls.controls = &ctrl; > ctrl.id = p->id; > ctrl.value = p->value; > - if (check_ext_ctrls(&ctrls, 1)) { > + if (check_ext_ctrls(&ctrls, VIDIOC_G_CTRL)) { > int ret = ops->vidioc_g_ext_ctrls(file, fh, &ctrls); > > if (ret == 0) > @@ -2263,7 +2270,7 @@ static int v4l_s_ctrl(const struct v4l2_ioctl_ops *ops, > ctrls.controls = &ctrl; > ctrl.id = p->id; > ctrl.value = p->value; > - if (check_ext_ctrls(&ctrls, 1)) > + if (check_ext_ctrls(&ctrls, VIDIOC_S_CTRL)) > return ops->vidioc_s_ext_ctrls(file, fh, &ctrls); > return -EINVAL; > } > @@ -2285,8 +2292,8 @@ static int v4l_g_ext_ctrls(const struct v4l2_ioctl_ops *ops, > vfd, vfd->v4l2_dev->mdev, p); > if (ops->vidioc_g_ext_ctrls == NULL) > return -ENOTTY; > - return check_ext_ctrls(p, 0) ? ops->vidioc_g_ext_ctrls(file, fh, p) : > - -EINVAL; > + return check_ext_ctrls(p, VIDIOC_G_EXT_CTRLS) ? > + ops->vidioc_g_ext_ctrls(file, fh, p) : -EINVAL; > } > > static int v4l_s_ext_ctrls(const struct v4l2_ioctl_ops *ops, > @@ -2306,8 +2313,8 @@ static int v4l_s_ext_ctrls(const struct v4l2_ioctl_ops *ops, > vfd, vfd->v4l2_dev->mdev, p); > if (ops->vidioc_s_ext_ctrls == NULL) > return -ENOTTY; > - return check_ext_ctrls(p, 0) ? ops->vidioc_s_ext_ctrls(file, fh, p) : > - -EINVAL; > + return check_ext_ctrls(p, VIDIOC_S_EXT_CTRLS) ? > + ops->vidioc_s_ext_ctrls(file, fh, p) : -EINVAL; > } > > static int v4l_try_ext_ctrls(const struct v4l2_ioctl_ops *ops, > @@ -2327,8 +2334,8 @@ static int v4l_try_ext_ctrls(const struct v4l2_ioctl_ops *ops, > vfd, vfd->v4l2_dev->mdev, p); > if (ops->vidioc_try_ext_ctrls == NULL) > return -ENOTTY; > - return check_ext_ctrls(p, 0) ? ops->vidioc_try_ext_ctrls(file, fh, p) : > - -EINVAL; > + return check_ext_ctrls(p, VIDIOC_TRY_EXT_CTRLS) ? > + ops->vidioc_try_ext_ctrls(file, fh, p) : -EINVAL; > } > > /* >