Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp313371pxf; Thu, 18 Mar 2021 00:21:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyf0NqwLwiC64YY0QKjtz3eMDAjpwyGQSaUcU2WjubGek0trjp4PL1agDPmJa88JSVTSzEL X-Received: by 2002:aa7:d484:: with SMTP id b4mr1902974edr.63.1616052063985; Thu, 18 Mar 2021 00:21:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616052063; cv=none; d=google.com; s=arc-20160816; b=GsaR82s5PGiFXpvB9tnG4Qb3G4IUPnvN3mIVGVo4++ecteNa/W2wKpTaHxhIPhnStn sHOyUJ3lU3rJUw0bDTUJaavRqeNCQGttAr4/W9LnZdmum6IDFKWAvHyFZrlxcCk9b0tJ yt6i3VL22haPbt6C94dk07W3H9dx1skO0dZ8rw0HtfaPkPCBKuyepKMi6r4SEDHJjZah Vt2sg4qcLLlFR9Y/2q1FJSL5huD14swdpK3p9BTwEiaf5Q0ZCK020vrm4r6Au+IVsheL 3wIji1YP7uHC97pV7W3D7gl+9/apkFjW81gI4ioxW17PjAebPYTi8TgWUeEjcitGWSFH j+JA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=zUooUIUx9S9QUHmbXLCfbzs+6RUBy4mSgIV4FrQ6sHA=; b=0EUr4mgDDSectzlAHiB9/cHFJ7Q7FHiQR3ccccE5erD6OM1TX8bDNlZiPXxavTBOoi 0LZRO1cr8PrghWq6QuarLrUvP6Lu1VUIOzKZO7hUkd4FBMaRjhvx2M64Jgcn8g+mHGL2 3SYnUMQvhoAgR705tEiZDtfY1hubVkOLMuItCY0/2wT6Ooy5g5wS+TG4UFFXq4IC4wWf t5R0tFn0cMhz52z76omTvHnOsKJ33z4iqVN7gipsL/1fcaygIaMdFkUc84DWmc513NGo ctqB/nqQaV+kJEeSy/bRXtg28kG7M/omYSbVB6vAtdMQkeO9JxmYQIpoG+UDRLLD386g lAIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=WyI30lIE; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id du1si914469ejc.12.2021.03.18.00.20.41; Thu, 18 Mar 2021 00:21:03 -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=@chromium.org header.s=google header.b=WyI30lIE; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229849AbhCRHRk (ORCPT + 99 others); Thu, 18 Mar 2021 03:17:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229810AbhCRHRX (ORCPT ); Thu, 18 Mar 2021 03:17:23 -0400 Received: from mail-il1-x130.google.com (mail-il1-x130.google.com [IPv6:2607:f8b0:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E583C06175F for ; Thu, 18 Mar 2021 00:17:23 -0700 (PDT) Received: by mail-il1-x130.google.com with SMTP id m6so3952913ilh.6 for ; Thu, 18 Mar 2021 00:17:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=zUooUIUx9S9QUHmbXLCfbzs+6RUBy4mSgIV4FrQ6sHA=; b=WyI30lIEISbqz6L8oqGbsuA8xHSBHWtuCwZ5xG2y2OtYO2OJ2YX1AfCJtgP1HH97co hcxag48KoStM5bomW92zBQhQulS2z/bpoEruTUAYgg4222zvFs1XlydJNlJhZ8Kn4cFq sPGFiIZhNZKyln0ATTzrlYs5SI/r1agT5e4P8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=zUooUIUx9S9QUHmbXLCfbzs+6RUBy4mSgIV4FrQ6sHA=; b=dxnwHMd5ond3SCAOpH15JvuG5ul5bOXr8jMb2KGHlgjdesG3rlMxy+vEDMwiDaBa0K ZraM9SMrWC4xkacBZf0AtmZOp/YFHJbtrQmflSAtYugQvwfgnUwsvfMeaTFr9bDNDs7+ hMSd40zBr29L/vCrFdVgAJI/duTg5TsbOiR/fCm7nfELZ6RJGVw+S0i69jtBrThfcC4d ROz2z8Rrdk5uQ52RNolPsO2eXhSl9n8hbmWATtZee/C+uEJg/h8nwgjW/vpRO6RNxB+Q 07NpsxDE9BssZbe+W8WHQbbjG1KDHpKQsY9ND0YXresbJyt0eew9eVrxg7r5LXq+v5Sa qckQ== X-Gm-Message-State: AOAM531v58GaAXPe3/6WuhcxXsUfpyRpzw6HvNW6WOVewx4uFUpQPV3q imsVIxNxokVa3R4ucTfuTGDRUeyY2NAFMQ== X-Received: by 2002:a92:d604:: with SMTP id w4mr10518776ilm.11.1616051842519; Thu, 18 Mar 2021 00:17:22 -0700 (PDT) Received: from mail-io1-f42.google.com (mail-io1-f42.google.com. [209.85.166.42]) by smtp.gmail.com with ESMTPSA id x16sm722229ilp.44.2021.03.18.00.17.21 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 18 Mar 2021 00:17:22 -0700 (PDT) Received: by mail-io1-f42.google.com with SMTP id n198so1236865iod.0 for ; Thu, 18 Mar 2021 00:17:21 -0700 (PDT) X-Received: by 2002:a05:6602:24d4:: with SMTP id h20mr9363408ioe.4.1616051841488; Thu, 18 Mar 2021 00:17:21 -0700 (PDT) MIME-Version: 1.0 References: <20210317164511.39967-1-ribalda@chromium.org> <20210317164511.39967-2-ribalda@chromium.org> In-Reply-To: From: Ricardo Ribalda Date: Thu, 18 Mar 2021 08:17:10 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v6 01/17] media: v4l2-ioctl: check_ext_ctrls: Fix multiclass V4L2_CTRL_WHICH_DEF_VAL To: Hans Verkuil Cc: Laurent Pinchart , Mauro Carvalho Chehab , Sergey Senozhatsky , Linux Media Mailing List , Linux Kernel Mailing List , Tomasz Figa , stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Hans Can I merge 1-3, but leave 4 as a separate one? It helps to tell a story for 5 and 6. Thanks On Thu, Mar 18, 2021 at 8:14 AM Hans Verkuil wrote: > > 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; > > } > > > > /* > > > -- Ricardo Ribalda