Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1173420pxf; Fri, 12 Mar 2021 03:50:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJx1jgS6IMq6tpI4JcMs3zKh2htWsNtTEAY1p8fjdz4zfW1rq7/GRR1TUFbS63k0WrT3RKt2 X-Received: by 2002:a17:907:20c7:: with SMTP id qq7mr7862849ejb.528.1615549805232; Fri, 12 Mar 2021 03:50:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615549805; cv=none; d=google.com; s=arc-20160816; b=t+L1MY7aakzf1oQr5u16FPZVkdzHjj74zT7eAb+wxyBiLAOpGcm2+bDtE3A+kfHXOE Ze5d7sSUJWWp7TfQwvGRb0V1J77C0CoCnSZT/4HJ5/0xAsYYfHFEkkz8az7XXI+diJ0h nvU1jB29ynIA8uKMI6IRmYQZdqqLI7a3mWTIvUHgV4LMNPU6kkIovi1hnPQh9cSyDyr1 vZGcp9Vd5JyrrdORqb1EUx+x+5zXKjyPklINltUUaveQ4OLd2CSlEQ69qgh5+AHMwV/W iOXt1rGyiLI5y4dEheQCMyUoCaTs8JVia0qxeZQqQA+h0anIBbgEgDG0eFshU70/2PAj 7bQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=UTZJqNO9odQJYKnrDzqKwQfhjuaZ+3gYCJkxoObD0Y4=; b=o2KlY4fpswEccoidJJz6fYRsWsI7MVpDpD97cStvftH3Fm0eI+7CzbhgH32hOwp4vZ iMld6ztF7CH4fqSXXTMMBYuZVgZMSpGEBqeKrn4h2jaRbSLi1HHpr0M/aWyVIOhZhup2 Ol4Hy8tsRpkPSkFpFwXN3ebaKjAUse3Usl1qNvNpHXR5/aw0foM3nyAvHpnhboH2ibjQ Xm1q8HjBAGwyWlCA3eTWv72xgiag1SiHJpHFAuh5McWIEwvpLe5qCBfCWOFZ4D5JOLWR I58HhfgV9cWJIpZP39t8LSL/VSimb5lhn/LXPpAD97FVTA+OEE5LcCIacu5hmIWnrZeO wPtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=b4gaPxei; 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 k5si3903608ejc.134.2021.03.12.03.49.43; Fri, 12 Mar 2021 03:50:05 -0800 (PST) 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 (test mode) header.i=@ideasonboard.com header.s=mail header.b=b4gaPxei; 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 S233250AbhCLKUC (ORCPT + 99 others); Fri, 12 Mar 2021 05:20:02 -0500 Received: from perceval.ideasonboard.com ([213.167.242.64]:39892 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232892AbhCLKTd (ORCPT ); Fri, 12 Mar 2021 05:19:33 -0500 Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 43FA68F9; Fri, 12 Mar 2021 11:19:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1615544372; bh=4WVLNWsi0vGsr2BYi2E+FHBor319xTVMivfKBNEC2nk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=b4gaPxeiNSII5ZsDx7Xv4IatsN/uodYX4TQU7WbyhBK+jGyV85/lgoxqsMjWc9OH5 pculN6iZ7LUXS/LtGW6fFlYr2OTOhRPIIOc1Nz6jXHGHQmCDYDvZHXYmpEZjpwgnTd JHCG5u2+Fq4vsW7+hKWLbb6vbORXx6/lOgyWiKFI= Date: Fri, 12 Mar 2021 12:18:57 +0200 From: Laurent Pinchart To: Hans Verkuil Cc: Ricardo Ribalda , Mauro Carvalho Chehab , Tomasz Figa , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, senozhatsky@chromium.org Subject: Re: [PATCH v2 4/6] media: uvcvideo: set error_idx to count on EACCESS Message-ID: References: <20210311221946.1319924-1-ribalda@chromium.org> <20210311221946.1319924-5-ribalda@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Hans, On Fri, Mar 12, 2021 at 08:14:13AM +0100, Hans Verkuil wrote: > On 11/03/2021 23:19, Ricardo Ribalda wrote: > > According to the doc: > > The, in hindsight quite poor, solution for that is to set error_idx to > > count if the validation failed. > > I think this needs a bit more explanation. How about this: > > "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." Here's what I commented on v1: The [V4L2 spec] states: "This check is done to avoid leaving the hardware in an inconsistent state due to easy-to-avoid problems. But it leads to another problem: the application needs to know whether an error came from the validation step (meaning that the hardware was not touched) or from an error during the actual reading from/writing to hardware." I'm not sure this is correct though. -EACCES is returned by __uvc_ctrl_get() when the control is found and is a write-only control. The uvc_ctrl_get() calls for the previous controls will have potentially touched the device to read the current control value if it wasn't cached already, to this contradicts the rationale from the specification. I understand the need for this when setting controls, but when reading them, it's more puzzling, as the interactions with the hardware to read the controls are not supposed to affect the hardware state in a way that applications should care about. It may be an issue in the V4L2 specification. > > > > 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 > > After improving the commit log you can add my: > > 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; > > return ret; > > } > > } -- Regards, Laurent Pinchart