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: 638963 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7B72AC46467 for ; Tue, 3 Jan 2023 14:37:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231134AbjACOhD (ORCPT ); Tue, 3 Jan 2023 09:37:03 -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 S233507AbjACOgr (ORCPT ); Tue, 3 Jan 2023 09:36:47 -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 A121710B4E for ; Tue, 3 Jan 2023 06:36:46 -0800 (PST) Received: by mail-ed1-x52a.google.com with SMTP id z11so28191122ede.1 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=wYBntsVyXyAlZGohdYiIXmfUupIL+C9GVL4Xy+PKdFhdzrnsiGhUOXljgREbt+6Iti ID1cgTLlg0psIcZ8lkrTPNEn4haW/rpHksgZt1bkjeD1RAvEaZ1Mx1WJmqKHQ9Qocstu 63nauc5MLepukvXifsE0dE91Q5g7NE8ZnugMM6tH7f4QaQFlb5g189SI7I4jFxtwsa8z X0bnhrhrQ+FCJUKsOcuobH/BD4pbAhVkizxlwSE2MLLbR97PFuGElVgxAgMBsgOylil2 rjFCx91NDdOp+aVr4HyqbStQJJLzkuUVM9V3MKje6xmyvx+XuaZHObga1pjqrj+MopEK r37A== X-Gm-Message-State: AFqh2kpJMGeN3uJ+Zp+hYurkUO2E31fcU+3PTNdiMBeWN5ZqTgbgLKde tDKWRstGswt9hlGUiC4EzGtymSoXYRRTL4b5POU= X-Google-Smtp-Source: AMrXdXvjqPPYzbopbrJmWLjzf+kJEn8sIFmgDwOGZIYyPJaThxKy8VZaNxUZ0dVmtzYuIZIoAuzcNA== 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 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org 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 --- 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: 638962 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7C77C3DA7D for ; Tue, 3 Jan 2023 14:37:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238010AbjACOhH (ORCPT ); Tue, 3 Jan 2023 09:37:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237816AbjACOgs (ORCPT ); Tue, 3 Jan 2023 09:36:48 -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 836E911446 for ; Tue, 3 Jan 2023 06:36:47 -0800 (PST) Received: by mail-ed1-x534.google.com with SMTP id j16so11494560edw.11 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=3gekvKO7E5MQeUYzXQoScsjSNJZptSNUgRXQ2uxZGXRfPA1fx5nXU7NJ0OHaJWUIKg BOGg6OUwNVNPtXIl3EZEGvlvX/rgWI9HKaY4iYBPq9OS4QSholI5HQEODoeP7C8tBwue hUZZABRvGbEgSFmNY6oOq3zVG2KViLAScFmwk135t5ayk73aORPM5HsSgr/aCwSZ0xvy gQRd8ISO2D66GG2UjhqG0P2UJna6egH7PqfA133075AtDTy03q026FHNoZlhrOZVOtyV +m4EYDT6/SCvpv8zEmyE+A0m1udNfmMDrD9lq/gt/KfUxfzZD0QCuTYvlSFWSYMDHfyC QPqA== X-Gm-Message-State: AFqh2krVRNEi52PAhBwWQZNba+2u/28m+GGu3p9w5IUTeUy9jMEE+OpD 8VcwqlYuL/fgccFw08VVPuP8JQ== X-Google-Smtp-Source: AMrXdXv/ERkpbmQUN1jOPgeP5z2kA5nwMnSadpWDuFkONa4pSNM4CEf4WAdUSkPlrEy5oOzet90Jhg== 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 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org 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: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: 638961 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39228C3DA7D for ; Tue, 3 Jan 2023 14:37:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238015AbjACOhK (ORCPT ); Tue, 3 Jan 2023 09:37:10 -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 S237911AbjACOgu (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 2566A11825 for ; Tue, 3 Jan 2023 06:36:49 -0800 (PST) Received: by mail-ed1-x52b.google.com with SMTP id j16so11494672edw.11 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=nmvQe9dck4uLRXTCgh9jW4fyTk5aNdO8dIMpECXXX3FMXDcUSCKakxengyXvDGN5+W XebZu+Fz0+iOX/WLg7gPakB90mespSVnIsibyN957njHvosbshGTXJ+MYywKBCvsc6ZI wgZqvgqkNwC7rm+NyqcHnp/YidEfM+cs+2EUMgZjtUoLUQGKy3EhK6Tn/VT7Rcm/GLrQ GX3Z3NQaKmGaQ5O04ktUEEWGNnkf9FEjhdt6ARVJupo+Ty7uVn24dILFhu231L89Zpm5 NdSF/9/VDMSDd1SSHPoWwiIugT76hw3+7ZHWPWIrWBPt52dT74DC2gUJHNNUR8gdCbka iwTw== X-Gm-Message-State: AFqh2krV9pLyoQle+8yKerrArHN3+1Iwp+vj7H6uLE/n4bQDD+jf1Cmi x15EA+vl46tNVB4BITzf2pLXUg== X-Google-Smtp-Source: AMrXdXvrG/icB/AxrF+Mtk79mTLUwLtAUf2Jo46vsAJbtKZTNHYOLM2kdgnVdJ7fZtWDh84Nrhq6+A== 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 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org 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 | 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: 638959 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5B9DBC46467 for ; Tue, 3 Jan 2023 14:38:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238042AbjACOix (ORCPT ); Tue, 3 Jan 2023 09:38:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237929AbjACOgv (ORCPT ); Tue, 3 Jan 2023 09:36:51 -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 E487CB59 for ; Tue, 3 Jan 2023 06:36:49 -0800 (PST) Received: by mail-ed1-x52b.google.com with SMTP id c17so43983772edj.13 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=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=IPnO/GRRRfcp93EC+Z5vWeBl8GUVzISBGen8KeVxwEaijLs3ATo2fmGEobAFT2LBmO NuOZUA3rO5LhrUTCsYVhSUGiJPNUkKAXuSFtBfxNcetr3wQrooIUhNoq8M03r1jyy/e9 cPuRjOXTZTS64ZYx35bWvpPphiiGOutDQiCA/yU9o+P5w5bBAe2LkkvdIrCfMPKH8pMR NV+a5FsR35c1aqYlOMG86O/NFNkka8bSOFVfdfEomDJFMIlVUPgmcOJ1+EGjweoHJ+Z/ 0PhT4NmI6MWDb8dd2OozDZ8+pNx01pFJEECo8GDH0gGNRkyAUVlPF1hH2SeT82HnGZXw kPvw== X-Gm-Message-State: AFqh2kpp3LDF+fdTrYrTFpx58CkdgASSBftH7KPumssylZ/keS5CuLjk TJsVLKv8ucPx4zW2aj5DHe/QTQ== X-Google-Smtp-Source: AMrXdXtb0KbBmffKCMQE10rF9mg7ZpQ9x6DkWuo9IcT6QWXkYzDnWbNV6Y5bNLVqhUd+d/048F/V8w== 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 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org 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: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: 638960 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8E3B8C46467 for ; Tue, 3 Jan 2023 14:37:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237778AbjACOhN (ORCPT ); Tue, 3 Jan 2023 09:37:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237970AbjACOg4 (ORCPT ); Tue, 3 Jan 2023 09:36:56 -0500 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD0741005B for ; Tue, 3 Jan 2023 06:36:51 -0800 (PST) Received: by mail-ed1-x52c.google.com with SMTP id s5so44028527edc.12 for ; Tue, 03 Jan 2023 06:36:51 -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=6tApJxpBtgaNgE1yCvgpO+tshoFI9D8lUtV0pYzILcA5xN15TZZuGLf0du08vCWmT8 pmhNr11hrwrJABCIv09KBeONZFu1Vp3x5ysffgRRkFFN903pgqntCG0DFSoNZLlD66OB bRbjuF0S7L3idRloegiy7hQfvNPHjJ+XlQpN0kZ0+82Y3zQ67wfwM7ZS8AyfMWfP7KcF bud7c1D7pbByWSFTRM+Z9cMOByrP/ger8JQW4enlUiu6tAA0GasMwDg66RpTU/anExUS KDRdWe81ACsZsaQvWZRp+Pvv5QyJIOuZqZ2k9fvu5NQC3vl4ER2AmtnYdRJUM3f3fDQc u2qg== X-Gm-Message-State: AFqh2kroamIEHezkxfJbJV35LRc+n/N40jawbg62v8W4L5kU0qyOEnCN XZxYyEFJoQ8x77TdGvzBKhDshg== X-Google-Smtp-Source: AMrXdXtTdwXyMgkFUJhvTUdoDkY0MJ12WcTC2Y+YFZb/CLUVel3X5u5Mscd307lZz9/tCb4DL5wK+w== 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 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org 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 {