Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4232649pxf; Tue, 16 Mar 2021 08:34:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwVrEg9PsPUdEDtvyD2kDCaE/rnCdDHDSRSBe6JwyqxkewyhuFO3l8l0LO1nWTJoD70dao6 X-Received: by 2002:a17:906:3388:: with SMTP id v8mr30770438eja.278.1615908877213; Tue, 16 Mar 2021 08:34:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615908877; cv=none; d=google.com; s=arc-20160816; b=hEkR/j0LpTN02fuRbLKOPyL4RHPD/lWK8b17jjlwYsBKwUh173NrZn9eIa9gUWdVdG yJgfAZVm6pwl+4Y8vtaR/xk3f0AML8RWfvA4Ye1J3VOaXGVuCdyFDNTyF7VWqf14Ra0q W0e1n2aaRivIwVCSzCrueu4zXvMJap/V6cUngGfCF+B2sAEovICgVDEmP2hRxTsXRIAY R7rP727VL6mLzs8zjAPobguCvVMQ+Jydm8z+hK439PoMfq7gfyVDdEB+rTJBfUQc1W9c gaw7rt56wL65iZrpNrt6hQ6LEDIOyYh1KCh4N7X4gxfM6rK5Mb6Ko4McoeEr9jRZTmaY 2CGQ== 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 :to:subject:dkim-signature; bh=lFaMUIywMj08Hbt1FozVgRqYO6rwiY/lE/AH9dUNSMs=; b=uZBdISa102NyyRy4n3ZggZz67NZtPq3A3Q0ncEhPKgA9DLW1Y5UHkImA2npTYeGB4S /MxDUd2DjMInwMIwVMWepuO9YgTjJMjQSsNY56XOrdQCSfcCdlf49YpG1Skl7zuMaH0W 1utW9KzQ6pZEN0H0d7DdGVP8TE2t3saR/MaVJvH0ctQS8k9OSmUeyIRqhmQBatc5s6Me Ce/YmNAuVnmPHGUXSVkBmYLLauiADeMI73SoBYSWTkbvvHRAy0/uuJZ2V8YwgnYpjT52 m8To0MRUwYk8UhXPEzuZXAWNdCfO85v/FZ6O2a5LAx8LG7rDCPE4EQ0Z61/Lc0BoC5/y V7OA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xs4all.nl header.s=s2 header.b=f8BDJI3F; 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 a21si14030981ejd.654.2021.03.16.08.34.14; Tue, 16 Mar 2021 08:34:37 -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=f8BDJI3F; 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 S231288AbhCPLVY (ORCPT + 99 others); Tue, 16 Mar 2021 07:21:24 -0400 Received: from lb1-smtp-cloud7.xs4all.net ([194.109.24.24]:36421 "EHLO lb1-smtp-cloud7.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231513AbhCPLVF (ORCPT ); Tue, 16 Mar 2021 07:21:05 -0400 Received: from cust-b5b5937f ([IPv6:fc0c:c16d:66b8:757f:c639:739b:9d66:799d]) by smtp-cloud7.xs4all.net with ESMTPA id M7kxl1V9v4ywlM7l1lAjQh; Tue, 16 Mar 2021 12:21:03 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xs4all.nl; s=s2; t=1615893663; bh=lFaMUIywMj08Hbt1FozVgRqYO6rwiY/lE/AH9dUNSMs=; h=Subject:To:From:Message-ID:Date:MIME-Version:Content-Type:From: Subject; b=f8BDJI3F+U8GXJ3LbYTiFrz0s/lRweaLzytT4JDOsWkfmwi51H3CKwclD7HrunML1 ZYuAO1QIyWV136k96SYM/OL90Xae+oREnpQ23TgausR9R2b81vSd5YmKWFMRHJKUCH X0rhpOIMg7fD6dR0CtUM+CC+dzg0TMjZwcAmSGZ9dly/BcaG/AjVNc28eGCljqzRj1 3IuKyIsMKVBd5s8XSNayuiXOiMNAoikke8U2HM3v8HooadvidDYFTjKBKB+PgcPyVz y8k/kkRv5G4rb20xlKJmctYBuIUe9XMCW8ipjvCShL5XqFgTzC0tixxdiAqxDOdDCw 5Xglz5gVvSsUQ== Subject: Re: [PATCH v4 04/11] media: uvcvideo: set error_idx to count on EACCESS To: Ricardo Ribalda , Laurent Pinchart , Mauro Carvalho Chehab , Sergey Senozhatsky , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org References: <20210315173609.1547857-1-ribalda@chromium.org> <20210315173609.1547857-5-ribalda@chromium.org> From: Hans Verkuil Message-ID: Date: Tue, 16 Mar 2021 12:20:59 +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: <20210315173609.1547857-5-ribalda@chromium.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-CMAE-Envelope: MS4xfAB64SNb/pmcOy6dZ23h1tW5Z8ljmjo3cF98zALcSf3w1m70/K+WATitKWtD14DuShh0MBSBMU1TcRF4VO51WC5rpJJ6lL8p052pcSXfASNFLo9gOSZC rCr1mIBdQx9x9sTaaC+UN4QlAA01lqOIFXUVTscPJqFgD6IhW5JZLbuOA4DEkbnvptbf5csIM0VIWRVSy5VVSWuT/s9hxeeH7IPjsn3S+kjHCrZMXrE6rjn0 DAHSrWghWsJCWmnFwg1UHgpr3mSwgzC7ZrQLxfGPJpq3mmQZVgcvsjRplxqv3qad6gBwgvaC9WL9gTVLAypVkjTX2ig8RyAjXNZ7VkPetFGmFccQHotJdk6v CnmWkRIUExciIw76ZQY4y+IhvrXLjzH+9OW1ntQBb+T8J79uSmE= Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 15/03/2021 18:36, Ricardo Ribalda wrote: > If an error is found when validating the list of controls passed with > VIDIOC_G_EXT_CTRLS, then error_idx shall be set to ctrls->count to > indicate to userspace that no actual hardware was touched. > > It would have been much nicer of course if error_idx could point to the > control index that failed the validation, but sadly that's not how the > API was designed. > > Fixes v4l2-compliance: > Control ioctls (Input 0): > fail: v4l2-test-controls.cpp(645): invalid error index write only control > test VIDIOC_G/S/TRY_EXT_CTRLS: FAIL > > Signed-off-by: Ricardo Ribalda > Reviewed-by: Hans Verkuil > --- > drivers/media/usb/uvc/uvc_v4l2.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c > index 157310c0ca87..36eb48622d48 100644 > --- a/drivers/media/usb/uvc/uvc_v4l2.c > +++ b/drivers/media/usb/uvc/uvc_v4l2.c > @@ -1073,7 +1073,8 @@ static int uvc_ioctl_g_ext_ctrls(struct file *file, void *fh, > ret = uvc_ctrl_get(chain, ctrl); > if (ret < 0) { > uvc_ctrl_rollback(handle); > - ctrls->error_idx = i; > + ctrls->error_idx = (ret == -EACCES) ? > + ctrls->count : i; This isn't right. For G_EXT_CTRLS error_idx should be set to either ctrls->count or the index of the failing control depending on whether the hardware has been touched or not. In the case of the 'if (ctrls->which == V4L2_CTRL_WHICH_DEF_VAL) {' the hardware has not been touched, so there is should set error_idx to ctrls->count. In the case where we obtain the actual values with uvc_ctrl_get() it must return the index of the failing control. According to the spec if VIDIOC_G_EXT_CTRLS returns an error and error_idx is equal to the total count, then no hardware was touched, so it was during the validation phase that some error was detected. If it returns an error and error_idx < count, then the hardware was accessed and the contents of the controls at indices >= error_idx is undefined. So setting error_idx to i is the right thing to do, regardless of the EACCES test. This does create a problem in v4l2-compliance, since it assumes that the control framework is used, and that framework validates the control first in a separate step before accessing the hardware. That's missing in uvc. I think v4l2-compliance should be adjusted for uvcvideo since uvc isn't doing anything illegal by returning i here since it really accessed hardware. An alternative would be to introduce an initial validation phase in uvc_ioctl_g_ext_ctrls as well, but I'm not sure that it worth the effort. It's quite difficult to get it really right. Relaxing the tests in v4l2-compliance for uvc is a better approach IMHO. Or rewrite uvc to use the control framework :-) :-) Regards, Hans > return ret; > } > } >