Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp525092pxf; Wed, 17 Mar 2021 09:46:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyOEamM7JmvZcJVyHEbZ13tY6AnbGsKYPrdgyr1ajgOEFvXlZWARd/qhv8XkhAkY2+Jq8aO X-Received: by 2002:a17:906:684b:: with SMTP id a11mr35414419ejs.329.1615999611816; Wed, 17 Mar 2021 09:46:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615999611; cv=none; d=google.com; s=arc-20160816; b=x31siYuTRBL0DjBufEU5a12UFQ2sGKHUsvBpowDoA6Tqq/2+XCbYaEKaxisatmIGox UIY7C7UM2yswH8O5863LEShzezPI+P2cYp9sDqFhebvmN+vD02uQ9YrU6+Jad17PLaYA CTibqYOfPRZQrbnDfl1Qpk6AhpUsAsFs4OUMzXhiLqp6RAyWxH1qH6TruOMvIVsPafWZ hr0vmJdt2GSGbrAYsOsuYPJEJJccNCCjM/V5c+/3/NFJjmRrh3+EJqsMVeDgCeqXSilM hrHne40fGyptjK6BSXGdHjO6OBNHBV+GaMJqpYVXpAsTFAyzxE+YcK+3Br9JW1ClcdI3 7sLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ERNXG1v+qDkfV0aFqnySPvlk5uuRx9CupYTJSS90Mk4=; b=DQjuRPsv1WsxjMKr9rLTLqVA558QRuTxAVLMoRAPeuSZKxllPLaZK4iTsEEeUnN/8n IFB2XZ7P5pB4Tk1DOMzZ27O5v92wrqsJ3938YwMhEmDPxJz/UmmyOu8CP03I277NZWPG tEmhkWEC3P17lzufl5gWMTOpMALzCA3cKdCcSoOmlzC/jop1+3At+sZeHkAWjCnYbSf7 XbM60c1RNSDCOniYiwkkJBKAjaFxN/3Fr3rXM4PDQwOXnNPdQL4mfyveu4M2sMf0SIoB /TJ8/0zFnAKkLAJxyiF/r8NYn2P8Yi6l13zV4InOZX7K8OIS+7RDEH9Fzy31riuPvSOO tg5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=aHcwsimQ; 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 j13si16674611edn.369.2021.03.17.09.46.28; Wed, 17 Mar 2021 09:46:51 -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=aHcwsimQ; 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 S232546AbhCQQp2 (ORCPT + 99 others); Wed, 17 Mar 2021 12:45:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232560AbhCQQpQ (ORCPT ); Wed, 17 Mar 2021 12:45:16 -0400 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 051EBC061763 for ; Wed, 17 Mar 2021 09:45:15 -0700 (PDT) Received: by mail-ej1-x62e.google.com with SMTP id mm21so3652886ejb.12 for ; Wed, 17 Mar 2021 09:45:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ERNXG1v+qDkfV0aFqnySPvlk5uuRx9CupYTJSS90Mk4=; b=aHcwsimQ4eB5xhyPHCGPnZ8+zMDMnDDgA2E7ZAv2rmdgbOW/aJ6XzLcj+VmeM8YtD0 /4bk7PlON9VlmR7hqtiloYJ0COSAgSp/diwQaZQTa95VzRoh0X5WNrCF3NZiMYpoYdQd IGfCn9Q7ahtF/NxApdC9UxZAKy3QkjjDHORVU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ERNXG1v+qDkfV0aFqnySPvlk5uuRx9CupYTJSS90Mk4=; b=a3jFMnm5tdBB28nA8jcnmmUrpSaQL/1LFn9QVSQ8FtD/PEx9wObB9pSLx7SFBZK4mL Kuht3sdDW9VEI6QCrwSxXb+qgz9MX/eh9RcI+3pyEmJXxIhFSt3pVCzR+wnQLVW2RcnA P5ZxZhA21zdsC9U+L0qgK2VrmysQFSktzVQ7Mm5/M36xbVQWAUectOdnNlhTQhm3xAHJ y0mh9VRzq9Ii6rEJVsf7W5ES/3wmwLZGPSVES6XNWmck4DkNKrF/lUE5nbnW1GMayysj 04ie/ohSb193ml6j8k3UnBoQ2O3Df0VftFOwbJHxAU/INiSoC/Hz6i+Ssby9WU5TfsND FLXg== X-Gm-Message-State: AOAM533xiKbK0Lg8PR/2k9KTVqCfEx8HhNKNSMgPdk/P51B/6hzN57A6 m/KFbBu60A9gMUGlOq9uo7n29w== X-Received: by 2002:a17:906:b752:: with SMTP id fx18mr37310300ejb.128.1615999514597; Wed, 17 Mar 2021 09:45:14 -0700 (PDT) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id hy25sm12088128ejc.119.2021.03.17.09.45.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Mar 2021 09:45:14 -0700 (PDT) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , Hans Verkuil , Sergey Senozhatsky , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, tfiga@chromium.org Cc: Ricardo Ribalda , stable@vger.kernel.org Subject: [PATCH v6 01/17] media: v4l2-ioctl: check_ext_ctrls: Fix multiclass V4L2_CTRL_WHICH_DEF_VAL Date: Wed, 17 Mar 2021 17:44:55 +0100 Message-Id: <20210317164511.39967-2-ribalda@chromium.org> X-Mailer: git-send-email 2.31.0.rc2.261.g7f71774620-goog In-Reply-To: <20210317164511.39967-1-ribalda@chromium.org> References: <20210317164511.39967-1-ribalda@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 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; } /* -- 2.31.0.rc2.261.g7f71774620-goog