From patchwork Fri Dec 2 17:21:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 29040 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp982065wrr; Fri, 2 Dec 2022 09:26:14 -0800 (PST) X-Google-Smtp-Source: AA0mqf6eftET8d8YM5fYJfSOg8A7bjs+9wPzjcYY0TQMvHZZhU4NZ1he1SxudEojTsxezr8Xz2af X-Received: by 2002:a17:90a:c712:b0:212:9625:c8e9 with SMTP id o18-20020a17090ac71200b002129625c8e9mr82254930pjt.128.1670001974598; Fri, 02 Dec 2022 09:26:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670001974; cv=none; d=google.com; s=arc-20160816; b=g4DNHCTT8qWAw5u1uFeBZ4AjylThHy2yxdrgcs2Wf27Kn9/w8ji20p1ovt6Nv+047V azPLFHmA8GHcKgLHctk7ZbgR76mytyTNGaouImxIs+ntOlQuTAeYo0fbUe4fCd74Ol8M PhM9AjSWOMZU0BRexz1DGbKjglPpGAWcBcVRGXtrnxf51BOszqIdvd6rBZTCAFc30EhO nT8FXDeLVwsmzcjZsdfNFPpWASaYk3+5yZouJuLNYnobEOqnJeRb83pgh8uYc9RZNQUj A22IniNDPTRGCvD6xz/u8i+9a/eHYBXTQH2PPSB8qFmsjI/WjqSFg5wDZYH8gz1Dh0pG EYBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=EhS+JBqxHQJxyGff9DpvK+kt09IedMih5IP8k22GY28=; b=d7pChyzearoFsTx1YcPGeq+4iURu7o93KybGjliQiDQIgbqMty4rIYYwImdlQq+xqS Z6V9zaALtX1A+3qYiJVSoPe0T86Rg9hdOyaZ00ElSOydZZX4HSxoDv70inB5QQV1/RXx 2q3ASTfkXx2XVJk92bRnqARSnayeFJIS1np/kgUNdVuOfqSF1V3AcdDf137dYP7Z9kJ7 3uSaC62lHInbYCJZFDBANZAH/+X/htfxtreJkCu/9RKH6mTJkk7b1SgJXs3UkcHNnrrG vMob6xiVarkZTKLshFD+e1iRoSUfKqndmOlJtlxT5qGlz9XGgywB6ve7SuhhJTltFKrx ZV3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=CDmPCRBe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i8-20020a63d448000000b00477c498cca3si7729746pgj.55.2022.12.02.09.26.00; Fri, 02 Dec 2022 09:26:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=CDmPCRBe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S233907AbiLBRV7 (ORCPT + 99 others); Fri, 2 Dec 2022 12:21:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233497AbiLBRVx (ORCPT ); Fri, 2 Dec 2022 12:21:53 -0500 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B56AE7861 for ; Fri, 2 Dec 2022 09:21:52 -0800 (PST) Received: by mail-ej1-x630.google.com with SMTP id n20so13157198ejh.0 for ; Fri, 02 Dec 2022 09:21:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=EhS+JBqxHQJxyGff9DpvK+kt09IedMih5IP8k22GY28=; b=CDmPCRBe4IMk6p0oPlsz1zfKi7fsgZn30ytnDuUodDsq+R0J3sCgnUXk2+KAwY84qz dhYh/JyqBoWJgHb86Hw+Uc/s6Ej7yTzgzxNPALs9bCzWRbpPq++MZeNZxEd9DTOyXmWf oNAHsYnMqAvXhSUylCHPDssa5ks2raFhpco4s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EhS+JBqxHQJxyGff9DpvK+kt09IedMih5IP8k22GY28=; b=nWjexhNurlx1TUSfpVgTC6DWE1ZeopgpvhdIL78ziAlHBfzcoR4abWQ2JwSGsxvQYx gVy3bXKBonibiHw0JE7PmOkJCeQdp21VYgJnxEK4yeB3/thO1Pzgh45rPBga0ibk5lvy jqXCWWKC6LUcX0D07+sLzmWycAVpLx3sEUD2FLF3gYlmVPeuzopSkxtLiY9dLqTHkRXK 17TR4fhrnQf92eaSj2bDYGJtkGqeQjHr3yKxxlztY0Ifte1IrwaAaLP7Re6CB3SjGwiQ cGbZsPPiwm/OIAwR6O86+WplIXYEQk0yAyicUbYGCbYTOCyCyZkjKtydVkQpmk4GJJ0u ibsA== X-Gm-Message-State: ANoB5plUFYnUq83Aojc4wNfrnTpxbqTYVibRAO+KQG2qa7FV0Scbc6K5 mb9SQFzK6qUgX3sVxe1TUb6U2w== X-Received: by 2002:a17:906:2352:b0:7ad:a030:487e with SMTP id m18-20020a170906235200b007ada030487emr62542555eja.508.1670001710996; Fri, 02 Dec 2022 09:21:50 -0800 (PST) Received: from alco.roam.corp.google.com (80.71.134.83.ipv4.parknet.dk. [80.71.134.83]) by smtp.gmail.com with ESMTPSA id fe17-20020a1709072a5100b007be301a1d51sm3206685ejc.211.2022.12.02.09.21.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Dec 2022 09:21:50 -0800 (PST) From: Ricardo Ribalda Date: Fri, 02 Dec 2022 18:21:35 +0100 Subject: [PATCH RESEND v2 1/7] media: uvcvideo: uvc_ctrl_is_accessible: check for INACTIVE MIME-Version: 1.0 Message-Id: <20220920-resend-v4l2-compliance-v2-1-b0ceb15353ac@chromium.org> References: <20220920-resend-v4l2-compliance-v2-0-b0ceb15353ac@chromium.org> In-Reply-To: <20220920-resend-v4l2-compliance-v2-0-b0ceb15353ac@chromium.org> To: Mauro Carvalho Chehab , Laurent Pinchart Cc: Hans Verkuil , Hans Verkuil , linux-media@vger.kernel.org, Ricardo Ribalda , linux-kernel@vger.kernel.org, Hans Verkuil X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=5265; i=ribalda@chromium.org; h=from:subject:message-id; bh=tVt2FQwFWMzsSMl0muyb+NJLs92ZMfXZ/5urTCanEaY=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjijQj5Jwb/s3MtZM6LnzqyJVwaqUWM2+ULqkL3TGt 3vilUAyJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY4o0IwAKCRDRN9E+zzrEiOlCEA Ca5s+4X4YKwXvy9cPwI/cDHlh15ZgXJZ+3di0azDRwhMWVjUZDovHBJhz7sDnwO7gWCn7omPDq5mdF IEgEJw5ZyyqjFp33oDe4xjBdafldE23hYh8gXUj6DjyxsdkSrLbUaZfS+PeCeiHNEVu8FWnsvEtwkJ Nv34577sjadbyXkNpaQFJFAdfbB5BOy667bUv06sCYdrzNAlXS1JyJmanypFGF4pUHAuQLH74LdWHq Z55HJJQCp8e+PqgHP/Lenhxe6FbBNvjIQ8D2abzxdOENvF8lND3G5q1zWbXYD+BeLFjhhq0bh/iIY4 bQdpdusLhL3llwyD88qaeaYOv/vnKpjGwdkRsVYuO8CaHQEaxNO/zjJ6k9NM0zU6fSCeC06MlmKup8 qKk1p4Cmm/nK6UDPpDOV+iA5LCFocWb9ADgm30RqsBKBr7+j7Of+D9KaNXWr6JUk5lTbPcIEBthnaf Qsg7kW2hihNgm1+AehAEodK3mqIcw29zpU2PCtERvf7hHZ7rD75wYTfFWBz3TM+PnTARDuVI/aXLDF b7tTXVdx8zezvsWCO91S80571pnbwQEUbKcA8R1b9+8Uv3CcvyjEo8Oi/XrtrQxJ+NpmgbK2h7GaaX 3554EW94M64DmLTeV+PNX7aObgbodMhFZahMNMoXg3zysIb3cHGxA89rBW0A== X-Developer-Key: i=ribalda@chromium.org; a=openpgp; fpr=9EC3BB66E2FC129A6F90B39556A0D81F9F782DA9 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751123990303886504?= X-GMAIL-MSGID: =?utf-8?q?1751123990303886504?= From: Hans Verkuil Check for inactive controls in uvc_ctrl_is_accessible(). Use the new value for the master_id controls if present, otherwise use the existing value to determine if it is OK to set the control. Doing this here avoids attempting to set an inactive control, which will return an error from the USB device, which returns an invalid errorcode. This fixes: warn: v4l2-test-controls.cpp(483): s_ctrl returned EIO   warn: v4l2-test-controls.cpp(483): s_ctrl returned EIO test VIDIOC_G/S_CTRL: OK   warn: v4l2-test-controls.cpp(739): s_ext_ctrls returned EIO   warn: v4l2-test-controls.cpp(739): s_ext_ctrls returned EIO   warn: v4l2-test-controls.cpp(816): s_ext_ctrls returned EIO test VIDIOC_G/S/TRY_EXT_CTRLS: OK Tested with: v4l2-ctl -c auto_exposure=1 OK v4l2-ctl -c exposure_time_absolute=251 OK v4l2-ctl -c auto_exposure=3 OK v4l2-ctl -c exposure_time_absolute=251 VIDIOC_S_EXT_CTRLS: failed: Input/output error exposure_time_absolute: Input/output error ERROR v4l2-ctl -c auto_exposure=3,exposure_time_absolute=251,auto_exposure=1 v4l2-ctl -C auto_exposure,exposure_time_absolute   auto_exposure: 1 exposure_time_absolute: 251 Reviewed-by: Ricardo Ribalda Signed-off-by: Hans Verkuil --- drivers/media/usb/uvc/uvc_ctrl.c | 47 +++++++++++++++++++++++++++++++++++++++- drivers/media/usb/uvc/uvc_v4l2.c | 4 ++-- drivers/media/usb/uvc/uvcvideo.h | 3 ++- 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 8c208db9600b..7153ee5aabb1 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1064,11 +1064,33 @@ static int uvc_query_v4l2_class(struct uvc_video_chain *chain, u32 req_id, return 0; } +/** + * uvc_ctrl_is_accessible() - Check if a control can be read/writen/tried. + * @chain: uvc_video_chain that the controls belong to. + * @v4l2_id: video4linux id of the control. + * @ctrl: Other controls that will be accessed in the ioctl. + * @ioctl: ioctl used to access the control. + * + * Check if a control can be accessed by a specicific ioctl operation, + * assuming that other controls are also going to be accessed by that ioctl. + * We need to check the value of the other controls, to support operations + * where a master value is changed with a slave value. Eg. + * auto_exposure=1,exposure_time_absolute=251 + * + */ int uvc_ctrl_is_accessible(struct uvc_video_chain *chain, u32 v4l2_id, - bool read) + const struct v4l2_ext_controls *ctrls, + unsigned long ioctl) { + struct uvc_control_mapping *master_map = NULL; + struct uvc_control *master_ctrl = NULL; struct uvc_control_mapping *mapping; struct uvc_control *ctrl; + bool read = ioctl == VIDIOC_G_EXT_CTRLS; + bool try = ioctl == VIDIOC_TRY_EXT_CTRLS; + s32 val; + int ret; + int i; if (__uvc_query_v4l2_class(chain, v4l2_id, 0) >= 0) return -EACCES; @@ -1083,6 +1105,29 @@ int uvc_ctrl_is_accessible(struct uvc_video_chain *chain, u32 v4l2_id, if (!(ctrl->info.flags & UVC_CTRL_FLAG_SET_CUR) && !read) return -EACCES; + if (read || try || !mapping->master_id) + return 0; + + /* + * Iterate backwards in cases where the master control is accessed + * multiple times in the same ioctl. We want the last value. + */ + for (i = ctrls->count - 1; i >= 0; i--) { + if (ctrls->controls[i].id == mapping->master_id) + return ctrls->controls[i].value == + mapping->master_manual ? 0 : -EACCES; + } + + __uvc_find_control(ctrl->entity, mapping->master_id, &master_map, + &master_ctrl, 0); + + if (!master_ctrl || !(master_ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR)) + return 0; + + ret = __uvc_ctrl_get(chain, master_ctrl, master_map, &val); + if (ret >= 0 && val != mapping->master_manual) + return -EACCES; + return 0; } diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c index 4cc3fa6b8c98..d95168cdc2d1 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -1020,8 +1020,8 @@ static int uvc_ctrl_check_access(struct uvc_video_chain *chain, int ret = 0; for (i = 0; i < ctrls->count; ++ctrl, ++i) { - ret = uvc_ctrl_is_accessible(chain, ctrl->id, - ioctl == VIDIOC_G_EXT_CTRLS); + ret = uvc_ctrl_is_accessible(chain, ctrl->id, ctrls, + ioctl); if (ret) break; } diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index 24c911aeebce..644d5fcf2eef 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -905,7 +905,8 @@ static inline int uvc_ctrl_rollback(struct uvc_fh *handle) int uvc_ctrl_get(struct uvc_video_chain *chain, struct v4l2_ext_control *xctrl); int uvc_ctrl_set(struct uvc_fh *handle, struct v4l2_ext_control *xctrl); int uvc_ctrl_is_accessible(struct uvc_video_chain *chain, u32 v4l2_id, - bool read); + const struct v4l2_ext_controls *ctrls, + unsigned long ioctl); int uvc_xu_ctrl_query(struct uvc_video_chain *chain, struct uvc_xu_control_query *xqry); From patchwork Fri Dec 2 17:21:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 29039 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp982062wrr; Fri, 2 Dec 2022 09:26:14 -0800 (PST) X-Google-Smtp-Source: AA0mqf421krV3LZQWHuwC2ULJxtkj4t1p05ihxJf9lfuycBO7jXhGkNClptdrDBxcB1llVw6UcpN X-Received: by 2002:a17:90a:ce8d:b0:213:9c67:1b09 with SMTP id g13-20020a17090ace8d00b002139c671b09mr75362723pju.221.1670001973957; Fri, 02 Dec 2022 09:26:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670001973; cv=none; d=google.com; s=arc-20160816; b=pN6hP1SIu6V0vIyxOAJwb4pfozRa918ID6iSL9FW8/OePEwkD0xQqKDvZkuNbqCwCM 6nSj9aEpchaUb4QA+6mQ2gD6ZobnYVf50fuVgiJcN2DVuMlxWi37sPUwU+qYObptLrHt neTsRargXIsLWEYdlKrO6MT52QJG/064E4svEcC60A48wOVEpkFVcHIOnPiD4qeivgB1 f8g92iYn2FKA/sPxH3jxy9qcx4UgdS2hTE6hA+7Dxot2MnCQ0RaHQkijB64zAPfcTyft 4StHKcQ8L0nXVHTr0qjgP+uCoQCQAfs8E6SMb/y9ZFJ0N8PEI/krKDjKTV9nC3j/L6Ee u2Cw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=zQFSXPNg1gYWDjvMJz4jAnc9KE0EX4hKeDHlzX5rMq8=; b=Yo2es7YV/loWPEK3qGzj3FWDUUvcvAlagY6LRoesF0J9OgFmozwOUpV5rGd+Kfpwx1 N+Loa4rMmxdyUdXtQNNl64BpFLobzX8z2n8OJXJNw/g5Y6lE+mzPqCcONWVdsYQw1FF4 U2VpCS+GOMWqp6aJY7FmjrXI3a9+RpQUGGmeRCJrbSrlMAJKrvLPm1lA797a3RXsct7b kUa6EAGpfeUvU8qEolXNJIGJWUPEMO1vBDWY7Syc16SdPUM2uP6xs3qrS5iGZqni1t3H TIkRsHobRXbFkLYBOOA3Ano7oKMccH6Nj2pRcFMrr+OqczT2OHKOG9T5ZfVHnbwbcRoN opNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=BnzWpCO8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x69-20020a638648000000b00476e845a78bsi7925628pgd.126.2022.12.02.09.26.00; Fri, 02 Dec 2022 09:26:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=BnzWpCO8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S234163AbiLBRWE (ORCPT + 99 others); Fri, 2 Dec 2022 12:22:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233664AbiLBRVy (ORCPT ); Fri, 2 Dec 2022 12:21:54 -0500 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E0466F0F6 for ; Fri, 2 Dec 2022 09:21:53 -0800 (PST) Received: by mail-ej1-x62f.google.com with SMTP id td2so13070550ejc.5 for ; Fri, 02 Dec 2022 09:21:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=zQFSXPNg1gYWDjvMJz4jAnc9KE0EX4hKeDHlzX5rMq8=; b=BnzWpCO8mKVwdT7GTBAEcgvYbnL01MbI5NQsr83wBtyLA52vq8ngug/Do3zkiBUTGU EFl1ygWJntPuZIG82M32FyljDEI925ivDIflHNPNj/4vs3/lo3hJx+86WVXnlJiu3J2c S82/5sdSnehGTxs2P7Qm+mLT4cQUErat50eHg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zQFSXPNg1gYWDjvMJz4jAnc9KE0EX4hKeDHlzX5rMq8=; b=azs6djI7GnN8Ej1PtUtnTUEW4XKRQZpsePdJ8CJ7BCuhZYx/Eo39B8y8wv6fqjJbqu 2Q7BEiuTGyAjlX7fn6uXvICmPBfDCN4mYYFPZW4Rof+RmhK7jegfEUUg4ikn5QeUukEd NkzgchJ/CPjD/pjLelJVP39Y+jHnNv2zsUojSKDL276QgMJN9g4iEwFE7dSSK5o5x9yW JT+Sbl/OVbhAGm13I/tuaD4gOlNFYS76CNHotBMLI3MRvMQ+EJTAL38hHKcZJotk9Tmp wjmaE0sVSRkv9d9DT4W93Meyas7dNnFnoBMwJvF3cKdWXytq4njDp3hjO67xbfi8ktxp 3xJw== X-Gm-Message-State: ANoB5pk1/8PsJjRKR+Sg1sNX0HvuD4AwqhqxvO1qWD4dDyPJatCojgXx vMIR8dW3bMQW71d+3iNcOcLmmQ== X-Received: by 2002:a17:906:a198:b0:7b4:bc42:3b44 with SMTP id s24-20020a170906a19800b007b4bc423b44mr54135498ejy.101.1670001711651; Fri, 02 Dec 2022 09:21:51 -0800 (PST) Received: from alco.roam.corp.google.com (80.71.134.83.ipv4.parknet.dk. [80.71.134.83]) by smtp.gmail.com with ESMTPSA id fe17-20020a1709072a5100b007be301a1d51sm3206685ejc.211.2022.12.02.09.21.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Dec 2022 09:21:51 -0800 (PST) From: Ricardo Ribalda Date: Fri, 02 Dec 2022 18:21:36 +0100 Subject: [PATCH RESEND v2 2/7] media: uvcvideo: improve error logging in uvc_query_ctrl() MIME-Version: 1.0 Message-Id: <20220920-resend-v4l2-compliance-v2-2-b0ceb15353ac@chromium.org> References: <20220920-resend-v4l2-compliance-v2-0-b0ceb15353ac@chromium.org> In-Reply-To: <20220920-resend-v4l2-compliance-v2-0-b0ceb15353ac@chromium.org> To: Mauro Carvalho Chehab , Laurent Pinchart Cc: Hans Verkuil , Hans Verkuil , linux-media@vger.kernel.org, Ricardo Ribalda , linux-kernel@vger.kernel.org, Hans Verkuil X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=1265; i=ribalda@chromium.org; h=from:subject:message-id; bh=rgm9ldOQdFvtTQWrF5DcxtzEXVIXvtMre8cRCEzUeW8=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjijQkk2KiH3FCrs6/9FkXB8JArDKnUjOw4uk6Fbtq tybbomSJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY4o0JAAKCRDRN9E+zzrEiFFZD/ 44nlgQCwCgK7bIXKPqOnXBjUX/CBmpUHIfxXj/WT7srZAhrBEf52wH6Z+F3HUfHHnysgURi+FmipeW eanU/JiSfbgezrCmitzwHf/MZx0ugYok1EBad4MXzQid7LYim1h8MbG0FXViYI2DazlxdVEVxGw83K uGOpjPnUbwqr1RzrJfGVQqzg6YtFv6qs96q+sbD8f8j6sKPIszBB9zk4z2hzcu7jzNW4kGWa9d5n5S uRnD55iYeMYIgfeMc4uUzQE6e+m2KDZEGg9ilTutFYMKkSyM3YDLhXMIlS6DX/nJ9SdEn6RF+hbDuk MMZH0R/Hf4VFsnnlKOclKCGHBU3WOBID8LLJ7JbLdKzKQVR7YeKbKpR8xEAqyl9RXzGttP3XxG/4ej zk6bn+zSrjgVqKdNUOU+6xZSS8wtFi9cuyG/0rrlJUIQP/Yjkay+45QwlfZRZYmboc91bNjzYj6iif 3acLBeKaHDp1jKDnX42a5YVmNke18FNKUGCv5j1sDS9cb1eIWJwAfvDyTNyBf4TcuE3rByLUh9uhOQ epjRq9+/JZ9ZwmJF95UhecCD4aiKFVYzCxASZ47wB6XyalMRyJiTnu3cO2h6rIjzRhLn2vbk950J23 QxVYNTgEWAgfSLdCv+UUP8TaXwWa74cfPhNKhCDrJPkUEriwiD76ol3tn/Ug== X-Developer-Key: i=ribalda@chromium.org; a=openpgp; fpr=9EC3BB66E2FC129A6F90B39556A0D81F9F782DA9 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751123989780715928?= X-GMAIL-MSGID: =?utf-8?q?1751123989780715928?= From: Hans Verkuil If __uvc_query_ctrl() failed with a non-EPIPE error, then report that with dev_err. If an error code is obtained, then report that with dev_dbg. Reviewed-by: Ricardo Ribalda Signed-off-by: Hans Verkuil --- drivers/media/usb/uvc/uvc_video.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index 170a008f4006..2cf7f692c0bb 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -79,13 +79,14 @@ int uvc_query_ctrl(struct uvc_device *dev, u8 query, u8 unit, if (likely(ret == size)) return 0; - dev_err(&dev->udev->dev, - "Failed to query (%s) UVC control %u on unit %u: %d (exp. %u).\n", - uvc_query_name(query), cs, unit, ret, size); - - if (ret != -EPIPE) + if (ret != -EPIPE) { + dev_err(&dev->udev->dev, + "Failed to query (%s) UVC control %u on unit %u: %d (exp. %u).\n", + uvc_query_name(query), cs, unit, ret, size); return ret; + } + /* reuse data[0] to request the error code. */ tmp = *(u8 *)data; ret = __uvc_query_ctrl(dev, UVC_GET_CUR, 0, intfnum, From patchwork Fri Dec 2 17:21:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 29034 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp981729wrr; Fri, 2 Dec 2022 09:25:35 -0800 (PST) X-Google-Smtp-Source: AA0mqf7NvgslhJmMm51pxYTuztGEsdmJ3BCGfb52/LJR5BuocYajqShAw/EWJ5oPdFF56uw10wq4 X-Received: by 2002:a63:f510:0:b0:478:1020:b1e6 with SMTP id w16-20020a63f510000000b004781020b1e6mr23829784pgh.561.1670001935092; Fri, 02 Dec 2022 09:25:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670001935; cv=none; d=google.com; s=arc-20160816; b=RV6El+ZB8EZoAzgCVUIr0ipr5EKdmHE1gXhB63lEbYvyV6M/2RbfCXP/urp+yVfeDc DP6jZUSNfZ+Gzq+o1pku4bsp+uYKtmXSps/1Vrj3ND4Q74H7pntAXe5Zu04A3C1yQVfU gKDteIyEink00mTDjWYK8gGJHRr5tBIH6qfd7WucsoMMrTxA+w+NXV4Rll2ys/+v/jLy N7SNrXuxGBEkQMrMpA+tfTvbaUAQIW1M6jZkp7CWYEIadI0LlK1c5c1obpM46IzLQXtx kuvLjufUW4wFM3fgDK8vaFtV18Q9gX2TV39QkhJIpQ84IJhASiJVJrASbta3YYqrY53E N6zg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=bxw2Ty4M46rsTuihUXRiS/Nyvg7teTU6EvDgGOU8X18=; b=Ce2XGJpL4OAWwnlH0XxSsxMq+QXJjl7u2aCfzRNvotfdoJQ9/NSGCnwl5nV+qZTt0O 7sEOTUj+YkcDJANiWtYMt3VqeF152CwqtCWD7nRI+KGwGENCwurzq5TMcCuT8WS/0lUs AHeHc768mARIXVNdlO9hRUoVAu+DCcKWMOoGObcK8iuVC17EgMNyPVuoCyOmXmx4al8K 0XJ9eVTGRvS7N3ezXLqgjde0M0cOepODEJ+ztlGptifknb6XMuXtuo75TWjKge9zPDxV baXZso1mCDWXjVy0gExmWsb61AFMD2zxX9iFkZzsSV56h/N0ChzedkqNF6cu2mZydGNO Facw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=jJEVHDdl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l18-20020a170902e2d200b00189bcf8c18fsi1656870plc.231.2022.12.02.09.25.20; Fri, 02 Dec 2022 09:25:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=jJEVHDdl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S233802AbiLBRWI (ORCPT + 99 others); Fri, 2 Dec 2022 12:22:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233809AbiLBRVy (ORCPT ); Fri, 2 Dec 2022 12:21:54 -0500 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF6A2E7879 for ; Fri, 2 Dec 2022 09:21:53 -0800 (PST) Received: by mail-ej1-x630.google.com with SMTP id bj12so13034889ejb.13 for ; Fri, 02 Dec 2022 09:21:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=bxw2Ty4M46rsTuihUXRiS/Nyvg7teTU6EvDgGOU8X18=; b=jJEVHDdlvpUPCZhRaERran9eUhOM2qlOOFnRvqqedej3zPhgq021ZTuEjKL2vx3Out b4kvxDCjksOswC5RpRzF5475S3alzk2VfBobREeil0g6d3/kqEjadY7zGkArNg7AirEA lZs9jbuWvXKaDNHErwa1oINVxV5f3Y8fHla3I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bxw2Ty4M46rsTuihUXRiS/Nyvg7teTU6EvDgGOU8X18=; b=qFKH+7/XvwGibP4KvoUM4WG39+VNgqamLbQrz68OsIMg6IiEF5w5jPJkzBbD2gJvT7 pEhN66RCGr/Gxiaccz0APVsr4vi6qzey4zW7PggHDhxPBJUr2wYSNwNq3Oe49ImiLRkZ 8jD2S3jDYTcMsDlpM0FnYDlK1pi8/emLoys/6YIgYiQUQHdYwr11nfwDe32TC/jzxI7b F7ndY9Tr2LyNatHgjzmTOddjQkmhO9MU2sosIyewnhCsuVIop54+QQqKI3DCM5H38UUB lK4kkE2RPK/88DNn6eUKoi3ITq5MVCznvK2w5bW5TRjYav4fRYHE5ipUA2y72kjsNPme FSOg== X-Gm-Message-State: ANoB5plwx7OLGJWu7MK5uwWyrqviVcEjeb/NIctK7//e8s6D8fVCfctX FVpgm3lmKeMKxDHBwW+0GqUs7A== X-Received: by 2002:a17:906:a019:b0:7be:e774:5aad with SMTP id p25-20020a170906a01900b007bee7745aadmr11360543ejy.426.1670001712399; Fri, 02 Dec 2022 09:21:52 -0800 (PST) Received: from alco.roam.corp.google.com (80.71.134.83.ipv4.parknet.dk. [80.71.134.83]) by smtp.gmail.com with ESMTPSA id fe17-20020a1709072a5100b007be301a1d51sm3206685ejc.211.2022.12.02.09.21.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Dec 2022 09:21:52 -0800 (PST) From: Ricardo Ribalda Date: Fri, 02 Dec 2022 18:21:37 +0100 Subject: [PATCH RESEND v2 3/7] media: uvcvideo: Return -EACCES for Wrong state error MIME-Version: 1.0 Message-Id: <20220920-resend-v4l2-compliance-v2-3-b0ceb15353ac@chromium.org> References: <20220920-resend-v4l2-compliance-v2-0-b0ceb15353ac@chromium.org> In-Reply-To: <20220920-resend-v4l2-compliance-v2-0-b0ceb15353ac@chromium.org> To: Mauro Carvalho Chehab , Laurent Pinchart Cc: Hans Verkuil , Hans Verkuil , linux-media@vger.kernel.org, Ricardo Ribalda , linux-kernel@vger.kernel.org, Hans Verkuil X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=982; i=ribalda@chromium.org; h=from:subject:message-id; bh=0oIT1Gw1hO0u+7q6An7Ai/dJe13xUDjVNu6Ry1clGFI=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjijQmpIoIjFr3y9ZZLwbmXpabLfWEY4uztWa1E3R0 pSoPKi2JAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY4o0JgAKCRDRN9E+zzrEiAbNEA CaYQocLmpu+Q7+j7T3rRhdnpqASN9EbtMtNzOxii2/ubnfHq8sWhoBFOqlh5IlyN5ItBymGP5ZUzVQ F9Jm+m2UXqvIMvNJAFdDpMyh39BGX53KocfkJJz1w3OO6q0uD/owPRd0P30tC0c6PTIunSLHguVnDz m3bP+NxPjJth125jxjTCyBPG416uvP3gRcAYT/nH61IDmaMMutBFgBkxTMhdRCkCc0iQ1notbaFR4c M5jXlHqroH9o1iYVed2w69/mTRUJSXkv/u06WKGmr3VLD/WhQ/WjkaPbO9eGUEOdrHBuGC1/nUWGik LEWOvGvOpYV/3QWlbs0ThkJDeqy5ZhPuVLAepKGLSEI722isfSbCt2gH8mdawjwS5rFEfM4glXY77g 8FzLCNdn9/CPEyoyH9+mDzSPmx/zl4Rojhbygg3inwSyvkZIZMpkGOk6J9hM83bX79TsxiJgq1bv3A DwZAR4Tz5YlrCsGQYCmcjQb0k3VnP32Iszz/y9nFMfW1dQVZO2ed71fvMK1QStR2CNXtLeAcPTXL87 5agpKQmlJA7QANvJRYHbu9ftRXFAhOC2FjTe9ZoqclTupa/XTX8GCyY15ibV+a65ueo2Xe6weBxJtO Q4ofJX028Tnd37JPaCN+e71KmtbiqLQMFPa449J5eeoUuW083H9WX/Tk2fww== X-Developer-Key: i=ribalda@chromium.org; a=openpgp; fpr=9EC3BB66E2FC129A6F90B39556A0D81F9F782DA9 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751123949195172723?= X-GMAIL-MSGID: =?utf-8?q?1751123949195172723?= For error 2 (Wrong state) return -EACCES instead of -EILSEQ. EACCES is a much more appropriate error code. EILSEQ will return "Invalid or incomplete multibyte or wide character." in strerror(), which is a *very* confusing message. Suggested-by: Hans Verkuil Signed-off-by: Ricardo Ribalda Reviewed-by: Laurent Pinchart --- drivers/media/usb/uvc/uvc_video.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index 2cf7f692c0bb..497073a50194 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -108,7 +108,7 @@ int uvc_query_ctrl(struct uvc_device *dev, u8 query, u8 unit, case 1: /* Not ready */ return -EBUSY; case 2: /* Wrong state */ - return -EILSEQ; + return -EACCES; case 3: /* Power */ return -EREMOTE; case 4: /* Out of range */ From patchwork Fri Dec 2 17:21:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 29036 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp981914wrr; Fri, 2 Dec 2022 09:25:54 -0800 (PST) X-Google-Smtp-Source: AA0mqf4gf9/NrCiLv43p36nz12t18e7ej4vCjNKgi58tiEStT9U52uibp8pDHzZYWeI+c4hRDgKT X-Received: by 2002:a17:902:f2c5:b0:189:1cc3:802a with SMTP id h5-20020a170902f2c500b001891cc3802amr54537549plc.56.1670001954186; Fri, 02 Dec 2022 09:25:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670001954; cv=none; d=google.com; s=arc-20160816; b=cmJmCLrw274umSh+Crnij1EZIXqzGNMJJDLUpauoVlJm8CUoFMZV9TJqkm+fN1N/yY KdOSkNbOvQxcLF/FHedo7ZCFQmArD16A54y+2L7SFfT2rMcJILu11LlHQu3PawS1Mvmu rkeyHQtAlhGA90Sb5p91HnuCC8+1MSNieFuawWG4Vg0VkrroN7iGUVaP4ARJXI6brAf/ JwisMszCmp4duZd3SudSl2qSXxtJF3vZDD1SqMdTgRW9aPaHf5pSKuXAfTIiG9PjYQJf 0ufAQkyZe/vgcm5b4GsS8oCDNsLLejnPPqevQMx+jdS5OnB4X5VVF40kCL4OC4C9eE5Q psYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=Z1aPiVVPlDCTllBooA/cyjkx+Y2V7OSiqGOhFRZ36VQ=; b=xQTrUKqR401aF7HFC2sMws4TpFW/DDTZB2XQTewmWD72VvxN3lqt0fc+wdrvPMyCh+ bhO7JhHn8lTeNzOiOkBUq9FTzYXHsI0YTOSF5w/p+w7TOWB9vegIX0Ldfou/BkqMpZc/ YEvDZT/PHTJiRgvtlCbt/WBpoTnasz3Yw5zI70PD9OF0NZVIJZEj57rvNfjO7pEbx5Hh eAfX3FpMTF03FvcMSRbwzyWMWQeNCcghlUWfnLFLETtiqrZjdD0MENI3ulatmxZfoook omCt2DEB5uU+Aq3Ewn7Ko0yGH1/W74bEqg+ejMh0OfuxesRDOtJQOi4ZYcigY8rNykAR kPMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=IxByCPcf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n14-20020a62e50e000000b0056d67d820ecsi7575750pff.258.2022.12.02.09.25.39; Fri, 02 Dec 2022 09:25:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=IxByCPcf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S234015AbiLBRWS (ORCPT + 99 others); Fri, 2 Dec 2022 12:22:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233973AbiLBRVz (ORCPT ); Fri, 2 Dec 2022 12:21:55 -0500 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AECFC9D2C3 for ; Fri, 2 Dec 2022 09:21:54 -0800 (PST) Received: by mail-ej1-x633.google.com with SMTP id bj12so13034963ejb.13 for ; Fri, 02 Dec 2022 09:21:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Z1aPiVVPlDCTllBooA/cyjkx+Y2V7OSiqGOhFRZ36VQ=; b=IxByCPcfz52cTjbTUwN9fgOj6PnMnGahYA4D0I8s/mvxj1OKSMmPnHkCkGnL21MAiv W7aVZXSCrZ8kgANumWp6xzJCsnhy3ss+ZEB1/naDxPGe0nKDm4mcF8ZkLBFwGU/7MHUM wgXDwFDZB+bbqMRHRn6N4fuN5u8qtqUfTzdZE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Z1aPiVVPlDCTllBooA/cyjkx+Y2V7OSiqGOhFRZ36VQ=; b=QfGyDIjxkaiHftn1kn5JIg4Dh1WWj6NlDvpEwaRPcSoBrCLS37BVOKvpBiuAK+OwEe wtZ84Bw6R35aphOTcp0FjsjwtfSHOfE/wuFyWOBmWDxjxMIQUrBhffxcEDM17WWOA1Ig U1d50H4R1Ei+VhWwuvZVgKhSd8UO34BtyAqbLtjCxzpFF4q+1nUvCu7iVwu8FSvE10Zb YHnATB3ugMFS2TYW/EDfVqo/Q8jI/yD67phMCP1oT0+5Rx49SnUpO4CDQAWCmDx0GCi6 JAcNm8wPtKpyqZ1ouYBYEkTa3HxtMhd9lw0xuUbgBCHpMHEQ26R/zro5zwckHusTEGnA 0Aqg== X-Gm-Message-State: ANoB5pkqPg8GLVmpQ0hwlYaIZYPZyamFXScz2EPe+p/fFTRdICe2FLwh Ap0vAo6ghMfFvR7tutDeq3BvYQ== X-Received: by 2002:a17:906:4e8c:b0:7ba:9c18:1204 with SMTP id v12-20020a1709064e8c00b007ba9c181204mr39579362eju.262.1670001713325; Fri, 02 Dec 2022 09:21:53 -0800 (PST) Received: from alco.roam.corp.google.com (80.71.134.83.ipv4.parknet.dk. [80.71.134.83]) by smtp.gmail.com with ESMTPSA id fe17-20020a1709072a5100b007be301a1d51sm3206685ejc.211.2022.12.02.09.21.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Dec 2022 09:21:52 -0800 (PST) From: Ricardo Ribalda Date: Fri, 02 Dec 2022 18:21:38 +0100 Subject: [PATCH RESEND v2 4/7] media: uvcvideo: Do not return positive errors in uvc_query_ctrl() MIME-Version: 1.0 Message-Id: <20220920-resend-v4l2-compliance-v2-4-b0ceb15353ac@chromium.org> References: <20220920-resend-v4l2-compliance-v2-0-b0ceb15353ac@chromium.org> In-Reply-To: <20220920-resend-v4l2-compliance-v2-0-b0ceb15353ac@chromium.org> To: Mauro Carvalho Chehab , Laurent Pinchart Cc: Hans Verkuil , Hans Verkuil , linux-media@vger.kernel.org, Ricardo Ribalda , linux-kernel@vger.kernel.org, Hans Verkuil X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=963; i=ribalda@chromium.org; h=from:subject:message-id; bh=CrX1QP0MUpT5GPNS9+y3kLIDIjsOHF6cFLdPMYSyV0Y=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjijQop6CSX4WKA8eEwB7KCAVyCeS/f5mL+1jPm51Z w2ePrMCJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY4o0KAAKCRDRN9E+zzrEiBncD/ 4ymJjJEZahs1/dcQ6bbs2dRSxIPYY4z6ip53LnN1v8aiXVNs38zmQpamI0E4D3idP8W8YLqFaUpJj1 VuaKlsIMzd0FkwkrmL2FX9c/5Pcxeq7kXRZ3dimv52i7KkU51etyTQiNT+HNHsiRW6iFoyu3nF2krB Ifu8QTRJ/FMW/aFQK3aQgQIIP1WdH2FoJZxyHTU0cJufBFZOxvpTw349g4ameJ4Yd4RLDs8enVf2fD CUVspusW9j5a2FKBq3JS6qBAhDNoyC5r0OU6DEg4WSTiSsKG/6YFMZ7AnwuDq00PjyQQBVJegS2LBl 7SzZBdSNaD27CvrqPPY+oHRSGdYAc+4AnV9qcAraJaVCoa1Ym1JgCTJx0PMmq3ar7nNBg9qBmUkpl9 CPhJsK5t9zTK1WmLo/PsCyBfpnh61KWNX5t/lMcn1YwwU6aj1a1vTtSKVXWuFc3+Trzp76KThakFyy 0ZIjsXZQSbphInK/AyKcmo0UMbfi+gLUzsfogSvNnucR9aJQpHo2xThNPnkJPiL0+fUrSQ4eZOaFMP dVOlJ3CmM/z9ZVyiaHXWfPf48pkriKxLwNn7jegVhXLir88b9SCyhbzwEEgWk8ZapV40Lkd9gBme6G HRAVQIqF9M2BxQkAdLZAeyxDtB4Nb9Etfwq1kSToDJ0lWWYk67/eUxZjee4A== X-Developer-Key: i=ribalda@chromium.org; a=openpgp; fpr=9EC3BB66E2FC129A6F90B39556A0D81F9F782DA9 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751123968998655114?= X-GMAIL-MSGID: =?utf-8?q?1751123968998655114?= If the returned size of the query does not match the expected size or it is zero, return -EPIPE instead of 0 or a positive value. Suggested-by: Laurent Pinchart Signed-off-by: Ricardo Ribalda Reviewed-by: Laurent Pinchart --- drivers/media/usb/uvc/uvc_video.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index 497073a50194..902f2817a743 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -83,7 +83,7 @@ int uvc_query_ctrl(struct uvc_device *dev, u8 query, u8 unit, dev_err(&dev->udev->dev, "Failed to query (%s) UVC control %u on unit %u: %d (exp. %u).\n", uvc_query_name(query), cs, unit, ret, size); - return ret; + return ret < 0 ? ret : -EPIPE; } /* reuse data[0] to request the error code. */ From patchwork Fri Dec 2 17:21:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 29031 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp981499wrr; Fri, 2 Dec 2022 09:25:03 -0800 (PST) X-Google-Smtp-Source: AA0mqf60QM1XL94Kna+nMYbn2oyf/z40Tb5GYZGCrg4rkWj7R6YqxwgsReXRd5Z4/v0rLLXzyaNu X-Received: by 2002:a17:906:5ad7:b0:7c0:b55f:295 with SMTP id x23-20020a1709065ad700b007c0b55f0295mr6416535ejs.424.1670001902956; Fri, 02 Dec 2022 09:25:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670001902; cv=none; d=google.com; s=arc-20160816; b=LyxAPFHVePdzRzozM9urWeIQ6rbdqN/bFq5VVpCiV/AChnu2YOKGfeqKvgY3jCLjTe NgYj5Q0iQZFfE9jLPTY3hFG8oIjsdptnwBuIGBS4riCVAuwzhWfVJn+TmnEOFBGREMql 4GdJnED7zA8jnoXBZCqtrPli0TmuEwPshJxV1Yg5TK/peYqBjX4ldiUxU91hPEbYmgx4 D110E0MNH9T1TqNSb/TDI2yiqzYiFmkeFavxv+4RZC7lql1jeUJ8twPE0kauBFZLutQG BS7ja0lNnJTuG7Y7fwnQi5sjnv/jmuMkDUfhwo5kVoduK10DZpW/fYH5ms0eOZVj3nEV RSdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=1TOCYbcSDGYo9uBDae2YM90jdMCkFXFL9pKLx8gH8lk=; b=NwHDqVRjgFk/sZQXvfckzmgw0wps7i75YTFw9YkioCFAebIo642osNGNFpTGkMfUSf G+JNYRughcJnH1omcN2EVZpDCdZ7j7PGLb0DZZIsfjXUOT2PEqtzgMHgnOdB35mQyew1 MkqTU7jDl9nvcvIO+dqvslfn8ze9He0WgVj2fxUZxqCKojWm26CMdiEXFL0LWhZiPdhD hfwgj0KcZjCKqgPo5T6IXdSgXewYoN1gOKm2gTwZHg9Z3q6v+7nXtGXVKMwrAmuacGfC gW3YU19wy2b33t1SqVFXON5v7UIImpYbxJN7T7mDcCrPw+jQcIJ8BlmqEDzKMdbFtOgI 3BIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Rv8G+gUW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cw8-20020a170906478800b007ad8bd5a3b2si7731304ejc.263.2022.12.02.09.24.39; Fri, 02 Dec 2022 09:25:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Rv8G+gUW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S234211AbiLBRWM (ORCPT + 99 others); Fri, 2 Dec 2022 12:22:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234096AbiLBRV4 (ORCPT ); Fri, 2 Dec 2022 12:21:56 -0500 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67717E7879 for ; Fri, 2 Dec 2022 09:21:55 -0800 (PST) Received: by mail-ej1-x62a.google.com with SMTP id bj12so13035029ejb.13 for ; Fri, 02 Dec 2022 09:21:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=1TOCYbcSDGYo9uBDae2YM90jdMCkFXFL9pKLx8gH8lk=; b=Rv8G+gUWpIQ0RpbmMyAexFTzcwXByWUGtbzZhNjQV34dWvYdqMGVOyV2zgXVLnStUI JreWZrXYPkvYSMfX3iLfHq8zfjqx+7nFjRu1T6UvpwfVUHXcrrefkFAztT2nA9iV1aBf 9PKgvJcAuYoIrWWM1bdOOwvDxl6pCt6GEzHVw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1TOCYbcSDGYo9uBDae2YM90jdMCkFXFL9pKLx8gH8lk=; b=fXfSVmleq67wo/EW62J0MlZKtaGCNmZy7jNpY0yoFQPhimoEwCH1YTC3O62hSMpqrX 3Yf/OnYfMArNrEKYn9/f5VsPkxOTqLkEXvFv2HlQGS1oszj7XgS5OgparkWMtPjJLXGD tAkCiz1TeYChwQfrjp8z4Hi4OEs60rD4r77PnymecVZjV6goeeAyeUCVbNiB0j7wHJ7M IS3iO25u9pPUT5wm/qZaHcXL+1z7FzcYXOj34kO1m01/vzypcZYJu8Z5dZ5Mi8W0+o+b BH9VVPo9Kk1MCsDN/ooKbCSHmJWQKYcmX97zD+6S5HDGXAzjtuOnlfGhS3FeIO8dGmGE FMtQ== X-Gm-Message-State: ANoB5pkCTkkE6I99etkNH+Yf1YApqsor5dHu4fKHx5kS9YWeipGntPrj WbWCTKcbrlz9iFDCMdltnUel3w== X-Received: by 2002:a17:906:a387:b0:7bc:2ad:7c1e with SMTP id k7-20020a170906a38700b007bc02ad7c1emr34567522ejz.588.1670001713981; Fri, 02 Dec 2022 09:21:53 -0800 (PST) Received: from alco.roam.corp.google.com (80.71.134.83.ipv4.parknet.dk. [80.71.134.83]) by smtp.gmail.com with ESMTPSA id fe17-20020a1709072a5100b007be301a1d51sm3206685ejc.211.2022.12.02.09.21.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Dec 2022 09:21:53 -0800 (PST) From: Ricardo Ribalda Date: Fri, 02 Dec 2022 18:21:39 +0100 Subject: [PATCH RESEND v2 5/7] media: uvcvideo: Fix handling on Bitmask controls MIME-Version: 1.0 Message-Id: <20220920-resend-v4l2-compliance-v2-5-b0ceb15353ac@chromium.org> References: <20220920-resend-v4l2-compliance-v2-0-b0ceb15353ac@chromium.org> In-Reply-To: <20220920-resend-v4l2-compliance-v2-0-b0ceb15353ac@chromium.org> To: Mauro Carvalho Chehab , Laurent Pinchart Cc: Hans Verkuil , Hans Verkuil , linux-media@vger.kernel.org, Ricardo Ribalda , linux-kernel@vger.kernel.org, Hans Verkuil X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=4061; i=ribalda@chromium.org; h=from:subject:message-id; bh=Q6Ty28eEyDWUJosEKd4UTXCsSOQeb3Aa2fdI+JNxN3I=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjijQpN+Gp11+KJtyf2NqCaonYO3z4AG74/0P4ktMz X+9mnGyJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY4o0KQAKCRDRN9E+zzrEiDabD/ 4hdednARo9vIZ63cZE6rj/LqS7zBcNbf4ARBjcT0uoLqLwPIoOBReqPeG7oJyDA7hLjdCVFOvjQpLp C2Cskx1EE/9OoCEVpnh8KpSiqv4vOdkh9MrXErvEs3ftBp4ygmFnC1epjDrjn7R5YzQAyMdNdew04S qOmrIGTuDkPpo0rwg+zjuwMuPSUwmAuHr21BHWQpCEp10jfllYv8bc5Wpnh7c3u+36ri8mTD5ACwva EcWSQjHA1/krvk24Rm/78XqJWJ/l6ocDc+1vLfspiPYs/jzKO1UxAJwHY6FpYWeQLVApg2KyVPVuaf Ha6Xc5oFzZOZKJdzbjtNtIt5ds5L5zpUS6TtQEWdoWHsLZneng1Md9yh7PuCSmDq2dCSLBqxCP6Ujw kw+qmFX5Y550YZ+alIAdvaqxkIrWNB1jR962Mxg7bD4Zm+FOHlFlA/O7EO5TXGB+Kj+7DVrARWAXxL d/x8eUeFbdqXGhxDtt/FPH64Qz5pIrgElhgSfQplbJo2XSkCyArPy8d3C5bAHQk0AbW0A59U9+P6DX 9Xn0B6UzUIwaxA89+K7Md2aTY/wxc5bQ4ZlUOJw+tKmbb1PtGpDGNrn+vwm4SVXjR5JNBgV9xqHJ5N J1RsVk6vooHSyqNZPxJ888bSHIsN3xBVxlQG7/n8vad5+q4YuseFYRFGI4iQ== X-Developer-Key: i=ribalda@chromium.org; a=openpgp; fpr=9EC3BB66E2FC129A6F90B39556A0D81F9F782DA9 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751123915425229647?= X-GMAIL-MSGID: =?utf-8?q?1751123915425229647?= Minimum and step values for V4L2_CTRL_TYPE_BITMASK controls should be 0. There is no need to query the camera firmware about this and maybe get invalid results. Also value should be masked to the max value advertised by the hardware. Finally, handle uvc 1.5 mask controls that use MAX instead of RES to describe the valid bits. Fixes v4l2-compliane: Control ioctls (Input 0): fail: v4l2-test-controls.cpp(97): minimum must be 0 for a bitmask control test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: FAIL Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_ctrl.c | 53 +++++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 12 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 7153ee5aabb1..526572044e82 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1145,6 +1145,25 @@ static const char *uvc_map_get_name(const struct uvc_control_mapping *map) return "Unknown Control"; } +static u32 uvc_get_ctrl_bitmap(struct uvc_control *ctrl, + struct uvc_control_mapping *mapping) +{ + /* + * Some controls, like CT_AE_MODE_CONTROL use GET_RES to + * represent the number of bits supported, those controls + * do not list GET_MAX as supported. + */ + if (ctrl->info.flags & UVC_CTRL_FLAG_GET_MAX) + return mapping->get(mapping, UVC_GET_MAX, + uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MAX)); + + if (ctrl->info.flags & UVC_CTRL_FLAG_GET_RES) + return mapping->get(mapping, UVC_GET_RES, + uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES)); + + return ~0; +} + static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, struct uvc_control *ctrl, struct uvc_control_mapping *mapping, @@ -1219,6 +1238,12 @@ static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, v4l2_ctrl->step = 0; return 0; + case V4L2_CTRL_TYPE_BITMASK: + v4l2_ctrl->minimum = 0; + v4l2_ctrl->maximum = uvc_get_ctrl_bitmap(ctrl, mapping); + v4l2_ctrl->step = 0; + return 0; + default: break; } @@ -1320,19 +1345,14 @@ int uvc_query_v4l2_menu(struct uvc_video_chain *chain, menu_info = &mapping->menu_info[query_menu->index]; - if (mapping->data_type == UVC_CTRL_DATA_TYPE_BITMASK && - (ctrl->info.flags & UVC_CTRL_FLAG_GET_RES)) { - s32 bitmap; - + if (mapping->data_type == UVC_CTRL_DATA_TYPE_BITMASK) { if (!ctrl->cached) { ret = uvc_ctrl_populate_cache(chain, ctrl); if (ret < 0) goto done; } - bitmap = mapping->get(mapping, UVC_GET_RES, - uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES)); - if (!(bitmap & menu_info->value)) { + if (!(uvc_get_ctrl_bitmap(ctrl, mapping) & menu_info->value)) { ret = -EINVAL; goto done; } @@ -1815,6 +1835,18 @@ int uvc_ctrl_set(struct uvc_fh *handle, value = xctrl->value; break; + case V4L2_CTRL_TYPE_BITMASK: + if (!ctrl->cached) { + ret = uvc_ctrl_populate_cache(chain, ctrl); + if (ret < 0) + return ret; + } + + xctrl->value = max(0, xctrl->value); + xctrl->value &= uvc_get_ctrl_bitmap(ctrl, mapping); + value = xctrl->value; + break; + case V4L2_CTRL_TYPE_BOOLEAN: xctrl->value = clamp(xctrl->value, 0, 1); value = xctrl->value; @@ -1829,17 +1861,14 @@ int uvc_ctrl_set(struct uvc_fh *handle, * Valid menu indices are reported by the GET_RES request for * UVC controls that support it. */ - if (mapping->data_type == UVC_CTRL_DATA_TYPE_BITMASK && - (ctrl->info.flags & UVC_CTRL_FLAG_GET_RES)) { + if (mapping->data_type == UVC_CTRL_DATA_TYPE_BITMASK) { if (!ctrl->cached) { ret = uvc_ctrl_populate_cache(chain, ctrl); if (ret < 0) return ret; } - step = mapping->get(mapping, UVC_GET_RES, - uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES)); - if (!(step & value)) + if (!(uvc_get_ctrl_bitmap(ctrl, mapping) & value)) return -EINVAL; } From patchwork Fri Dec 2 17:21:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 29032 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp981573wrr; Fri, 2 Dec 2022 09:25:13 -0800 (PST) X-Google-Smtp-Source: AA0mqf4WgnQevQ2xjC0un3SyonlvhGEup9SdsAQTIQcuSS6T4VUxJeOb8wekRzqTfKyAXDEvKt4D X-Received: by 2002:a17:906:5a8b:b0:7c0:bf7c:a56b with SMTP id l11-20020a1709065a8b00b007c0bf7ca56bmr4057305ejq.306.1670001913659; Fri, 02 Dec 2022 09:25:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670001913; cv=none; d=google.com; s=arc-20160816; b=ASaUJBi/kwb6CVJEKfRNv9UFrSz8yHlJHJ3f/8Z78ZIb1Xb6mLeNUwxw5+9lY8zJCL UO6qR+56vHpHER1nQ65Mcet9i5ZqLuVXoaJRajYlKKOCzG+hSKylrZJeXrG9XLKIlVY8 nqUAMorTsWRnoKs94PaLrHlO6rTnaDipwVVGqls/sF02877D/m+2HB15BqnyraJhuEq+ 6uy20eY8Bxj5Lop5N9fChaS2P/3i0AKsJLe0K5X49/Mwj7SUhKkbC88dKJBxJNg4qHBZ cTLH0Ey3jqa2KiAC9xsunskNbSiHatAHYZsNQdWLrPcV/NejHExVtEwr7E5kt0lpTMAJ jF3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=kFcyBpj+roptImEjPj9piLF8BA0R7w/IlAfi2K8P7bY=; b=ZNMblwYj5jBo1R0sFMUg3s3PfMonWr9LrHkOBMa/QIDRWtlZ0clb2tTrawNfxOw9up fSUeLoO7JYenA8lmWcjZjGcNd/Y9C+PdHQBAcODEuj00jj/2Qj4CauAWByKKltPqHRbD izXsoO4njwU7VTRvhsmr998xOfjqB4/0UHcYHKGCCCVHPMwc+DFMxa0+d++dpKFwFZ5h LyNHiiLnAmBsc519st38eXc/tA7jTBkjBeMEKF/bNxMYk2H4V7t+k4ZmfDFUt0LkgkaU wJePsGycHqSVteodB4cveKC3mreyJzJX0Ww7PZUKXPC6FjGQMZQlBfgATLngwHI3F4Lk V2JQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=GJGQWn6x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qk32-20020a1709077fa000b007877b1c7f27si7060285ejc.829.2022.12.02.09.24.49; Fri, 02 Dec 2022 09:25:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=GJGQWn6x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S233946AbiLBRWW (ORCPT + 99 others); Fri, 2 Dec 2022 12:22:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234145AbiLBRV5 (ORCPT ); Fri, 2 Dec 2022 12:21:57 -0500 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 031F36F0F6 for ; Fri, 2 Dec 2022 09:21:56 -0800 (PST) Received: by mail-ej1-x631.google.com with SMTP id fy37so13028749ejc.11 for ; Fri, 02 Dec 2022 09:21:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=kFcyBpj+roptImEjPj9piLF8BA0R7w/IlAfi2K8P7bY=; b=GJGQWn6xnoSY7Etym9vgtQmRI7e2aKzTXyoq8ceLg89ytjx8ExTNQ/K3mgnmQxKtcM hV1qZaRprsc75L8mzCcjtuWDDX0QUncg3zNHukS6UtvicoqqzZzmEFsPMGLmZLcl4ddi +W+iDxLGFAOL9kjjX+260929kQNvNuKcnyfvA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kFcyBpj+roptImEjPj9piLF8BA0R7w/IlAfi2K8P7bY=; b=zOCpEILkT7cOlfVJyrGY1HhPE/hdg3Yl/esyEimqTVsrn9ftXdMEYV5U5cC01g1U1+ 8k7GWsdihDEuArMBd6UNb5UiuUmDHLAv8WTmXgBdXI+g6KjO27BeHBlc1KK91kQoMMTQ O/I7wpFDdSyHmngY4Oqh9K59JdZGyXow3ldfrpFxBD6I4dVbZCgliqhJKuj6k8GML49Q OWC7+1y8GhxwjbpeBIjH42yRAy/7aY81XmNgyPnt9STt1hCyfnFDPOjl6UaPfVR26uct d29S8pYhNP1YPmkv5MbuT6/YsNFnDFE3l+f7k2Zhqa3kUU0o/zo03FVPe2+na7F37t2R rKIA== X-Gm-Message-State: ANoB5pkjuGCNMCXl//Xuc7U4uj1+9iM2sbrsf0obVZ2SYzgpOHaAaaru r/5Qym3CAY3tEefQowR2MZKE+A== X-Received: by 2002:a17:906:5792:b0:7c0:9e1d:c83b with SMTP id k18-20020a170906579200b007c09e1dc83bmr11992942ejq.68.1670001714555; Fri, 02 Dec 2022 09:21:54 -0800 (PST) Received: from alco.roam.corp.google.com (80.71.134.83.ipv4.parknet.dk. [80.71.134.83]) by smtp.gmail.com with ESMTPSA id fe17-20020a1709072a5100b007be301a1d51sm3206685ejc.211.2022.12.02.09.21.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Dec 2022 09:21:54 -0800 (PST) From: Ricardo Ribalda Date: Fri, 02 Dec 2022 18:21:40 +0100 Subject: [PATCH RESEND v2 6/7] media: uvcvideo: Implement mask for V4L2_CTRL_TYPE_MENU MIME-Version: 1.0 Message-Id: <20220920-resend-v4l2-compliance-v2-6-b0ceb15353ac@chromium.org> References: <20220920-resend-v4l2-compliance-v2-0-b0ceb15353ac@chromium.org> In-Reply-To: <20220920-resend-v4l2-compliance-v2-0-b0ceb15353ac@chromium.org> To: Mauro Carvalho Chehab , Laurent Pinchart Cc: Hans Verkuil , Hans Verkuil , linux-media@vger.kernel.org, Ricardo Ribalda , linux-kernel@vger.kernel.org, Hans Verkuil X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=5794; i=ribalda@chromium.org; h=from:subject:message-id; bh=u0yMi5/b9HeKgqPvAbyKu4QWjgjZ09vQlVYM51vM0MI=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjijQrqdm7x9AeEez0Rs5z96/uVtOCtyrQXMM4olmo 9fU5NWeJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY4o0KwAKCRDRN9E+zzrEiFiMD/ wIK6XzjhijxUt99b5c1npLY+opxvbJa7ZuQpbCKzCAytyeXZd/lkx1P4vRq//8LVYj5gI3nBbbQMl+ DBCXnM2x/kcUEOFfPv0XM3KbzvNr8aS56CvNEbF9BIqeAyBYxrjHth2EjXhhZdqY8Md3FfiN9YL0Rs JMVjuNsBYziJXZSwg8sm0Yb3ZbqabHwTZqUzivRHf5TcOVS9Sskd/gJsh7uVAI9i3fGQ1ilZFSVA9v PCe77hdQT5gZCm1UXPLWffMH3Rl5FFbLSESokwnuELflSggl73hc+ShGHv2gKJLbLriSvlUnH2XB6h 4d+/hWENuAtgp7hDqbFDSNZFDBGPdBFJOkOIMrZIL/qP+oIlt32JPENS8JFRulB5flYlCUoYgLDzZH kJO1eDIO+AQv9TYKWjg2ie+2foaalLXA976Vm1iE0lcirnzkILGoAhCZOYH2dwh/0pQaLtvwdeR40E tzuSKxr6wyxtpeKMq0szztkA4rXpestkiE1DGnwR9vSWGSGxWtiJn4uf3093Hk9ahgCQWimIBoIgmD xXx7nl+afITvGrEhERBwHbDyWC9bLy7f1V70j94fwlKZVLc7IaNLoTfPvI+O9i1GGWLuQSDm8DCGbD E5eZWh3mnFARiiHwaXW/6SRIw3v2pCcbQo7J9Gi+gO21EA1F7mVqJLDqJhsQ== X-Developer-Key: i=ribalda@chromium.org; a=openpgp; fpr=9EC3BB66E2FC129A6F90B39556A0D81F9F782DA9 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751123926636926947?= X-GMAIL-MSGID: =?utf-8?q?1751123926636926947?= Replace the count with a mask field that lets us choose not only the max value, but also the minimum value and what values are valid in between. Signed-off-by: Ricardo Ribalda Suggested-by: Laurent Pinchart Reviewed-by: Laurent Pinchart --- drivers/media/usb/uvc/uvc_ctrl.c | 30 ++++++++++++++++++++---------- drivers/media/usb/uvc/uvc_driver.c | 2 +- drivers/media/usb/uvc/uvc_v4l2.c | 2 +- drivers/media/usb/uvc/uvcvideo.h | 2 +- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 526572044e82..df273b829961 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -6,6 +6,7 @@ * Laurent Pinchart (laurent.pinchart@ideasonboard.com) */ +#include #include #include #include @@ -524,7 +525,7 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { .v4l2_type = V4L2_CTRL_TYPE_MENU, .data_type = UVC_CTRL_DATA_TYPE_BITMASK, .menu_info = exposure_auto_controls, - .menu_count = ARRAY_SIZE(exposure_auto_controls), + .menu_mask = BIT_MASK(ARRAY_SIZE(exposure_auto_controls)), .slave_ids = { V4L2_CID_EXPOSURE_ABSOLUTE, }, }, { @@ -730,7 +731,7 @@ static const struct uvc_control_mapping uvc_ctrl_mappings_uvc11[] = { .v4l2_type = V4L2_CTRL_TYPE_MENU, .data_type = UVC_CTRL_DATA_TYPE_ENUM, .menu_info = power_line_frequency_controls, - .menu_count = ARRAY_SIZE(power_line_frequency_controls) - 1, + .menu_mask = BIT_MASK(ARRAY_SIZE(power_line_frequency_controls) - 1), }, }; @@ -744,7 +745,7 @@ static const struct uvc_control_mapping uvc_ctrl_mappings_uvc15[] = { .v4l2_type = V4L2_CTRL_TYPE_MENU, .data_type = UVC_CTRL_DATA_TYPE_ENUM, .menu_info = power_line_frequency_controls, - .menu_count = ARRAY_SIZE(power_line_frequency_controls), + .menu_mask = BIT_MASK(ARRAY_SIZE(power_line_frequency_controls)), }, }; @@ -974,7 +975,9 @@ static s32 __uvc_ctrl_get_value(struct uvc_control_mapping *mapping, const struct uvc_menu_info *menu = mapping->menu_info; unsigned int i; - for (i = 0; i < mapping->menu_count; ++i, ++menu) { + for (i = 0; BIT(i) <= mapping->menu_mask; ++i, ++menu) { + if (!test_bit(i, &mapping->menu_mask)) + continue; if (menu->value == value) { value = i; break; @@ -1212,12 +1215,14 @@ static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, switch (mapping->v4l2_type) { case V4L2_CTRL_TYPE_MENU: - v4l2_ctrl->minimum = 0; - v4l2_ctrl->maximum = mapping->menu_count - 1; + v4l2_ctrl->minimum = ffs(mapping->menu_mask) - 1; + v4l2_ctrl->maximum = fls(mapping->menu_mask) - 1; v4l2_ctrl->step = 1; menu = mapping->menu_info; - for (i = 0; i < mapping->menu_count; ++i, ++menu) { + for (i = 0; BIT(i) <= mapping->menu_mask; ++i, ++menu) { + if (!test_bit(i, &mapping->menu_mask)) + continue; if (menu->value == v4l2_ctrl->default_value) { v4l2_ctrl->default_value = i; break; @@ -1338,7 +1343,7 @@ int uvc_query_v4l2_menu(struct uvc_video_chain *chain, goto done; } - if (query_menu->index >= mapping->menu_count) { + if (!test_bit(query_menu->index, &mapping->menu_mask)) { ret = -EINVAL; goto done; } @@ -1853,8 +1858,13 @@ int uvc_ctrl_set(struct uvc_fh *handle, break; case V4L2_CTRL_TYPE_MENU: - if (xctrl->value < 0 || xctrl->value >= mapping->menu_count) + if (xctrl->value < (ffs(mapping->menu_mask) - 1) || + xctrl->value > (fls(mapping->menu_mask) - 1)) return -ERANGE; + + if (!test_bit(xctrl->value, &mapping->menu_mask)) + return -EINVAL; + value = mapping->menu_info[xctrl->value].value; /* @@ -2301,7 +2311,7 @@ static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, INIT_LIST_HEAD(&map->ev_subs); - size = sizeof(*mapping->menu_info) * mapping->menu_count; + size = sizeof(*mapping->menu_info) * fls(mapping->menu_mask); map->menu_info = kmemdup(mapping->menu_info, size, GFP_KERNEL); if (map->menu_info == NULL) { kfree(map->name); diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index 9c05776f11d1..abdb9ca7eed6 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -2675,7 +2675,7 @@ static const struct uvc_control_mapping uvc_ctrl_power_line_mapping_limited = { .v4l2_type = V4L2_CTRL_TYPE_MENU, .data_type = UVC_CTRL_DATA_TYPE_ENUM, .menu_info = power_line_frequency_controls_limited, - .menu_count = ARRAY_SIZE(power_line_frequency_controls_limited), + .menu_mask = BIT_MASK(ARRAY_SIZE(power_line_frequency_controls_limited)), }; static const struct uvc_device_info uvc_ctrl_power_line_limited = { diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c index d95168cdc2d1..e6792fd46bf5 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -80,7 +80,7 @@ static int uvc_ioctl_ctrl_map(struct uvc_video_chain *chain, goto free_map; } - map->menu_count = xmap->menu_count; + map->menu_mask = BIT_MASK(xmap->menu_count); break; default: diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index 644d5fcf2eef..7e2339fc256e 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -255,7 +255,7 @@ struct uvc_control_mapping { u32 data_type; const struct uvc_menu_info *menu_info; - u32 menu_count; + unsigned long menu_mask; u32 master_id; s32 master_manual; From patchwork Fri Dec 2 17:21:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 29041 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp982315wrr; Fri, 2 Dec 2022 09:26:52 -0800 (PST) X-Google-Smtp-Source: AA0mqf4FSu4ZQilah17LL8MCi/Fi3UM7O5ReRgharoqwZCPRXud8ds1VPl9ww5Z7gFofN9v43sKQ X-Received: by 2002:a17:902:b20f:b0:188:d4ea:251f with SMTP id t15-20020a170902b20f00b00188d4ea251fmr65741934plr.36.1670002012585; Fri, 02 Dec 2022 09:26:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670002012; cv=none; d=google.com; s=arc-20160816; b=mBNyAxPVc8qc0Eos5Or/k8tbVkBaF35WiBBUYXp7d+dEOpI23e7Cw1Lmzye/uekQux c7VERW8p9ZADewPQGR8x/V6aWTUGWgnl2RlJJqKtgPW1jKvmf01fl0yABiovRGU6dEsM P0JQCI/CVYtxDV5DtmXn6T8vVDonTBo9+5W8udYviHouTj8AWCXy7GMSFnzpbTzYDFTd kl6xNSoefjFNvg5LiwO138MBP7EJpzmfwVzNSQlyTH2/6WJlInEq1O9zDWnxQ5xYr4h2 TZoNRl9YcSgfP7g4XE3Yq8kXCHyHWGEsDc/Sha+ldNLgDu23xqgc2ZfD1XsIS+74T+c6 2/Fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=EjhL47z9Nl+DaAg29fxcGxhmqEDsIaNpB1QWBqLjg58=; b=lzeG/F4qcWE3Eoj6Sjr4mIUdpH6Eq5QFoM9aCfWqK4Y7Wyfy/8LAL9fkJ2u258gR1S GxALHQoilVBhYC2u4DUTKnvWMJmiOXnYvPh4o9Az2RT+K08TrXzpCn4z9mJc5eW0EuF/ Y2aGkxSJFKqri87L+o1gptA3O1sc1jqYuKso6cUdS+6w+iY3bux7jbakAZ1LskYUsWNR MQX5szPmWZ4B1fK1KPReUj9AYkEpPSRvAtjrpegGPjVOtwcBZn1VfTKgBWDEsbjgmMjv TJLQCZcyyOwLNCLbPYKPV5x00/arEW2mAW4IcfMfaQyem7Vfxp1WRbHJ0NjU81lAGoY8 vusQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=gUybeRSn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mw10-20020a17090b4d0a00b0020d5867aab6si8627642pjb.141.2022.12.02.09.26.38; Fri, 02 Dec 2022 09:26:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=gUybeRSn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S234380AbiLBRW1 (ORCPT + 99 others); Fri, 2 Dec 2022 12:22:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233837AbiLBRWC (ORCPT ); Fri, 2 Dec 2022 12:22:02 -0500 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 222699D2C3 for ; Fri, 2 Dec 2022 09:21:57 -0800 (PST) Received: by mail-ej1-x635.google.com with SMTP id fy37so13028865ejc.11 for ; Fri, 02 Dec 2022 09:21:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=EjhL47z9Nl+DaAg29fxcGxhmqEDsIaNpB1QWBqLjg58=; b=gUybeRSnsTC0aPYHfRkd5QF9Nu44JbnujAhiWe8zqjr0Na8yfDqSl4ugB+81lmz0qV EZHYcR0O8pfYxb5qaPjjJsyKJNE9VIWMvCr+dNxSTLpvwo73ZLiqppnhEl+gvTftUMUT gMLacG2c4ujg6pOGC7I1P9mR8FUnfz3GEtZLM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EjhL47z9Nl+DaAg29fxcGxhmqEDsIaNpB1QWBqLjg58=; b=8PNGiKB25gv+m9eQbaLTbN9/z4awQEZL2A8HL2I5kITfC4iX3aEuK5GDS2alIqo8nO RGSAq6w9Xy2I6jKSo1zyjitJo7mDFvlW6rD4s2VcF5z06d5r9sfhPa8/LZK+4+lU93Nt T1XlRHPFOyVHkvfgNHntBQo405G3Ul0lkMsjg1EgjKC2euLiKeDcYzD29d5y/tI0bDSd 3x67KA8Ei02nW7Y/zjiUc8XRsJdzv3bLVTNskrkFqWhjPTOgjlX3XUphzho4WBz/8+tp xG1HHeNq205iq2ML5Zw+WVKFjeVWrj9hzldeWEomjGr3L1e4W73KmbjeHhDk+UwlxwzQ RgVg== X-Gm-Message-State: ANoB5pkxKBOIGUcEINU3JlmLNMOW7/7sCgfO/7zAQqxbvD1GoixjiAUZ preMmg/2QE5l7rK2tRel0g/U9Q== X-Received: by 2002:a17:907:986b:b0:7ad:b7c2:a2f7 with SMTP id ko11-20020a170907986b00b007adb7c2a2f7mr45617347ejc.227.1670001715642; Fri, 02 Dec 2022 09:21:55 -0800 (PST) Received: from alco.roam.corp.google.com (80.71.134.83.ipv4.parknet.dk. [80.71.134.83]) by smtp.gmail.com with ESMTPSA id fe17-20020a1709072a5100b007be301a1d51sm3206685ejc.211.2022.12.02.09.21.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Dec 2022 09:21:55 -0800 (PST) From: Ricardo Ribalda Date: Fri, 02 Dec 2022 18:21:41 +0100 Subject: [PATCH RESEND v2 7/7] media: uvcvideo: Use standard names for menus MIME-Version: 1.0 Message-Id: <20220920-resend-v4l2-compliance-v2-7-b0ceb15353ac@chromium.org> References: <20220920-resend-v4l2-compliance-v2-0-b0ceb15353ac@chromium.org> In-Reply-To: <20220920-resend-v4l2-compliance-v2-0-b0ceb15353ac@chromium.org> To: Mauro Carvalho Chehab , Laurent Pinchart Cc: Hans Verkuil , Hans Verkuil , linux-media@vger.kernel.org, Ricardo Ribalda , linux-kernel@vger.kernel.org, Hans Verkuil X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=12904; i=ribalda@chromium.org; h=from:subject:message-id; bh=CQ0Q3iEnjgF/RdatrIffgvHt8KgiNN9Adkhd3ymwRxg=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjijQsHCyx0OPBe0KIY2MAlct06a6Z8vNSFlgl59Ra dYmEr3CJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY4o0LAAKCRDRN9E+zzrEiLsDEA CbR5VB6GomNQ5k9uB94p/hQJV0SIQWBUa1L1ZtyRc0ovxw0Baysc6YVnr/xgxS7zexj467+n+mEHXB ppsw/DtQnuiJa/vv4/XcCYbwTG0kM/KiS5vTLznCfHnToC/DLQTQvytS+s70W8fv6cy8KwGOOtVUAg 4HwFFbT2DT1RKEs87bqcBOZtBPKHM+913oSyL8iPB3/663JNjJFhVtjTOD1EPuupo92WfcTUT5Jeno U66lZpxDDF1AElyCvOTeoBW3/FsE6i17nNLGGzuk96+0NhyKvvFmmBY2p8K8BhX5v/7lsISQze3kfR JdqNgcUcQ9a6ruuuUdVOPPEQPsnhcb04xB094umEdomMsa+FiD6ELNnnQ+CDhKcSGIH+Nkv2LIJGbo 60tCcPqk5K5LmUmqOAFov5EJUW6fO0DIHIjQ3xgccJhb57+c3yz1+rycQNueAGvQD32EdQqb0SVVFI ZsLOqP5i1ZBju9p79IeytwsmP+sBZBtp33Dr2vNz4v9Y3eDK9DyYiMWx8j8xmI6cHsvtIET54rzBYH Rxbx49rc74D9Mbro2Bakfb1sHri+/WveUWyZopShstgiwCTxS11WoKLBNKX9HgwdcumFu66bJMzPYU 4Y/EFhHF9Cx0Wcpvht5clDthsQuavOLQi9B4dmYM3rxkYzPRt5X44KNJJh5A== X-Developer-Key: i=ribalda@chromium.org; a=openpgp; fpr=9EC3BB66E2FC129A6F90B39556A0D81F9F782DA9 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751124030384547504?= X-GMAIL-MSGID: =?utf-8?q?1751124030384547504?= Instead of duplicating the menu info, use the one from the core. Also, do not use extra memory for 1:1 mappings. Signed-off-by: Ricardo Ribalda Suggested-by: Laurent Pinchart --- drivers/media/usb/uvc/uvc_ctrl.c | 116 +++++++++++++++++++++++++------------ drivers/media/usb/uvc/uvc_driver.c | 9 +-- drivers/media/usb/uvc/uvc_v4l2.c | 81 ++++++++++++++++++++------ drivers/media/usb/uvc/uvcvideo.h | 3 +- include/uapi/linux/uvcvideo.h | 3 +- 5 files changed, 146 insertions(+), 66 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index df273b829961..5c28d8aace37 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -363,19 +363,31 @@ static const u32 uvc_control_classes[] = { V4L2_CID_USER_CLASS, }; -static const struct uvc_menu_info power_line_frequency_controls[] = { - { 0, "Disabled" }, - { 1, "50 Hz" }, - { 2, "60 Hz" }, - { 3, "Auto" }, -}; +static const int exposure_auto_mapping[] = { 2, 1, 4, 8 }; -static const struct uvc_menu_info exposure_auto_controls[] = { - { 2, "Auto Mode" }, - { 1, "Manual Mode" }, - { 4, "Shutter Priority Mode" }, - { 8, "Aperture Priority Mode" }, -}; +static u32 uvc_mapping_get_menu_value(struct uvc_control_mapping *mapping, + u32 idx) +{ + if (!test_bit(idx, &mapping->menu_mask)) + return 0; + + if (mapping->menu_mapping) + return mapping->menu_mapping[idx]; + + return idx; +} + +static const char +*uvc_mapping_get_menu_name(struct uvc_control_mapping *mapping, u32 idx) +{ + if (!test_bit(idx, &mapping->menu_mask)) + return NULL; + + if (mapping->menu_names) + return mapping->menu_names[idx]; + + return v4l2_ctrl_get_menu(mapping->id)[idx]; +} static s32 uvc_ctrl_get_zoom(struct uvc_control_mapping *mapping, u8 query, const u8 *data) @@ -524,8 +536,8 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { .offset = 0, .v4l2_type = V4L2_CTRL_TYPE_MENU, .data_type = UVC_CTRL_DATA_TYPE_BITMASK, - .menu_info = exposure_auto_controls, - .menu_mask = BIT_MASK(ARRAY_SIZE(exposure_auto_controls)), + .menu_mapping = exposure_auto_mapping, + .menu_mask = GENMASK(ARRAY_SIZE(exposure_auto_mapping) - 1, 0), .slave_ids = { V4L2_CID_EXPOSURE_ABSOLUTE, }, }, { @@ -730,8 +742,7 @@ static const struct uvc_control_mapping uvc_ctrl_mappings_uvc11[] = { .offset = 0, .v4l2_type = V4L2_CTRL_TYPE_MENU, .data_type = UVC_CTRL_DATA_TYPE_ENUM, - .menu_info = power_line_frequency_controls, - .menu_mask = BIT_MASK(ARRAY_SIZE(power_line_frequency_controls) - 1), + .menu_mask = GENMASK(V4L2_CID_POWER_LINE_FREQUENCY_60HZ, 0), }, }; @@ -744,8 +755,7 @@ static const struct uvc_control_mapping uvc_ctrl_mappings_uvc15[] = { .offset = 0, .v4l2_type = V4L2_CTRL_TYPE_MENU, .data_type = UVC_CTRL_DATA_TYPE_ENUM, - .menu_info = power_line_frequency_controls, - .menu_mask = BIT_MASK(ARRAY_SIZE(power_line_frequency_controls)), + .menu_mask = GENMASK(V4L2_CID_POWER_LINE_FREQUENCY_AUTO, 0), }, }; @@ -972,13 +982,17 @@ static s32 __uvc_ctrl_get_value(struct uvc_control_mapping *mapping, s32 value = mapping->get(mapping, UVC_GET_CUR, data); if (mapping->v4l2_type == V4L2_CTRL_TYPE_MENU) { - const struct uvc_menu_info *menu = mapping->menu_info; unsigned int i; - for (i = 0; BIT(i) <= mapping->menu_mask; ++i, ++menu) { + for (i = 0; BIT(i) <= mapping->menu_mask; ++i) { + u32 menu_value; + if (!test_bit(i, &mapping->menu_mask)) continue; - if (menu->value == value) { + + menu_value = uvc_mapping_get_menu_value(mapping, i); + + if (menu_value == value) { value = i; break; } @@ -1174,7 +1188,6 @@ static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, { struct uvc_control_mapping *master_map = NULL; struct uvc_control *master_ctrl = NULL; - const struct uvc_menu_info *menu; unsigned int i; memset(v4l2_ctrl, 0, sizeof(*v4l2_ctrl)); @@ -1219,11 +1232,15 @@ static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, v4l2_ctrl->maximum = fls(mapping->menu_mask) - 1; v4l2_ctrl->step = 1; - menu = mapping->menu_info; - for (i = 0; BIT(i) <= mapping->menu_mask; ++i, ++menu) { + for (i = 0; BIT(i) <= mapping->menu_mask; ++i) { + u32 menu_value; + if (!test_bit(i, &mapping->menu_mask)) continue; - if (menu->value == v4l2_ctrl->default_value) { + + menu_value = uvc_mapping_get_menu_value(mapping, i); + + if (menu_value == v4l2_ctrl->default_value) { v4l2_ctrl->default_value = i; break; } @@ -1322,11 +1339,11 @@ int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, int uvc_query_v4l2_menu(struct uvc_video_chain *chain, struct v4l2_querymenu *query_menu) { - const struct uvc_menu_info *menu_info; struct uvc_control_mapping *mapping; struct uvc_control *ctrl; u32 index = query_menu->index; u32 id = query_menu->id; + const char *name; int ret; memset(query_menu, 0, sizeof(*query_menu)); @@ -1348,22 +1365,28 @@ int uvc_query_v4l2_menu(struct uvc_video_chain *chain, goto done; } - menu_info = &mapping->menu_info[query_menu->index]; - if (mapping->data_type == UVC_CTRL_DATA_TYPE_BITMASK) { + u32 menu_value; + if (!ctrl->cached) { ret = uvc_ctrl_populate_cache(chain, ctrl); if (ret < 0) goto done; } - if (!(uvc_get_ctrl_bitmap(ctrl, mapping) & menu_info->value)) { + menu_value = uvc_mapping_get_menu_value(mapping, + query_menu->index); + if (!(uvc_get_ctrl_bitmap(ctrl, mapping) & menu_value)) { ret = -EINVAL; goto done; } } - strscpy(query_menu->name, menu_info->name, sizeof(query_menu->name)); + name = uvc_mapping_get_menu_name(mapping, query_menu->index); + if (name) + strscpy(query_menu->name, name, sizeof(query_menu->name)); + else + ret = -EINVAL; done: mutex_unlock(&chain->ctrl_mutex); @@ -1865,7 +1888,7 @@ int uvc_ctrl_set(struct uvc_fh *handle, if (!test_bit(xctrl->value, &mapping->menu_mask)) return -EINVAL; - value = mapping->menu_info[xctrl->value].value; + value = uvc_mapping_get_menu_value(mapping, xctrl->value); /* * Valid menu indices are reported by the GET_RES request for @@ -2311,12 +2334,28 @@ static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, INIT_LIST_HEAD(&map->ev_subs); - size = sizeof(*mapping->menu_info) * fls(mapping->menu_mask); - map->menu_info = kmemdup(mapping->menu_info, size, GFP_KERNEL); - if (map->menu_info == NULL) { - kfree(map->name); - kfree(map); - return -ENOMEM; + if (mapping->menu_mapping && mapping->menu_mask) { + size = sizeof(mapping->menu_mapping[0]) * + fls(mapping->menu_mask); + map->menu_mapping = kmemdup(mapping->menu_mapping, size, + GFP_KERNEL); + if (!map->menu_mapping) { + kfree(map->name); + kfree(map); + return -ENOMEM; + } + } + if (mapping->menu_names && mapping->menu_mask) { + size = sizeof(mapping->menu_names[0]) * + fls(mapping->menu_mask); + map->menu_names = kmemdup(mapping->menu_names, size, + GFP_KERNEL); + if (!map->menu_names) { + kfree(map->menu_mapping); + kfree(map->name); + kfree(map); + return -ENOMEM; + } } if (map->get == NULL) @@ -2661,7 +2700,8 @@ static void uvc_ctrl_cleanup_mappings(struct uvc_device *dev, list_for_each_entry_safe(mapping, nm, &ctrl->info.mappings, list) { list_del(&mapping->list); - kfree(mapping->menu_info); + kfree(mapping->menu_names); + kfree(mapping->menu_mapping); kfree(mapping->name); kfree(mapping); } diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index abdb9ca7eed6..97c267e75fa4 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -2661,11 +2661,6 @@ MODULE_PARM_DESC(timeout, "Streaming control requests timeout"); * Driver initialization and cleanup */ -static const struct uvc_menu_info power_line_frequency_controls_limited[] = { - { 1, "50 Hz" }, - { 2, "60 Hz" }, -}; - static const struct uvc_control_mapping uvc_ctrl_power_line_mapping_limited = { .id = V4L2_CID_POWER_LINE_FREQUENCY, .entity = UVC_GUID_UVC_PROCESSING, @@ -2674,8 +2669,8 @@ static const struct uvc_control_mapping uvc_ctrl_power_line_mapping_limited = { .offset = 0, .v4l2_type = V4L2_CTRL_TYPE_MENU, .data_type = UVC_CTRL_DATA_TYPE_ENUM, - .menu_info = power_line_frequency_controls_limited, - .menu_mask = BIT_MASK(ARRAY_SIZE(power_line_frequency_controls_limited)), + .menu_mask = GENMASK(V4L2_CID_POWER_LINE_FREQUENCY_60HZ, + V4L2_CID_POWER_LINE_FREQUENCY_50HZ), }; static const struct uvc_device_info uvc_ctrl_power_line_limited = { diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c index e6792fd46bf5..89581c1559df 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -25,6 +25,64 @@ #include "uvcvideo.h" +static int uvc_control_xu_2_mapping(struct uvc_control_mapping *map, + struct uvc_xu_control_mapping *xmap) +{ + char (*names)[UVC_MENU_NAME_LEN]; + unsigned int i; + u32 *mapping; + size_t size; + + /* Prevent excessive memory consumption, as well as integer + * overflows. + */ + if (xmap->menu_count == 0 || + xmap->menu_count > UVC_MAX_CONTROL_MENU_ENTRIES) + return -EINVAL; + + map->menu_mask = BIT_MASK(xmap->menu_count); + + size = xmap->menu_count * sizeof(*map->menu_mapping); + mapping = kzalloc(size, GFP_KERNEL); + if (!mapping) + return -ENOMEM; + + for (i = 0; i < xmap->menu_count ; i++) + if (copy_from_user(&mapping[i], &xmap->menu_info[i].value, + sizeof(mapping[i]))) { + kfree(mapping); + return -ENOMEM; + } + + map->menu_mapping = mapping; + + /* + * Always use the standard naming if available. + */ + if (v4l2_ctrl_get_menu(map->id)) + return 0; + + size = xmap->menu_count * sizeof(map->menu_names[0]); + names = kzalloc(size, GFP_KERNEL); + if (!names) { + kfree(mapping); + return -ENOMEM; + } + + for (i = 0; i < xmap->menu_count ; i++) { + /* sizeof(names[i]) - 1: to take care of \0 */ + if (copy_from_user(&names[i], &xmap->menu_info[i].name, + sizeof(names[i]) - 1)) { + kfree(names); + kfree(mapping); + return -ENOMEM; + } + } + map->menu_names = names; + + return 0; +} + /* ------------------------------------------------------------------------ * UVC ioctls */ @@ -32,7 +90,6 @@ static int uvc_ioctl_ctrl_map(struct uvc_video_chain *chain, struct uvc_xu_control_mapping *xmap) { struct uvc_control_mapping *map; - unsigned int size; int ret; map = kzalloc(sizeof(*map), GFP_KERNEL); @@ -63,24 +120,9 @@ static int uvc_ioctl_ctrl_map(struct uvc_video_chain *chain, break; case V4L2_CTRL_TYPE_MENU: - /* - * Prevent excessive memory consumption, as well as integer - * overflows. - */ - if (xmap->menu_count == 0 || - xmap->menu_count > UVC_MAX_CONTROL_MENU_ENTRIES) { - ret = -EINVAL; - goto free_map; - } - - size = xmap->menu_count * sizeof(*map->menu_info); - map->menu_info = memdup_user(xmap->menu_info, size); - if (IS_ERR(map->menu_info)) { - ret = PTR_ERR(map->menu_info); + ret = uvc_control_xu_2_mapping(map, xmap); + if (ret) goto free_map; - } - - map->menu_mask = BIT_MASK(xmap->menu_count); break; default: @@ -92,7 +134,8 @@ static int uvc_ioctl_ctrl_map(struct uvc_video_chain *chain, ret = uvc_ctrl_add_mapping(chain, map); - kfree(map->menu_info); + kfree(map->menu_names); + kfree(map->menu_mapping); free_map: kfree(map); diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index 7e2339fc256e..8ebd7ee2934d 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -254,7 +254,8 @@ struct uvc_control_mapping { enum v4l2_ctrl_type v4l2_type; u32 data_type; - const struct uvc_menu_info *menu_info; + const u32 *menu_mapping; + const char (*menu_names)[UVC_MENU_NAME_LEN]; unsigned long menu_mask; u32 master_id; diff --git a/include/uapi/linux/uvcvideo.h b/include/uapi/linux/uvcvideo.h index 8288137387c0..1b64b6aa40b5 100644 --- a/include/uapi/linux/uvcvideo.h +++ b/include/uapi/linux/uvcvideo.h @@ -36,9 +36,10 @@ UVC_CTRL_FLAG_GET_MAX | UVC_CTRL_FLAG_GET_RES | \ UVC_CTRL_FLAG_GET_DEF) +#define UVC_MENU_NAME_LEN 32 struct uvc_menu_info { __u32 value; - __u8 name[32]; + __u8 name[UVC_MENU_NAME_LEN]; }; struct uvc_xu_control_mapping {