From patchwork Tue Jan 3 14:36:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 38466 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp4654080wrt; Tue, 3 Jan 2023 06:42:26 -0800 (PST) X-Google-Smtp-Source: AMrXdXvm2bDfSqDFAjSuAYbIhJcb7ru1uR6nrWCLA7O4cvGeooyJLCT3UKMFkgqumfsw0p5wOsk6 X-Received: by 2002:a17:90a:7404:b0:219:a8e5:79f5 with SMTP id a4-20020a17090a740400b00219a8e579f5mr48256257pjg.43.1672756945826; Tue, 03 Jan 2023 06:42:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672756945; cv=none; d=google.com; s=arc-20160816; b=uttJGyTBqsIrLo5Fju33B6xcklGOSqW6ld3qv7TjqwrPti22CaI7KyM2n7DhqTMC06 drqqblt8NOvbJ8V70LafeHm7yvngkUBVEZQRIJX1Blr/Jt/qFH6Yx9QLa80d+lQ5ALI8 8zKR1WdeVorFtXGC4wFATn3IHBB3aQ+/jzOFXpIKhVO44b779DKtX5HjhhxajZ8xAsiD 8aYbuCjarrKPTxZgi0PW7L9hadpt2VqcpbxqbGLvxHLWEQV9fVM6ntFYBCC1egYYfjx/ eYKHofeDf6Q794SFnRFkeKgwQ0DeZrw6c4Pd29j+hodrwAxA6zIXyRVk3hLMtFvlzODW y+PQ== 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=o4vpRNrVLZpZlxsGBTMbyBeXBdw1nBEF/02PDPHH1do=; b=0+zMhK2go59drMM0vw4EXtnUXi63LlQk6Z/yQITcCTIhRv6nBfNWGrqbol8MMTx/Y5 mm7dQP978VYsOC4yyWZ7P4hwVoPYR6W+dm59pQUNovAoaujQOEvyCgEL7a6B8tiuJbEq /ppoYhHxTaW9bCzZlVYxs6EVtXvFSGxOmEpFkYVgx6TELGVzLTmKHo2Mq3YrYJCtZKpc 5+vAecRBefjw427dyguH+KU+rkEj9pUc9nHYldncfGwsbN/e9AmX2zJMiZuEMOT5+Ny1 X8EvuUjgC54zg7y5E3ixwJ0H4NB0Me8UCdvkz23e/VbfXKVsTcr8F8H1+i6kbS1M1qVB ghQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=l8jI+U5c; 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 b13-20020a17090acc0d00b00225ca23faddsi29182644pju.54.2023.01.03.06.42.12; Tue, 03 Jan 2023 06:42:25 -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=l8jI+U5c; 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 S238013AbjACOhK (ORCPT + 99 others); Tue, 3 Jan 2023 09:37:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233410AbjACOgq (ORCPT ); Tue, 3 Jan 2023 09:36:46 -0500 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 960D710073 for ; Tue, 3 Jan 2023 06:36:45 -0800 (PST) Received: by mail-ed1-x52a.google.com with SMTP id i9so44030785edj.4 for ; Tue, 03 Jan 2023 06:36:45 -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=o4vpRNrVLZpZlxsGBTMbyBeXBdw1nBEF/02PDPHH1do=; b=l8jI+U5cGLKMQzvUJ7CDE/jILdc2xdTMT5aBtvmitfIQDJn4IZpTAEaBgicAJE0GAf dzwGH3enfaBAG0rMmtn7ncIEvIgS7XFp0iOIeucSiVLP0XnTniVHLic7gNYysZG5ubYG UDp4PMmjFHDxKIBk8967pAPnQC86sO2M/h3qs= 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=o4vpRNrVLZpZlxsGBTMbyBeXBdw1nBEF/02PDPHH1do=; b=rM4aara0WHXsz31NBrG0rhTw6TQFqgWnr2qORhI3ktPPrJUpBXut2qcATi6A5Scuou xKHpye6hJlH3WTyl12006wwp6B5WYooW0GkajYRERvhr0QT60X/qCCvQQGzKoj3lmNJe FTBeyYZD1NjnWpdxQ8vcdVHs7af1tDTJduOXdA6r6yPQzDPYZou/dK/PAIMf7+vwI5UN 2TMyE0hSo11hM8HlFSkWz4gZHH2nPY3V+M1n9nHJngXbvIuOaKblWX39viDIdtkyaK9z gShZBRKAQuhNsxfjYEk3xLpMSLg1rC31n7tQToBt8A00cu+oNoTnGXBylPL/H5oP4cVb 3k2Q== X-Gm-Message-State: AFqh2kqnaxWVfMtdbyRsS5STbkNOQO4+29SqpCZdgcWYqWOY6QlqHC+x X++chNHKiRAg4SWS+WCOH3T4Qg== X-Received: by 2002:aa7:ccc2:0:b0:462:2e05:30ce with SMTP id y2-20020aa7ccc2000000b004622e0530cemr36951539edt.42.1672756604172; Tue, 03 Jan 2023 06:36:44 -0800 (PST) Received: from alco.roam.corp.google.com ([2620:0:1059:10:9789:8e2b:74ac:a9a0]) by smtp.gmail.com with ESMTPSA id p14-20020a05640243ce00b0048ebf8a5736sm877245edc.21.2023.01.03.06.36.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Jan 2023 06:36:43 -0800 (PST) From: Ricardo Ribalda Date: Tue, 03 Jan 2023 15:36:19 +0100 Subject: [PATCH v3 1/8] media: uvcvideo: Check for INACTIVE in uvc_ctrl_is_accessible() MIME-Version: 1.0 Message-Id: <20220920-resend-v4l2-compliance-v3-1-598d33a15815@chromium.org> References: <20220920-resend-v4l2-compliance-v3-0-598d33a15815@chromium.org> In-Reply-To: <20220920-resend-v4l2-compliance-v3-0-598d33a15815@chromium.org> To: Mauro Carvalho Chehab , Laurent Pinchart Cc: Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda , Hans Verkuil , Hans Verkuil X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=5160; i=ribalda@chromium.org; h=from:subject:message-id; bh=23T/fd3YJJF1E+YgFkf8Ajmygtju9PWip1iEAdc/iJ8=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjtD1rNhhtvAFQKumGKX90/lQE4tOQjtbvjf17JOJ7 YhxxAf6JAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY7Q9awAKCRDRN9E+zzrEiH5cEA CaIlgVgUj3T8Q8M89phJlkwOypRrMetwVm+FDAFOiRfZi6ZCvYzAsgEuBuzT5ZxDumi14MCjYl2zNY aJWFYSbXI+eTs+ifDsZvrO0BrTTYbG0/PHokN5wiPoRsdaYkGtvkIc6kHWwWeFCUQVS0dolcEeFmrI 5IUK9rUTh8g/HGKqVrIZElxTlbdsZfkCEG2HCHs2c+XQagq0m40jPUMGNkWHD2g9a1Pg1YxG/kcynv atKV1QBiXuDrwTyez6KWH5QuDti0tVFLozaRbLHeLQDT+QyLPDtyPjKUCkPCG5fWTx2mguASoFC2i4 hpj7qbGXt7pobUBSm7+Qwl5WGXYU/WaCliRxJFj9I6mWCSUEXblLNxJjWS2Tdoah+rr9+2oPL0VlqA 28Zr4xUJYA603tTIyuU4H2oEXjbwfsZ65OS0MpVC8yTJ0IfWnVyPNNCOc0YNFeinPLRYruSQQaAcS4 V/pY9PuAtNXBkzMklvVDU0inT7nc6PDOmmlzRRI9ozZRysJwMmMroSaRwDHk/P4ySpYcONNankGt3B O4UDa3UNdeJ2SOvkPWMckVLjtaXSr1UWnlJ/0LM7PzMbXEtIV72WxZquEEF1YOmp+iV4COhbaxpPt5 64PEc/+nPuSi5HCGnAAA6aipoXBjgJrajsz1qOXxlZvbG9qO98hM8QpW/4OQ== 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?1754012786839859761?= X-GMAIL-MSGID: =?utf-8?q?1754012786839859761?= 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: Laurent Pinchart Reviewed-by: Ricardo Ribalda Signed-off-by: Hans Verkuil --- drivers/media/usb/uvc/uvc_ctrl.c | 42 +++++++++++++++++++++++++++++++++++++++- drivers/media/usb/uvc/uvc_v4l2.c | 3 +-- drivers/media/usb/uvc/uvcvideo.h | 3 ++- 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index c95a2229f4fa..6165d6b8e855 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1085,11 +1085,28 @@ static int uvc_query_v4l2_class(struct uvc_video_chain *chain, u32 req_id, return 0; } +/* + * Check if control @v4l2_id can be accessed by the given control @ioctl + * (VIDIOC_G_EXT_CTRLS, VIDIOC_TRY_EXT_CTRLS or VIDIOC_S_EXT_CTRLS). + * + * For set operations on slave controls, check if the master's value is set to + * manual, either in the others controls set in the same ioctl call, or from + * the master's current value. This catches VIDIOC_S_EXT_CTRLS calls that + * set both the master and slave control, such as for instance setting + * 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; + s32 val; + int ret; + int i; if (__uvc_query_v4l2_class(chain, v4l2_id, 0) >= 0) return -EACCES; @@ -1104,6 +1121,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 (ioctl != VIDIOC_S_EXT_CTRLS || !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 f4d4c33b6dfb..3edb54c086b2 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -1020,8 +1020,7 @@ 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 df93db259312..a151f583cd15 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -761,7 +761,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 Tue Jan 3 14:36:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 38465 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp4653806wrt; Tue, 3 Jan 2023 06:41:48 -0800 (PST) X-Google-Smtp-Source: AMrXdXussn6P7yLr4gy2RvuZ8gmhnhuN58hd/oJCyYQeTjjpSq0FOi8quwrRWsplbiKFqQ/f/91h X-Received: by 2002:a05:6a20:c1a3:b0:af:7a3d:5102 with SMTP id bg35-20020a056a20c1a300b000af7a3d5102mr58373829pzb.62.1672756908503; Tue, 03 Jan 2023 06:41:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672756908; cv=none; d=google.com; s=arc-20160816; b=UhePI+9ZXm8PEDpJMrhPpSZyLb8tJCLVlrYUFCkkWh0fRmfvN4+0CEblnRIhY3frZF JNSHNMcECCJhfXUm0n74xSkhJoNBCREc3e+ggRZFhdkSLT+PYnMuVg33xVyDqryTIWx4 Qz3ESuTw04+JCVbYqny/i/7hb1EvFj1e/t/y1HYzjW7NIx70gDigBK3UxONrv5eZNcUR /ZhDt9vJ/OqOVP/ksVIyQcmjU8KiTp7pZ84M57FyKA6prizpK52xzRM4Koa3CnFmJXvW wUUjTUZtw0BiOAPeL74o3Z29X43u6/JbOD+BZ85iD2GesHgMLqG1QOhOe4lR8PADPvo6 ZxbA== 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=rL6vjumDEZ8bp9EfDhAS6U23Sa8DpoR9rvInW/saadw=; b=L1Y4jzxJZxNtZ8UBOZCpMaqOmk87zrqi+8Em/pupG6MZ8ldCpU2qVyyL0oy3+++VXu cDD/VXjc22RZ8YxMq/P7r5ud10KH7hGWtH3pUBbV5za5BIRmql5hhA93Tf5wFf2Fm0jK 7ffgAA3/WC7xsQwGby03ihM2uOeLTI4LzxT6XU2oJ3XnR/zZu5N9IcgYaBCHDyEpW6IP ibvtsxHEGyxqOQfg6SZOQArhQxTUzw+F1UmPdEM4s0sPwDpUKLzek2vOLCihUG82umu0 bOCQzmBUJK0S38BACvBQsr9vyC2Mix+OvkC90CFk2/BH/sUXnM8pfoQTFTeVQW5HTOGQ QV7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=G2By3BqJ; 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 c22-20020a63d156000000b00477dc113782si31492698pgj.600.2023.01.03.06.41.36; Tue, 03 Jan 2023 06:41:48 -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=G2By3BqJ; 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 S233465AbjACOhG (ORCPT + 99 others); Tue, 3 Jan 2023 09:37:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237290AbjACOgr (ORCPT ); Tue, 3 Jan 2023 09:36:47 -0500 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A430210B70 for ; Tue, 3 Jan 2023 06:36:46 -0800 (PST) Received: by mail-ed1-x52b.google.com with SMTP id i15so44100283edf.2 for ; Tue, 03 Jan 2023 06:36:46 -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=rL6vjumDEZ8bp9EfDhAS6U23Sa8DpoR9rvInW/saadw=; b=G2By3BqJTaOu7tcF/DiJTm7we72oLpjph2rOGNoSu+JD8xr2DkYMcjrUUF9vdGMtea MlzYiKHewd3ACEitRrIqPdDGCY7yjVTgnQ9jjkI7pDAq3NsmTuWr1GoKLnKWWwY8BBtw 22kHIAil8+r17B8kM9KP4j4xw82PnctDUJ9pA= 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=rL6vjumDEZ8bp9EfDhAS6U23Sa8DpoR9rvInW/saadw=; b=GmhiB/DebM4XBTG6eKcs/d2BP1iln2hMl4KNsY00XqOknkjFcURwKzdwQATbZerf0C draL3Ahg00DHi4PF5/4EbdNJ0weU+wV7zEi36ShI7Tdiq4NyPTFVnQgnYDqOWjhDZb6M NGxZSR4nb6CBLQcDUb+BIGTX0061j8wtTbJgFrCIo9+MONeyVzYr7BkpsgGCXSt1RQ9y 3APyCLlXdp4dzUZQGR5R951u3OPG1wy6lw/mC9ve/YRwArGYFAlXvVis3ac9M7bjtmiz n12fbePtrNxhhvpyTc9FVmkKxElFM8Fq6mSlaR/RGUy7CnDMbXq0t55rrWYNRTn8Ibuu q2Ug== X-Gm-Message-State: AFqh2ko32TTEzqyvoY48VjHpmro9iT0SXXoVoU8eO3oGo0mye2JrEAam 8it7x0/3pStfUgzrjG9WeGG8ag== X-Received: by 2002:a50:cc4c:0:b0:463:e2cd:a8b5 with SMTP id n12-20020a50cc4c000000b00463e2cda8b5mr39293162edi.11.1672756605285; Tue, 03 Jan 2023 06:36:45 -0800 (PST) Received: from alco.roam.corp.google.com ([2620:0:1059:10:9789:8e2b:74ac:a9a0]) by smtp.gmail.com with ESMTPSA id p14-20020a05640243ce00b0048ebf8a5736sm877245edc.21.2023.01.03.06.36.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Jan 2023 06:36:44 -0800 (PST) From: Ricardo Ribalda Date: Tue, 03 Jan 2023 15:36:20 +0100 Subject: [PATCH v3 2/8] media: uvcvideo: improve error logging in uvc_query_ctrl() MIME-Version: 1.0 Message-Id: <20220920-resend-v4l2-compliance-v3-2-598d33a15815@chromium.org> References: <20220920-resend-v4l2-compliance-v3-0-598d33a15815@chromium.org> In-Reply-To: <20220920-resend-v4l2-compliance-v3-0-598d33a15815@chromium.org> To: Mauro Carvalho Chehab , Laurent Pinchart Cc: Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda , Hans Verkuil , Hans Verkuil X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=1481; i=ribalda@chromium.org; h=from:subject:message-id; bh=xOoehc4vwLA0iipvzwLxfRoUl2KbfEEdDxl6zHy2Huk=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjtD1uUt2X//JNsQhBiFozEJj3L0qZd4uDB5oeAeJE GHvpzAaJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY7Q9bgAKCRDRN9E+zzrEiIvdD/ 9KuCrPeHfK/M/hRHQYcLzHTK8be+wwTwYRSKkanRDWf0KHAK5MM6zVmT5hriYH0w3YqxzeeHKaIIDd j1dQFL4sAMUqRD3GdBx24cAX/8qC+5vp3bS73dMCCbUcMFpS7/M6nBPomAgyCIH1aWr9wSctQJUSf4 9d8evKsYnfknwWBOECRm81z7mFaegh42WjAlWu2jMbNZIcBRUsjSNL0LANTmbhppLhA+ZH9FM07br8 Rc/pK4V0ep5yaH2noRepY/hy1HgGwD/Jtc4I9Frn4jdPlKhoIQSLcHidf++AEBt6jPkQlxyS+FQu3H UJeZVUhbUOReB/JNNyOjATS03KvlfmYvhSBM4FAOVH+70gnYpRXCMpgOu3SNFfH/xPAPAUG05Zo71I 21xh3S9K7J+f1fVvpwcL96kLpgP9V7F3axwK7gGvjHHVIuX45vA4mWkA4Hz8G4p+veRNDLoCZZd+k/ qS5dK7hzhc9djVwq2bGXNpJ4yZ/K9r06KM4p/h9l+S/sNuPlHDexcN3n0Q5ZrAMbHyl22gaNn0OHTP IYfCDOoaoTSmZqlYQyzpButmheKxlcvzHjBou4K5SSFyrq/yeHTMQ9TkZDde4lTLzJLKlGQ6KtS76O RRxFuWoNuaohxgmgUePIsytf8tpmXzESQauylOQA5ibkSt0XMxJrLxOyQ/eQ== 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?1754012747888402305?= X-GMAIL-MSGID: =?utf-8?q?1754012747888402305?= From: Hans Verkuil Standard use of the driver may result in error messages on the kernel ring buffer. This can hide other more important messages, and alert unnecessarily the user. Let's keep dev_err() for the important occasions. 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 Reviewed-by: Laurent Pinchart --- 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 d2eb9066e4dc..6b20a23bc3cf 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 Tue Jan 3 14:36:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 38472 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp4654942wrt; Tue, 3 Jan 2023 06:44:21 -0800 (PST) X-Google-Smtp-Source: AMrXdXv/2qcG6XQHAmzd3EyeZU66tk9RQXMdjYdx7KKj/ZbZPvHqXY/vkIuQVtR3/Rr2aK835uCu X-Received: by 2002:a62:1704:0:b0:581:e3db:3b56 with SMTP id 4-20020a621704000000b00581e3db3b56mr16952433pfx.32.1672757061105; Tue, 03 Jan 2023 06:44:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672757061; cv=none; d=google.com; s=arc-20160816; b=oNrpvaNPUyUsU5oJ5A9h7PFbITtOU/ddqqGafKBADI8xvWjvNbOqLuugZ7ZAyVz2Lo /7ji5hhruwubhk3FiYpHR+rGycSppbCRmfTNMbfiERgkc6Cus24HVlJrdOoySrmjdYHF l99hxh/ifQ7ZvA77g+GO91oFvzxPKwCoiqIFyaasFxGUjvyefNZD1LeHdl35BovZc7Q2 MQ++FN8kFWGf5Rw+TbfKShZVMqYRlifTcixXA6OYZXm2VTg+NMA61zXOQJh3OwI+LCHN TizWnn+1epKtHA14xw0B7JzABYzB+wAmwXN3Tlhtlibl2wbpQQJ9nOy1Rz+6ty3KEBhP tK4Q== 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=qJf+h2f2R0607iPBKTi3aOdsbu1qoQNWuR3plbe+zVU=; b=pmrSfOM82hCabj5jj4wFWWDn4BTY7QpP+EkfeICVAlGjz4mufVAntwjM1Bqxz87vAj nxEqxnNPYR++AS1E+NeiDL7nNh3Aw/TqjorlI5pwjC6jL7QfLLIqBEe9jS16K5Kylk2S yYVEB/NZqsnojxfzszVj6Fc4CBzdu1V3ZAUgJDqhsDPAQCyA0XgZiaKovZ3/bv6HDsFc TKPpOGBK2W1UX1ZM6F+2yZBr8V/fdvOZ5JBGWTkicfsLbCCq9Pt4Mto3PM+rDsY2FI8h y1zDuTgQz2WxwRamgW3eMdDPwYvUR5/07urjpCLSeWvU5bwkzLoygDs/x4HqF2TviG6D GzyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=DORFtksW; 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 o3-20020a056a001bc300b005816eb19ee2si20103003pfw.162.2023.01.03.06.44.09; Tue, 03 Jan 2023 06:44:21 -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=DORFtksW; 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 S233541AbjACOhY (ORCPT + 99 others); Tue, 3 Jan 2023 09:37:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237817AbjACOgs (ORCPT ); Tue, 3 Jan 2023 09:36:48 -0500 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86B7E1146B for ; Tue, 3 Jan 2023 06:36:47 -0800 (PST) Received: by mail-ed1-x52d.google.com with SMTP id i9so44030934edj.4 for ; Tue, 03 Jan 2023 06:36:47 -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=qJf+h2f2R0607iPBKTi3aOdsbu1qoQNWuR3plbe+zVU=; b=DORFtksWSOAqwT83xzT791DCgSBLtY4QkVrt8RDWSezJ0Zzr3fxsYJjXA8m5j8JzSx D7fUA+MI4PnroF7PXK2faRne8PvsK8CqZxfi8AKDe6AqMe5FPpK6/8D3I7vMBSZYQpUJ EAT/1RabDaErRpWq/ydEfXK54MtXH/ianXzgc= 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=qJf+h2f2R0607iPBKTi3aOdsbu1qoQNWuR3plbe+zVU=; b=aaBG+9U+MdUGalQdLiG+d5Qwkcd7meUrgY2Oju703XIerzt6MZcUn0L0Z4MqF5rTvj pnio8MhaScZpfe7Td2ps8VHDG/D3cK+GyaF/eScSgw4/3n5eEcE7bJXkNFk7rGREBXm5 NgRIVFJaGIlJ54h1mXy+4NX9l7VIf/dlqMJ5edFkKqdFSTbT+UAUZ8jSeO+Sor7I3kj1 5dI2ehYGA5hXbsKyN0G/nVVYNuUm5ZEGFArKdBQQk0k7EUNloe1TVOA8IyWrW/b2vOOD vVk0dWhU+zGklqixD9MWwoqa+l9DK7su/lIQ0UKka3QEfMn6b2j0mRig+Bjc4izrjnbI RGqQ== X-Gm-Message-State: AFqh2kpqQcyZPzh1mjOTMdcI/vlB2v1sZBNqdw42/KCuKEL+zGvyDUVu dA2dp5fJiKF8dQ0fbOyE7Jc/XA== X-Received: by 2002:a05:6402:14d6:b0:479:6bf2:a9bb with SMTP id f22-20020a05640214d600b004796bf2a9bbmr35770781edx.15.1672756606094; Tue, 03 Jan 2023 06:36:46 -0800 (PST) Received: from alco.roam.corp.google.com ([2620:0:1059:10:9789:8e2b:74ac:a9a0]) by smtp.gmail.com with ESMTPSA id p14-20020a05640243ce00b0048ebf8a5736sm877245edc.21.2023.01.03.06.36.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Jan 2023 06:36:45 -0800 (PST) From: Ricardo Ribalda Date: Tue, 03 Jan 2023 15:36:21 +0100 Subject: [PATCH v3 3/8] media: uvcvideo: Return -EACCES for Wrong state error MIME-Version: 1.0 Message-Id: <20220920-resend-v4l2-compliance-v3-3-598d33a15815@chromium.org> References: <20220920-resend-v4l2-compliance-v3-0-598d33a15815@chromium.org> In-Reply-To: <20220920-resend-v4l2-compliance-v3-0-598d33a15815@chromium.org> To: Mauro Carvalho Chehab , Laurent Pinchart Cc: Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda , Hans Verkuil , Hans Verkuil X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=1494; i=ribalda@chromium.org; h=from:subject:message-id; bh=sEdvpc4Bk0VAM3TYxG5czBefJfH6Gr4ihACOSTYlAUo=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjtD1vAXIWeI4gUm0GA0hIn8dST/3ChZRkz+xJCg47 FeLEYjGJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY7Q9bwAKCRDRN9E+zzrEiGS0D/ 4hVkfk3RSkYUUFd1IJWWUGPZbi+dKG41xyvSqchdNJcO2eHDgfpa5JXTQDnPIxg+OkW/wV7q4eE5kf xsGSHI7nSs5ZY7aYxgisLTea27DJrhAqCqRKDVX/oXucirOFyOHUwGNijn6YlIjW0v72rxWWfjB00b kJJr0dNLrFmnchDcTIH54rb+1qNTrzrqceCNMezZ0OjNak90RHchQtnizV8oi5OMNHlt274fjwMOhd 4lZwz33wVOFopez5y8qlUE5EukTYzd9vFeuBGWoK8No9P0Y27oKWB6VcmFIc2BAt+31SmA9HmlShwR 4w2QNOR80PzrQbBl4gNoFF6ddEYf6eBXuyQGYjf5TSRkCCRIJGVV+hf1a34/XAVszMUkKu5FZKKRjt eiD7g74cXIHyIvFHd9eOroN5l+WLdS/W5x7ETRUQWwE2hYyo9iyJ91Sj3v3eD/QRC033A8fZGn2qx8 cTDdI/754jIuYXP4Q+FQm0xuwFHUMptUzGB1qwJUFO5X/hHy7JPHJ5QkyXjo9w4Tr2/SYfnl3bXLwG d+T1IqsyQaU4ftJrWDG6I56sfhUGq/H+iUWvA62flRzfXTmdmDt6HiWg1t1jEy8VTXFF7mZ6JMduu9 DVHLBP7lDdEOJ1XcArye038zZkIAsPGZUmkeDdfFgPnl0LBWv3W1X6QWFoPw== 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?1754012907677972950?= X-GMAIL-MSGID: =?utf-8?q?1754012907677972950?= Error 2 is defined by UVC as: Wrong State: The device is in a state that disallows the specific request. The device will remain in this state until a specific action from the host or the user is completed. This is documented as happening when attempting to set the value of a manual control when the device is in auto mode. While V4L2 allows this, the closest error code defined by VIDIOC_S_CTRL is indeed EACCES: EACCES: Attempt to set a read-only control or to get a write-only control. Or if there is an attempt to set an inactive control and the driver is not capable of caching the new value until the control is active again. Replace EILSEQ with EACCES. Reviewed-by: Laurent Pinchart Suggested-by: Hans Verkuil Signed-off-by: Ricardo Ribalda --- 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 6b20a23bc3cf..e56ccde9bd10 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 Tue Jan 3 14:36:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 38467 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp4654419wrt; Tue, 3 Jan 2023 06:43:16 -0800 (PST) X-Google-Smtp-Source: AMrXdXvz88poa1vCE6ocloWFCPpDqeIMq648PgE2xy9U9LEBO0AxKXl8h53BN6Ad/b27jU+M9ljf X-Received: by 2002:a17:902:7404:b0:189:b0fe:d70f with SMTP id g4-20020a170902740400b00189b0fed70fmr46142187pll.60.1672756995447; Tue, 03 Jan 2023 06:43:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672756995; cv=none; d=google.com; s=arc-20160816; b=OQyKkkP7aEtNhWq9uoedNj4pvM/KQwykRz56Td0kWbw3PCnCVB+y1Pp4IG3bGbnao3 7WTGE/uojsuJjGemNA1TkqtLOYE1IMBJN0mMeEaIw2krERAPouBufNAopTsuyNwmc1Fy KQB9I/TX7v1JN3eOrs7zg1OjwOF2Ur5ndYoRx18bJbNHI7m4Wq1N3vq0oIU9W2ETW9I3 vavgZ0WYkg5ukna4oXzEdvaY+UTQUz589VdmUSYabq3T/USUrXh9gIoD1hxHx1hmYV2W YacDJmkyglrhgQUj8kLdajMuU9iczTtRoGwe3hJMSjUBbro2dqQTx7oShBss1XpxhK/A 8bIQ== 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=YQ39IOVw3moKdkeR5wnNzBJ9M+k6/kqT58GkeY6kRfU=; b=kdE2jqWT30/I/eI924w5v5bDiCcawH8g1qhqMfHCOSTLoh8dj3yncZ476jB66vJO8j 61rs42kBe5lFij1y2B1F98yJMX3hHGWMx5Ttd6d3O1gdZbIIa0qbuN723ewALBVW7CU7 voPP/fmxWB0y9xq1FSV08ZDGdA5cMpGR6hhfYJkoq2iWcueqbo4B8k5O5uVCNiT6EuRf 56JgjDe+GlxuSjBtLfUbafHbLK6d9NK1R3f0QI0vZprQLQBYE8b9RwBeUuGtuK9sTkZS BK0AVPw/XwFD/aYeFdTizvG/twdtrJR/AyUgSB6NcMinOHvnuH9iVqLQILXHgyk9C6pf iBWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="Oyi/FMO8"; 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 34-20020a631662000000b00477c62b9498si33474615pgw.212.2023.01.03.06.43.02; Tue, 03 Jan 2023 06:43:15 -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="Oyi/FMO8"; 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 S238024AbjACOhO (ORCPT + 99 others); Tue, 3 Jan 2023 09:37:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237893AbjACOgt (ORCPT ); Tue, 3 Jan 2023 09:36:49 -0500 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 678A8DF5D for ; Tue, 3 Jan 2023 06:36:48 -0800 (PST) Received: by mail-ed1-x532.google.com with SMTP id r26so38830053edc.5 for ; Tue, 03 Jan 2023 06:36:48 -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=YQ39IOVw3moKdkeR5wnNzBJ9M+k6/kqT58GkeY6kRfU=; b=Oyi/FMO8dPSi+gTq/T0EBXugBrSrsBqfOatsjam/6Lnf16DuB5NfBxE9tnOMaqimBj UK9nffZucqy4W9JpIBLhExMPnyHUM4HSA1dljacVjjyupIHs8I5f3FrrGFlriD2yx8xD m4lWBBtDo0wEVsLe7sRjkl3ZJTHdtUJtvizSM= 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=YQ39IOVw3moKdkeR5wnNzBJ9M+k6/kqT58GkeY6kRfU=; b=NRKqWU4EHxekAHELs89KUrkJllGx7s9ozHYtI8T+stV0Xv0I7LKGr1MADCU7kASVsJ TcinQRAJcXAtY9W2KQqlBvyxiWSUlJD3kODlD9XFCaCODjVOF5POKOWlYf/TPPnfCZhL GrqzThVOYKwaeQ1RsUzUwti98WXpLaW/96A1DDoWaqz4bErXojxO30XrvoWK182A1AJY /gwUeBh4FPcjDUkN6L+oQ/nJmBx8NtojabIAJH0pY9bRZKcvHTlnz/8lJwmZDulVrxJy PeJpwllp6zWPRp0TqydTiPN4j0DF5hgcUqV40TkRLBVLKbMkpn6XT1Rgk/r7jvQO3kcc tqyQ== X-Gm-Message-State: AFqh2kqXQONZ9Iiet9fLXx9wtSzFsmvR7vvlfrWi1z/k6A0y744KSL1c qbduniB8/Xe2j7QzCdy5oWnkLQ== X-Received: by 2002:a05:6402:33a:b0:47d:c06a:c272 with SMTP id q26-20020a056402033a00b0047dc06ac272mr38542370edw.31.1672756606939; Tue, 03 Jan 2023 06:36:46 -0800 (PST) Received: from alco.roam.corp.google.com ([2620:0:1059:10:9789:8e2b:74ac:a9a0]) by smtp.gmail.com with ESMTPSA id p14-20020a05640243ce00b0048ebf8a5736sm877245edc.21.2023.01.03.06.36.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Jan 2023 06:36:46 -0800 (PST) From: Ricardo Ribalda Date: Tue, 03 Jan 2023 15:36:22 +0100 Subject: [PATCH v3 4/8] media: uvcvideo: Do not return positive errors in uvc_query_ctrl() MIME-Version: 1.0 Message-Id: <20220920-resend-v4l2-compliance-v3-4-598d33a15815@chromium.org> References: <20220920-resend-v4l2-compliance-v3-0-598d33a15815@chromium.org> In-Reply-To: <20220920-resend-v4l2-compliance-v3-0-598d33a15815@chromium.org> To: Mauro Carvalho Chehab , Laurent Pinchart Cc: Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda , Hans Verkuil , Hans Verkuil X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=1141; i=ribalda@chromium.org; h=from:subject:message-id; bh=yxgPmvZyTx1x+TY7IUGRFua/vffmv7MJCLBQE3ospZY=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjtD1xyCcB64eeoZqfpJYhCy/YtzURE6aTnDr3+j5L ZOBCoAyJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY7Q9cQAKCRDRN9E+zzrEiMZYD/ 4iuQJXS6BIc4hiZmDS/bNt4SrzIKdPC+Ml0Yr1VjziVZLUtx1b65snPKAYiN0mZcEY7qrRg5vDodY1 E07qSoGd4uTuhgvp+QFOaF0pFqoxQ/uU0+tXy8lVgQOBIZ2Q5/WA/curty4FlrF246K3SSecfhMIiK /n1YWm20+llcbRYIxfEj3oNpsMTHoWkQEDdV6VHGND2otUVSD3oEedRxh6hMgxsO762KyTrdDmc9i6 5Fj0EWWQamFHcXEFKhsPk+G35DxqK79jnFeHw6NML799lUwtIrZrVcKpfwEATKjIVoPwPRxfl1UuWz GiTuaKiQqVGeTzwLG2r+0lMXFNI7HJxoM49E1Y00RU4pBJgZltDgbONttoOkhuts645otbwynyAamu WmqN9JsF8HwEemFYPj9DSrp84ZSUcS1rpO6pCJ6GqudgGCSTyturEoeEcuLllKgYuZgDfSuhy1O8EF safrqQpR3PFAM5rZezwLl/cIWzF3cNRX3mSxOJQqUXtSGFk68m9YpM2ga05TYB4wp8Wf4wN6p4/x6m gfwqIYCQNdfmNGVzS/6C+wkeIfP7Wx+Bjy/w/dgTUOtoXBt+MBl4GXSyQavBs8+q+vnX1v9qoWFgzA s3jKK1OQzjodeq9RHTRmYZ14ggY3FHzgAEG6V1pj57ANN1DoMhRK8yiCri+Q== 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?1754012839149886325?= X-GMAIL-MSGID: =?utf-8?q?1754012839149886325?= 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. This will avoid confusing the caller (and ultimately userspace) that doesn't expect a positive or zero value. Reviewed-by: Laurent Pinchart Suggested-by: Laurent Pinchart Signed-off-by: Ricardo Ribalda --- 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 e56ccde9bd10..feba058fcb06 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 Tue Jan 3 14:36:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 38468 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp4654511wrt; Tue, 3 Jan 2023 06:43:28 -0800 (PST) X-Google-Smtp-Source: AMrXdXsgyunwzgNIqiOBaw2yhIh2sEStlmPlNqFRXkLhwypzKlkOBJhJyTYKg58C41l8CEmEdDMC X-Received: by 2002:a17:902:ef8b:b0:186:6ae1:5ee with SMTP id iz11-20020a170902ef8b00b001866ae105eemr45911417plb.26.1672757008005; Tue, 03 Jan 2023 06:43:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672757007; cv=none; d=google.com; s=arc-20160816; b=0yLPxv3PqSdKC+ek1/EnARUfT0ozRgM33dd9f1mbGYory9TUaN0d8Y9cGkMI+xkjOn KaGppWiY8YrcB20Iq80P2h2r5aOn8PmHHSTkySRVF3q49Jv+dTTNBkzvFcgWt6DzrRHw /PU8L0AgIdVmLvQqgPRTHeAXQK2mNWIwI1opb0m+Ollp/35TxeMYBK7TO2IoofO95D6C 5H5fTIlLqD+7zsWUZO0u2lVQJXV7VnD+3aumaQ0BTy0rqTkss3DrvfI11Nr9xE4JXyUm TklEWrIk69cpun9oN11Ye/JK7uaMq/+UHcJ3D7Nf1nptl1RXju0TPi6J+oavZRC5vlic +NiA== 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=zE/D4J+qsdGyCRspywDzgfmKn2UepOqc9aDMzc7tN+0=; b=CZ9gFn16FhhvDwEaW/wAFAAJHQ//PnEkYVXSKn0pNByxmjHXiHkk4VRMlzvc0bsQQc Q8MawQ7f1IHmp1gw9mm/1AX2znUW1XD3iys7gufv69Dmh6zjhCL3oBFD9i9qJUYE6/jb 8obDT7VgKTQv+/vh7zI/JzatfTLLAR93ullFjnU2nY+bca2r5OSWUrob203j5u3f55kn ipBLOW7Z1ISmJiUv25mVYt9sRuzywC5gsx4PwnS/TyTzZfTQgwmLXEdyO2pZL+4NfchG lzb9aSzoE4KLgoz4yx8Dun5nSHxGlcYwJ2FdtPbwMPV1Bw4u0Q2JONj1oqbBm3b2iKTo 3ioA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=mqOPefvz; 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 w8-20020a63f508000000b00479503041c4si16270013pgh.368.2023.01.03.06.43.16; Tue, 03 Jan 2023 06:43:27 -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=mqOPefvz; 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 S237975AbjACOha (ORCPT + 99 others); Tue, 3 Jan 2023 09:37:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237918AbjACOgu (ORCPT ); Tue, 3 Jan 2023 09:36:50 -0500 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B16F11829 for ; Tue, 3 Jan 2023 06:36:49 -0800 (PST) Received: by mail-ed1-x529.google.com with SMTP id r26so38830120edc.5 for ; Tue, 03 Jan 2023 06:36:49 -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=zE/D4J+qsdGyCRspywDzgfmKn2UepOqc9aDMzc7tN+0=; b=mqOPefvzjudmmghdvjicswADD648taX3TwblKDUjsogqygEgIlBO1pB8qwzrSTKC8k 5MIoQvUrlscfl1H3YSU4HLhcxXN+Jjuejy5uaYJcBvetyGoc9qC247W44l/+9A2//1sC 5f3EOUXM1g6DSQaX7sQPGdBnTorjPN1viVoIg= 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=zE/D4J+qsdGyCRspywDzgfmKn2UepOqc9aDMzc7tN+0=; b=uwu+OcFlURhl8qz9I1Ggd9PdUzIJ2GtFcWe0+SvBKsHvqIBajaQgwx6CRyFMySjxJI k2wHzyPp3GIdBtCLNMGR1ddmIVw3WQ42PfWAuU3douPfDWZIHqXvUwnZHgKTvy/HUrE1 vPqiOVgdV2BhhjD309fIzs1/o7HbFHcnC4byKDVZDnFWHETZreg2F422vbXJeD/4yHnJ /wvr1UWSMMlwCk7vSG8Q02y/JqteHkXTF0q36p2e3McfmQ4BsSqhJf1sTeVs4tfYSPn2 asuA1robRqBRGdcQq1QvcIjhzcMGqiCSDXrPTh8YxjfTZGOhTn227zx70Tano1tzxe/1 mA4Q== X-Gm-Message-State: AFqh2krzPSSM7JHzNTP5hqfNAvJ43nAANbpuP75NAO9pm4G/xtqp3FeJ s9RO3OY9ywnIRc1I2Qlc+cOkCA== X-Received: by 2002:a05:6402:3ce:b0:481:f14d:fda5 with SMTP id t14-20020a05640203ce00b00481f14dfda5mr34418013edw.39.1672756607742; Tue, 03 Jan 2023 06:36:47 -0800 (PST) Received: from alco.roam.corp.google.com ([2620:0:1059:10:9789:8e2b:74ac:a9a0]) by smtp.gmail.com with ESMTPSA id p14-20020a05640243ce00b0048ebf8a5736sm877245edc.21.2023.01.03.06.36.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Jan 2023 06:36:47 -0800 (PST) From: Ricardo Ribalda Date: Tue, 03 Jan 2023 15:36:23 +0100 Subject: [PATCH v3 5/8] media: uvcvideo: Fix handling on Bitmask controls MIME-Version: 1.0 Message-Id: <20220920-resend-v4l2-compliance-v3-5-598d33a15815@chromium.org> References: <20220920-resend-v4l2-compliance-v3-0-598d33a15815@chromium.org> In-Reply-To: <20220920-resend-v4l2-compliance-v3-0-598d33a15815@chromium.org> To: Mauro Carvalho Chehab , Laurent Pinchart Cc: Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda , Hans Verkuil , Hans Verkuil X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=4018; i=ribalda@chromium.org; h=from:subject:message-id; bh=/UXa7D+904aszgGVJg9MhDXEF8Qvo7g/0S8PptJkuaw=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjtD1zcL22Ph3au1U3gzHL8SWYDK7mYXfBWKoblEKt vdwEXkyJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY7Q9cwAKCRDRN9E+zzrEiLVJD/ 4gkhLghiJBjonvw6CJAfVqI0aasnm/3bx9A5syTAog7bKFD70PgcslI9eWgs30Hg4IXhGjZCqcNFV3 oO96EhhRbfAjeeBFWUzC5ClsT3Ms12e+4JfyrUbEjirRcr691puM9WrJ+27r1w8PRvkJg9q3Ce3fQY m5PDEbsaUvpjB94DFxv63b3mvOD49o/ljPEoEf5p2Oqe8R5rvUvyuSC7y6ZfE051bw1xFqNgD33x9t iMNnjPtv3MJHehd2juFvyVBo+WD59yoTlf83AP8JFV+NAVuwBuWp7uKeEuLJ0DhZtHw5BoWsAU2WpK q/oQbm9pJq5WDZWLMlmNRTD3SeDssmXUpmd7azj13hVvgXrCChNMgKK9POBJY0+O0p/NKvlJLV1grP Nm6JTBmVwi9IzHoZKAGpH84vZDkEseUFIF10WtzoC+GQf4XmfYH2o0D4cdMht87ifWaeolSWRvHfT5 pQdSDuCXOdWhsWlsrrZ4OFr9YOg7m5jND6XtSPkbRmPtap96tXz7TSpXUJ9RxixdPEY9z8e1NeLT3+ fnmNt3Sgo5LyXV8p+FGHqaQ4kLaGAVx0U7WgL7eee6WqOoKuGE6zCP+mU4mMCL564DEflVeRrUd42q xX0YDY0sVrMasnfxsioE78cPvkyZfiJXgsQ4cC6XiNnE0aNGcg/gksf0aIYQ== 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?1754012852523914185?= X-GMAIL-MSGID: =?utf-8?q?1754012852523914185?= 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 Reviewed-by: Laurent Pinchart --- drivers/media/usb/uvc/uvc_ctrl.c | 52 ++++++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 6165d6b8e855..7622c5b54b35 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1161,6 +1161,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_RES) + return mapping->get(mapping, UVC_GET_RES, + uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES)); + + if (ctrl->info.flags & UVC_CTRL_FLAG_GET_MAX) + return mapping->get(mapping, UVC_GET_MAX, + uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MAX)); + + return ~0; +} + static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, struct uvc_control *ctrl, struct uvc_control_mapping *mapping, @@ -1235,6 +1254,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; } @@ -1336,19 +1361,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; } @@ -1831,6 +1851,17 @@ 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 &= 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; @@ -1845,17 +1876,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 Tue Jan 3 14:36:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 38469 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp4654510wrt; Tue, 3 Jan 2023 06:43:28 -0800 (PST) X-Google-Smtp-Source: AMrXdXufFs3hxv2gzn6yJa2a4otIM63hWNi99uyWYdizAOGjs+V9jVvz+7YIhGJ6S+AwRy4TLkod X-Received: by 2002:a17:90b:2791:b0:226:3a7c:f97a with SMTP id pw17-20020a17090b279100b002263a7cf97amr16028859pjb.26.1672757008004; Tue, 03 Jan 2023 06:43:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672757007; cv=none; d=google.com; s=arc-20160816; b=tVNQ0fZpObW7qcaSByyDNY8NOcT7HZfwv2YC9/coJzItlECqJsX6IesGt85Ep0yp20 9eG617yKBCfWy5nSqW2FpMDosbe4A/3XJ9RosadPTHxz2+1SAH84fqwizhiALROVqynn RZxR768tG3PGD5Vlf+rucATaTDa/igcUtRBhC9IUwCSsbPViF4ZhCUpTm6mu9YwZ1iq8 rB+CLWKwZ+e0i4o6YFws9Rfr2TsktRASS5yGeyBLqv37SPLe6Avcd4lsXiTtFMM+UroP aF06zN4smdpbJLDQVYLDETw17e4gNf8ErTTpRAIeY4vOv93YTnqfsT97GbxnaJrU4VFo iGOg== 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=uMv0+FOAOO/esYuQ37yIKwt94y4B+tlVWaU4vykTkck=; b=MDT4eqxpalCAfiz3Nw3VVaVj03V58IFRTHIK7+GUQ7FiVP/epg7wjhrSZc9PZ5fcNc aAbjd0lQP1UPB+mPwoVxC68dqjrUTBdJjmCiVsVQWo2i+fPaRfi/hPHgVe4QT82fUxcE 1Yi1pjDsV01R2M8oI4DK3I+9HW09q5R72IwNBgC19esh6R0GXFdk5mVvc4Vm1j3RntZZ NdQTbdWxagxx/xWGgArScyGbxlWSDNzO6XDqOMtEJM0rvzQg1r6r6LLfW0UmLYKCiZxu zEewTGwvCfGZspb3b+T+C1jpaXmO0WB6yNpLjAFE5dIeml2VP2c63AFX/y+Om7pE8vF/ 80/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=axciJGXp; 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 mi13-20020a17090b4b4d00b00219f2ee2bbdsi6429168pjb.102.2023.01.03.06.43.16; Tue, 03 Jan 2023 06:43:27 -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=axciJGXp; 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 S237827AbjACOhh (ORCPT + 99 others); Tue, 3 Jan 2023 09:37:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237917AbjACOgu (ORCPT ); Tue, 3 Jan 2023 09:36:50 -0500 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E624411819 for ; Tue, 3 Jan 2023 06:36:48 -0800 (PST) Received: by mail-ed1-x52b.google.com with SMTP id i15so44100509edf.2 for ; Tue, 03 Jan 2023 06:36:48 -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=uMv0+FOAOO/esYuQ37yIKwt94y4B+tlVWaU4vykTkck=; b=axciJGXp+L8SXhJfkIq9Twg+BjWIAaVmjUFo2VgPpnEDwjUXfLMGXS+Mm7t0ShH3BO h4UPoPC/6hc16VgOnFLif51jIwHd336iVnaOD34CDwuWOAwkQqGaSL/03/n4Vs4FpVmt 3yoyEl5AnMmKov4OR1JYDVFdC6NsNS60KwEqQ= 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=uMv0+FOAOO/esYuQ37yIKwt94y4B+tlVWaU4vykTkck=; b=MOkvcOFPf9SEMhJa8vdUcWrZUPyC3cJE3GS5SnvBzPywXN63Vnza5r5KnNArRGTReT 6zPGfusJn7nyZnlrS4+dKUrlNUUAPlXurDNu5Eo7lyf2E812F/Ltv5Gm9ujecIcvE4xM NYdBd1uckmOCruyD8xwgvSY355wbT6fP7oU7vPJGCNbGrjzBiTcQx1SNdTcPk0TCXWgL lfDXMn1igtKSs1ztiLba6HYjUVr0B2ozzlKpI611xmLRFntFTE+CJtojfUPXDfXTl9HP 9s6bkZ4vdBUWB9xPDMHU6j9y0K2EGpFPtIbB6QvWOFWqmpMWx0jkQRgGELjbB0Ut6W6U ixhQ== X-Gm-Message-State: AFqh2kri+Dt7ryGqQxVbITLfNY9b8Cvb2nn+DHWKdysYHIyHqr26vUHy BS9FarIxNHX/XkSw32zJp3FdJw== X-Received: by 2002:a05:6402:7d4:b0:467:f630:7927 with SMTP id u20-20020a05640207d400b00467f6307927mr39620050edy.15.1672756608540; Tue, 03 Jan 2023 06:36:48 -0800 (PST) Received: from alco.roam.corp.google.com ([2620:0:1059:10:9789:8e2b:74ac:a9a0]) by smtp.gmail.com with ESMTPSA id p14-20020a05640243ce00b0048ebf8a5736sm877245edc.21.2023.01.03.06.36.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Jan 2023 06:36:48 -0800 (PST) From: Ricardo Ribalda Date: Tue, 03 Jan 2023 15:36:24 +0100 Subject: [PATCH v3 6/8] media: uvcvideo: Implement mask for V4L2_CTRL_TYPE_MENU MIME-Version: 1.0 Message-Id: <20220920-resend-v4l2-compliance-v3-6-598d33a15815@chromium.org> References: <20220920-resend-v4l2-compliance-v3-0-598d33a15815@chromium.org> In-Reply-To: <20220920-resend-v4l2-compliance-v3-0-598d33a15815@chromium.org> To: Mauro Carvalho Chehab , Laurent Pinchart Cc: Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda , Hans Verkuil , Hans Verkuil X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=6230; i=ribalda@chromium.org; h=from:subject:message-id; bh=CzvIh2I8OYn6qQYfnpDNhfSCuom8YJfz/8UwnMOFDWQ=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjtD111zYzZRZMddOczAz+5+Us8BZbk9PPe9y/ph22 e+LQ58KJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY7Q9dQAKCRDRN9E+zzrEiC77D/ 4+HY54d/4XeFnOJgGXJeNlSST+xxOaDQD+xupk1M0qW7jpH9VScQpPdGRwB15LzKmpAg+JsbsAB8f5 Iu/6OaST5qg6G/sKDs9HgPsh7/qdHgAsYC6zLH2U8ockN+jUEf71l2ZDptX5AejO/FIUpD4CaSvVAk FYqt5XcGI9zh9CiDniEL6++RYTd11uwRo92D0DJBFhaLnU4PhIAV9/+9Tffxm1Sfyakyx8zo0jQfpF Z4AvY97/8jdySxykYoDPa9Cgi4zX6zL8UpL1eNfWek8Ba7R1H4zN+FPTHKiCr/sLo0v8zT9dP/b8P+ G4P+a76atGzNDHt1EQRdabLLFPmVQgKubltY/z/KfBsB/95Itqs+45IKU9XdlJSj8u/NHjGAvcjY1x UnDpA5rTjMVhYhB3/QzASWAmU128FQeQ3QnO2dcOc3rjfemLhoBfN0DRQLzlkfLQyfHHf13DrdqzoC QZv2h6cdlnjFFuO9rBjyGVlOEc3zijXZ+SrRYmo+PSINCMDwTAGKpoa/i5FofUirP7WKAtn8n9Z9ft qX7yliMQhi1ybSaa9iq8pSD3B4qRz08G4lB2z3WUpAacMer/sNrlFL6CitGWpypZTPpVNHSjanPFuQ BFF+XcMN1NVipnG+et7krJ7AE/hBqZuzXcHO1+CXBn6BVPBD1TDhCE9R+UVA== 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?1754012852478233340?= X-GMAIL-MSGID: =?utf-8?q?1754012852478233340?= 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. Reviewed-by: Laurent Pinchart Signed-off-by: Ricardo Ribalda Suggested-by: Laurent Pinchart --- drivers/media/usb/uvc/uvc_ctrl.c | 30 ++++++++++++++++++++---------- drivers/media/usb/uvc/uvc_driver.c | 3 ++- drivers/media/usb/uvc/uvc_v4l2.c | 3 ++- drivers/media/usb/uvc/uvcvideo.h | 2 +- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 7622c5b54b35..aa7a668f60a7 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 @@ -525,7 +526,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, }, }, { @@ -731,7 +732,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), }, }; @@ -745,7 +746,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)), }, }; @@ -975,7 +976,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; @@ -1228,12 +1231,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; @@ -1354,7 +1359,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; } @@ -1868,8 +1873,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; /* @@ -2305,7 +2315,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 e4bcb5011360..f9e6208c4636 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -2384,7 +2385,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 3edb54c086b2..ed2525e7e2a5 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -6,6 +6,7 @@ * Laurent Pinchart (laurent.pinchart@ideasonboard.com) */ +#include #include #include #include @@ -80,7 +81,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 a151f583cd15..f75e5864bbf7 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -117,7 +117,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 Tue Jan 3 14:36:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 38470 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp4654778wrt; Tue, 3 Jan 2023 06:44:00 -0800 (PST) X-Google-Smtp-Source: AMrXdXuQs/G5DSAcDB/6/x57D8FjYTB8xExeJ6Pq9t4V05kVcRdpAg8DyTSnCMb9R18G9MFDBRhr X-Received: by 2002:a05:6a00:3490:b0:581:947a:b701 with SMTP id cp16-20020a056a00349000b00581947ab701mr24075577pfb.17.1672757040520; Tue, 03 Jan 2023 06:44:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672757040; cv=none; d=google.com; s=arc-20160816; b=ykXAMPqnnhPNrSaFi2Z8yauTaRaaDDy7LYPjRlI6jRhihTDLZfEDtwixphDLFQiTqP mnTmPEzFdO+71V4GcB/ptYajw+hB2RAO3hFfFuvOJGW02DgU2rPDireuqRcA2f7GXWYB DGYw9JrWIgEjXnDoDbyarKQP9rJn5Ut9uiwzJ3bfC1vTsxfNxAGLQYc0vCn9BZcvv37i v+RuHp1TE0T+rMtsozWz86dcZJXy1IMc09x3sqTlhuinAKFOy9JSQzTMpvKfgZi0XsxK ev8FXUlB63vU1CqLSKIbvubieTF9myX3bENhP73xoFBvPiiCxcURpTlUHGeniOS7CiLZ Wtlw== 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=dAHTPeQigGkzAZXe4x+9ro8RmOt+dmg94cg1cPhP7q8=; b=p5BItL2MtWcsIDxvFxtwKqqQZafZ25jA2/q3TByqC8tLhve/aNCwu5XPF0mASiYZhs JPDM/cPgkBgMvcLsNvYpRRg8Rg2n9NGsy9C5kiJkBeXC+Q62NP7jQ2M4xXrM+2zE011F EyoW0JuXcJ/2KCFHsdR53vmGVieD3CryNp9m1gkZtk3aKGPqc2Nxz0hQhMHwDnOfZZFR 1q0bw5Q+IFnGEo5tAtRraSLgzKDLzxzACEYY3Ag+BOfipUgD6Z2gbwtN7NMPwClo5/3g Yz+jZ0B+GntoMCY524lOFc0/FKBvsSdlXzM7nhqqmDqUabOMfR8NRzY8/hOd8hkzbN0Y +ZLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=lCMlC2H7; 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 d10-20020aa78e4a000000b00575757288e4si30807875pfr.90.2023.01.03.06.43.48; Tue, 03 Jan 2023 06:44:00 -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=lCMlC2H7; 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 S238045AbjACOh6 (ORCPT + 99 others); Tue, 3 Jan 2023 09:37:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237942AbjACOgv (ORCPT ); Tue, 3 Jan 2023 09:36:51 -0500 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4C8DFD30 for ; Tue, 3 Jan 2023 06:36:50 -0800 (PST) Received: by mail-ed1-x529.google.com with SMTP id s5so44028468edc.12 for ; Tue, 03 Jan 2023 06:36:50 -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=dAHTPeQigGkzAZXe4x+9ro8RmOt+dmg94cg1cPhP7q8=; b=lCMlC2H7baya2EyugYe/2t2UaN7sn8tQn32AmADW0/1KCdyNmlv2+0Mekp8k41K5yT mvy3hOn4QpdSu3vaAm3MdG3b5/kXSaK26E9zfMW3A8qAxNesfF7NEvvHmxAnkEyxh68t 9zdzZGfngI+UcZNpOb8nUyddtcMJjx9OCEFE8= 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=dAHTPeQigGkzAZXe4x+9ro8RmOt+dmg94cg1cPhP7q8=; b=HytRPvk/OqYMepHMPOBkioHYKJVs5qlGIEvmBS4uaK9ECRFuCQypJeTTcjXdFzQ/F7 aD8xL3BeimaKZPlitO8ZAYtBtT1Et8Hcyvvut2X/njwlUD9exgzD5QPs9slZTLZJyL1S pdWLLPjlymlOi4TW9gjn+8MeJJ+FRVNrSResrh4g01r8eENTxv7y/006Ewr865LcDDr/ F1EmYc3FWKDgPYfwoKw4zA30JjmC3ALsQ/wOfkR/gElRk9iHcGXacadPbB0/d4252/JE Y/tGp88KKCX9DziVB0kB87Xi9dSPWtXOsKRJ3cV9dWGtCd1q4hL3jAtzdohYRU6GC/eq qpPg== X-Gm-Message-State: AFqh2kpZZ+qSWh/PA3pRqvkLB0mUSQeXYTDMYVx1gHBq5MxQAleCTRch soaTCKP2f55br7oREWE2aUfvMg== X-Received: by 2002:a05:6402:f04:b0:46d:ca42:2e59 with SMTP id i4-20020a0564020f0400b0046dca422e59mr42519239eda.11.1672756609473; Tue, 03 Jan 2023 06:36:49 -0800 (PST) Received: from alco.roam.corp.google.com ([2620:0:1059:10:9789:8e2b:74ac:a9a0]) by smtp.gmail.com with ESMTPSA id p14-20020a05640243ce00b0048ebf8a5736sm877245edc.21.2023.01.03.06.36.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Jan 2023 06:36:49 -0800 (PST) From: Ricardo Ribalda Date: Tue, 03 Jan 2023 15:36:25 +0100 Subject: [PATCH v3 7/8] media: uvcvideo: Refactor __uvc_ctrl_add_mapping MIME-Version: 1.0 Message-Id: <20220920-resend-v4l2-compliance-v3-7-598d33a15815@chromium.org> References: <20220920-resend-v4l2-compliance-v3-0-598d33a15815@chromium.org> In-Reply-To: <20220920-resend-v4l2-compliance-v3-0-598d33a15815@chromium.org> To: Mauro Carvalho Chehab , Laurent Pinchart Cc: Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda , Hans Verkuil , Hans Verkuil X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=2015; i=ribalda@chromium.org; h=from:subject:message-id; bh=9TceltHofxTy9VGQ6b063wegxNqLkTD5czVh+mkaViU=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjtD12Pm+Pt4NYHp6kgsePzovAUC+g8qNSkc2d44eM mgFKrx2JAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY7Q9dgAKCRDRN9E+zzrEiNEpEA CLEufUPLQ3HTohZFgOdTqMvgKnnLNzS546HhLprD+bwAmbmQyuwqcepai9q5vjvPtbN9fCCjm01jPN v+iPwpjQvze6uxrrxJFhXjiyJdouV1Pc9vqF1djm082BwEVPpIzF4ICWKHj7xApvPYjRV+6L4mrDGk bcXcKxfyXSmBcWtKdv7g9OoMxRV9/AvwjpUMvMhKu7cIMo1f9pJXkk4CaaJr626OEEvfI42KktXyrs 7ep14IospObdVV09J1ASUr8i3OGswy3mnNypVG5QiejKZyqmR0aEZJo6sIkIr8GYHMW8GzW6IRQDiI VAz6Ewg611KDHSOMz2Sx+WLRHZCg8ZFB/XMumsExn1vH2bJ5T/UZ+HZDeBfZn/bsG72kUCIA94YO0O 3TwQE2vwjtMiircrGpMAzJbgagjKJZKmsGHl90IBbSY35Kbwe5uvgbr5oU4ipu59Cg6mzTbwcbqI0J FFLIITuGx/vAUwY7g5aNxUDZFAJBhrrSKGU6/PkdsXqwZRju6OSXGbkAM/hCrkIQ9ciDcbMT4rH4GS v7HtSDIlvsSwGPvjR2LV0ECLiIONo6Qu4VgmaGepFBIueklxEiE8JMsvtOjvKEPZdz3KYpfQf035eV P4eQX9l0pg5V5O8hAyJ1QaTNz3u5sJlj0JJnaLpuUUVcHkgTtIrU5//wkGuA== 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?1754012886547757965?= X-GMAIL-MSGID: =?utf-8?q?1754012886547757965?= Simplify the exit code with a common error tag freeing all the memory. Suggested-by: Laurent Pinchart Signed-off-by: Ricardo Ribalda Reviewed-by: Laurent Pinchart --- drivers/media/usb/uvc/uvc_ctrl.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index aa7a668f60a7..4830120e6506 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -2296,32 +2296,30 @@ static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, unsigned int i; /* - * Most mappings come from static kernel data and need to be duplicated. + * Most mappings come from static kernel data, and need to be duplicated. * Mappings that come from userspace will be unnecessarily duplicated, * this could be optimized. */ map = kmemdup(mapping, sizeof(*mapping), GFP_KERNEL); - if (map == NULL) + if (!map) return -ENOMEM; + map->name = NULL; + map->menu_info = NULL; + /* For UVCIOC_CTRL_MAP custom control */ if (mapping->name) { map->name = kstrdup(mapping->name, GFP_KERNEL); - if (!map->name) { - kfree(map); - return -ENOMEM; - } + if (!map->name) + goto nomem; } 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 (!map->menu_info) + goto nomem; if (map->get == NULL) map->get = uvc_get_le_value; @@ -2342,6 +2340,12 @@ static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, ctrl->info.selector); return 0; + +nomem: + kfree(map->menu_info); + kfree(map->name); + kfree(map); + return -ENOMEM; } int uvc_ctrl_add_mapping(struct uvc_video_chain *chain, From patchwork Tue Jan 3 14:36:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 38471 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp4654781wrt; Tue, 3 Jan 2023 06:44:00 -0800 (PST) X-Google-Smtp-Source: AMrXdXuuu583EkPeoB4dw/kKc8vxcmJBd5ckZZMzZWUKnKrl6Q36YJruU6aAk/quD8a11U+xkOUk X-Received: by 2002:a17:902:e845:b0:186:7a6b:dcdb with SMTP id t5-20020a170902e84500b001867a6bdcdbmr60283223plg.40.1672757040590; Tue, 03 Jan 2023 06:44:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672757040; cv=none; d=google.com; s=arc-20160816; b=gevO3mGPEqUBjjdHHwWGywss1LK5ujF10mBmWtlhkKZKYNzHNaLlxEqLLN7r+xXCXd 4UyAMX8xntbCHpjk1a/1CJG8RgrzUM3RQMyYhIhyyYEEWU9uB/izxUU4bjK0GFJZ6wCH n1iSqu7DY2eM2eqd9Eu1vloRCb/2fDIksAdiwyFjYzqCuvCzQyjwkdvNedjVxoQNcYOJ xsfNhRmmmMy2AmGB2kDsljxRNgq0tK6rxfs0vBiVF1HlcfBfECR5GwZL7UQomN4hQfhB nZxzBk+K1JU2evacZEbsMZCa+HnqArrrSkPqmOGKriVkyJ+EU+IjQ4qT0BJwYAvTK/24 +O2A== 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=sPT1vsmDpYTaSok4BQktrcsW23gdSBjX1RKoXWH8/0M=; b=HokqqPS9Uhu7krVVYox9vDNzekTA/lX+MhqdsiQ3ke2REsrLUHlibfhLtirTOFNmWv BK9fy00dfLtT4LP0bgUu2WlmyG0PM1z64XDOqQ4KUzJXO9dpR3Ur+P7rfJrMZ4qLBf5p r/wUMyI6SmuofkgT4cKynB5684M0976CFGzh4zgq1Sw7SB88EEyCjarXrZY4bwv5nVth URibV0atrwA8OMFJ3FXw5e69rXE+79xuI3SDrXTN5GBLnUu6RbqJENjp/GJXEj4uPdK9 63cjZrVXEgOMwbqeDvfraocCztaab/9ycmTIH7mafwDiezRAUMQ3t1djC8KHGf8QGOuc Gc3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=oJ9gTHBt; 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 h29-20020a63385d000000b004991efb7281si24168867pgn.423.2023.01.03.06.43.48; Tue, 03 Jan 2023 06:44:00 -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=oJ9gTHBt; 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 S237978AbjACOhs (ORCPT + 99 others); Tue, 3 Jan 2023 09:37:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237945AbjACOgw (ORCPT ); Tue, 3 Jan 2023 09:36:52 -0500 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1BE0DF5D for ; Tue, 3 Jan 2023 06:36:50 -0800 (PST) Received: by mail-ed1-x534.google.com with SMTP id j16so11494825edw.11 for ; Tue, 03 Jan 2023 06:36:50 -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=sPT1vsmDpYTaSok4BQktrcsW23gdSBjX1RKoXWH8/0M=; b=oJ9gTHBtVg7979odsYIZ0VWvQFcLgw8XR2HtRPCW+O5N/t9iQ2u8N4WJMtcGbRhDRz D/VIC6mqntGUrqiVnj+hEDz+Q/T0/QSg7O0atE8iFl50U7TZ0RyR1Obx90P8Z8gaaN2i qOzmDUlzq+eJ+q1cLo4iyeovLPSG7i7jYYn3c= 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=sPT1vsmDpYTaSok4BQktrcsW23gdSBjX1RKoXWH8/0M=; b=mAShYxBlOCKcomPYDQoueGf7J/A6FOFy8DkB6lWvEifv66FLT+3H6tWDkETRqvWKFg 1fnkwAIpf4WNSqhnsQwh258/IGTGGIv1KkpN/5cgRXe6X7Tw/rcd7jEM6+FIxaNVHUwV Sf9SBSfopEF80ww2AxONcVMi59w+F7pKNawpQeRiONyYnuDfD2fu7zHjwyrzwvPmEsP/ U5F33lAijTuxBRKMgsEqN5BAcIOH1ifkVweu4LdEyOjsFCeDZ5rUk43Hgfi3lL1U38JB k7JebVnPc+KmoAjNm87c9iQkq0HYRWz5nnJrhWSBuS6C3PBJCPNV+/JuvKhIVmd6a/ov EQbg== X-Gm-Message-State: AFqh2kpYbXnm2hejT9hfxnhyRFdq1oOsvulRwrbRqzF/nHIvX1fq2zC4 PAKt3yWvNW41e4XHbiNrclyy6g== X-Received: by 2002:aa7:c948:0:b0:48e:9afd:de66 with SMTP id h8-20020aa7c948000000b0048e9afdde66mr4372196edt.34.1672756610272; Tue, 03 Jan 2023 06:36:50 -0800 (PST) Received: from alco.roam.corp.google.com ([2620:0:1059:10:9789:8e2b:74ac:a9a0]) by smtp.gmail.com with ESMTPSA id p14-20020a05640243ce00b0048ebf8a5736sm877245edc.21.2023.01.03.06.36.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Jan 2023 06:36:49 -0800 (PST) From: Ricardo Ribalda Date: Tue, 03 Jan 2023 15:36:26 +0100 Subject: [PATCH v3 8/8] media: uvcvideo: Use standard names for menus MIME-Version: 1.0 Message-Id: <20220920-resend-v4l2-compliance-v3-8-598d33a15815@chromium.org> References: <20220920-resend-v4l2-compliance-v3-0-598d33a15815@chromium.org> In-Reply-To: <20220920-resend-v4l2-compliance-v3-0-598d33a15815@chromium.org> To: Mauro Carvalho Chehab , Laurent Pinchart Cc: Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda , Hans Verkuil , Hans Verkuil X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=14698; i=ribalda@chromium.org; h=from:subject:message-id; bh=wh1JJVQQr5H40YobLYSjous0EuZS24y5dLYMjTH4kYE=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjtD13VmFJBfH2E8Y0XPa0RY4TURQZGrC9Xur4qsHX MXxh+7eJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY7Q9dwAKCRDRN9E+zzrEiIhFD/ 9V8/clBABXViIniLLFOp2sb5J7sIa52e/cjVR60QI4kuF7/5/OrT8CiX75dbIgPN3oWU3q3eE6zoQC Ayn+8cFXIv8S6p5AMbwEdXMC0BZFYVak8Oh2gdrsQwQNXPPGdgOnevuDv2iBvGAHZOQHQhMEWkEWrc X9G0gHyPFx1mUmvD1pHbp3tmKWvSD1YH5hsG8qH3lISSdgVV6gdh2GiHWVmMogeOhw2U0X4J5+5tDB yEngpZnYw6jfEU1P3AMsA6CqiW4/TgWPcwdbxSfP6aR/0iqQJ+XLasuHAVllBnyMieSJMBUt81w0lD 3qBodKJKM/J0+16T5Jyp8+52quv221TD7aNYdRUqMMbf/yKUOfBVN7Vlw3BWxGbguKJ+loazRpYl4+ JIJv4uC08wAOjtq+w9ImbZ0ZUoTQuk61XzBf7IAHD5NAhXcxvV73bZeq55gccXwADNxNhnEWIlbLUV 8/dLJAc1XJNFtEgBiF3rn9Q5LhoQmQ2JOa6YijZ3S/r3aurUbUXVHRorcwltp5xTpbZEaQK2XBredm 5RLsCUdyV9E5h+8/2SqcJK8YjuQ7UoErCuxNC38YDmFLbPSp8QpYRSkQ2z6vvTDVbVKNvU6SLYN5ue 8UV/AicCbK5FECv+pNVRQ9HgH3p4kk+9e9XCDvLjHcX+ROQ7l6zkxI4Nv7pw== 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?1754012886335963622?= X-GMAIL-MSGID: =?utf-8?q?1754012886335963622?= 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 | 126 +++++++++++++++++++++++++------------ drivers/media/usb/uvc/uvc_driver.c | 9 +-- drivers/media/usb/uvc/uvc_v4l2.c | 104 ++++++++++++++++++++++-------- drivers/media/usb/uvc/uvcvideo.h | 3 +- include/uapi/linux/uvcvideo.h | 4 +- 5 files changed, 170 insertions(+), 76 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 4830120e6506..86d74c9740b0 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -364,19 +364,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 int uvc_mapping_get_menu_value(const struct uvc_control_mapping *mapping, + u32 idx) +{ + if (!test_bit(idx, &mapping->menu_mask)) + return -EINVAL; + + if (mapping->menu_mapping) + return mapping->menu_mapping[idx]; + + return idx; +} + +static const char * +uvc_mapping_get_menu_name(const 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) @@ -525,8 +537,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, }, }, { @@ -731,8 +743,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), }, }; @@ -745,8 +756,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), }, }; @@ -973,13 +983,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; } @@ -1190,7 +1204,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)); @@ -1235,11 +1248,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; } @@ -1338,11 +1355,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)); @@ -1364,22 +1381,34 @@ 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 (menu_value < 0) { + ret = menu_value; + goto done; + } + 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) { + ret = -EINVAL; + goto done; + } + + strscpy(query_menu->name, name, sizeof(query_menu->name)); done: mutex_unlock(&chain->ctrl_mutex); @@ -1880,7 +1909,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 @@ -2305,21 +2334,36 @@ static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, return -ENOMEM; map->name = NULL; - map->menu_info = NULL; + map->menu_names = NULL; + map->menu_mapping = NULL; /* For UVCIOC_CTRL_MAP custom control */ if (mapping->name) { map->name = kstrdup(mapping->name, GFP_KERNEL); - if (!map->name) - goto nomem; + if (!map->name) { + kfree(map); + return -ENOMEM; + } } 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) - goto nomem; + 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) + goto nomem; + } + 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) + goto nomem; + } if (map->get == NULL) map->get = uvc_get_le_value; @@ -2342,7 +2386,8 @@ static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, return 0; nomem: - kfree(map->menu_info); + kfree(map->menu_names); + kfree(map->menu_mapping); kfree(map->name); kfree(map); return -ENOMEM; @@ -2673,7 +2718,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 f9e6208c4636..ee016b370058 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -2371,11 +2371,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, @@ -2384,8 +2379,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 ed2525e7e2a5..dfa26ed0c7f1 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -26,14 +26,83 @@ #include "uvcvideo.h" +static int uvc_control_add_xu_mapping(struct uvc_video_chain *chain, + struct uvc_control_mapping *map, + const struct uvc_xu_control_mapping *xmap) +{ + unsigned int i; + size_t size; + int ret; + + /* + * 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_names = NULL; + map->menu_mapping = NULL; + + map->menu_mask = BIT_MASK(xmap->menu_count); + + size = xmap->menu_count * sizeof(*map->menu_mapping); + map->menu_mapping = kzalloc(size, GFP_KERNEL); + if (!map->menu_mapping) { + ret = -ENOMEM; + goto exit; + } + + for (i = 0; i < xmap->menu_count ; i++) { + if (copy_from_user((u32 *)&map->menu_mapping[i], + &xmap->menu_info[i].value, + sizeof(map->menu_mapping[i]))) { + ret = -EACCES; + goto exit; + } + } + + /* Always use the standard naming if available. */ + if (v4l2_ctrl_get_menu(map->id)) + goto done_mapping; + + size = xmap->menu_count * sizeof(map->menu_names[0]); + map->menu_names = kzalloc(size, GFP_KERNEL); + if (!map->menu_names) { + ret = -ENOMEM; + goto exit; + } + + for (i = 0; i < xmap->menu_count ; i++) { + /* sizeof(names[i]) - 1: to take care of \0 */ + if (copy_from_user((char *)map->menu_names[i], + xmap->menu_info[i].name, + sizeof(map->menu_names[i]) - 1)) { + ret = -EACCES; + goto exit; + } + } + +done_mapping: + ret = uvc_ctrl_add_mapping(chain, map); + +exit: + kfree(map->menu_names); + map->menu_names = NULL; + kfree(map->menu_mapping); + map->menu_mapping = NULL; + + return ret; +} + /* ------------------------------------------------------------------------ * UVC ioctls */ -static int uvc_ioctl_ctrl_map(struct uvc_video_chain *chain, - struct uvc_xu_control_mapping *xmap) +static int uvc_ioctl_xu_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); @@ -61,39 +130,20 @@ static int uvc_ioctl_ctrl_map(struct uvc_video_chain *chain, case V4L2_CTRL_TYPE_INTEGER: case V4L2_CTRL_TYPE_BOOLEAN: case V4L2_CTRL_TYPE_BUTTON: + ret = uvc_ctrl_add_mapping(chain, map); 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); - goto free_map; - } - - map->menu_mask = BIT_MASK(xmap->menu_count); + ret = uvc_control_add_xu_mapping(chain, map, xmap); break; default: uvc_dbg(chain->dev, CONTROL, "Unsupported V4L2 control type %u\n", xmap->v4l2_type); ret = -ENOTTY; - goto free_map; + break; } - ret = uvc_ctrl_add_mapping(chain, map); - - kfree(map->menu_info); free_map: kfree(map); @@ -1316,7 +1366,7 @@ static long uvc_ioctl_default(struct file *file, void *fh, bool valid_prio, switch (cmd) { /* Dynamic controls. */ case UVCIOC_CTRL_MAP: - return uvc_ioctl_ctrl_map(chain, arg); + return uvc_ioctl_xu_ctrl_map(chain, arg); case UVCIOC_CTRL_QUERY: return uvc_xu_ctrl_query(chain, arg); @@ -1429,7 +1479,7 @@ static long uvc_v4l2_compat_ioctl32(struct file *file, ret = uvc_v4l2_get_xu_mapping(&karg.xmap, up); if (ret) return ret; - ret = uvc_ioctl_ctrl_map(handle->chain, &karg.xmap); + ret = uvc_ioctl_xu_ctrl_map(handle->chain, &karg.xmap); if (ret) return ret; ret = uvc_v4l2_put_xu_mapping(&karg.xmap, up); diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index f75e5864bbf7..0e816be556f2 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -116,7 +116,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..d45d0c2ea252 100644 --- a/include/uapi/linux/uvcvideo.h +++ b/include/uapi/linux/uvcvideo.h @@ -36,9 +36,11 @@ 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 {