Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp5085634rwb; Wed, 21 Sep 2022 03:01:57 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7VQi+YYaqcCVzpbYQZWMpXcDI1yYNdi0LNxO8qw92hmF6eTw54IAMM21o/r5RxTZnhmra8 X-Received: by 2002:a63:5a63:0:b0:42f:e143:80d4 with SMTP id k35-20020a635a63000000b0042fe14380d4mr24396749pgm.456.1663754516699; Wed, 21 Sep 2022 03:01:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663754516; cv=none; d=google.com; s=arc-20160816; b=W8iMuJrzazf84nzO6pNvFT+ghCG0RFMcN26aHnJat5y5j1LBModemo4sT9OoNfElmg 3fWWODhQnyF8oZn3aUILOkl4FFVyF/E21T/EgXz7MZAU3eDTuLlua/aMVPfL5my2PQsn tx7dr2x3YEM640eAv2zsYY2BSVrWWXSJz8gmF7k5XJAI7jAQrA5pDDiDibUQ1l52Pae0 ajzt4mRIMXNFT1C66k/nECaek6MVToT4Iqz1guy7S8SAigU4UF78DHmdZsX/aPYkmBlb +GyP8jmf5J51114iwYpbPRPYS1ke3WXWRh918pfXLoFQFX44fUtVhVAt7sqzoExDRAd4 SO0w== 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=KhSTzdRpHyXekvkZIF9m/LOjh+6cejD2HdUoypu9ses=; b=e4ykV2a1XBPJXSoS7H0XZdIA/bwT6e7TsTfj/1J94GnCXIb72Fv3PkUXeF36nqG1yu SN+qUxNdsWMTJmpkMffLMuzxz1SlF3nL0hcj4h9HaTQxiDcGwDosLBv5Hj4ZXkluKRir AuJyA40QJbrSqmUq3jru5z8PXKj64vwNiQxnHGuHrSy8P4crJGOzIlEq95dU4rHUT7fj tRZlpo8a8ZP/TzuTx0Pc7Co6dDFRHp4PO3yGyQCpWmyKEKUA/4sPTx2aRN8F7IHuOOWI iYA2RgEM6jJIwHPHfJyKGSl02+rHdU0AFrgMd7QvPkct/WPYfMN++BJ3Dm+FOdZrPUcV p1iQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ZVzioVA5; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ck3-20020a056a00328300b00547d55a4d3bsi2111545pfb.285.2022.09.21.03.01.45; Wed, 21 Sep 2022 03:01:56 -0700 (PDT) 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=ZVzioVA5; 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 S231402AbiIUJND (ORCPT + 99 others); Wed, 21 Sep 2022 05:13:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231140AbiIUJMr (ORCPT ); Wed, 21 Sep 2022 05:12:47 -0400 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 6E4DC8C471 for ; Wed, 21 Sep 2022 02:12:39 -0700 (PDT) Received: by mail-ed1-x52a.google.com with SMTP id e18so7703480edj.3 for ; Wed, 21 Sep 2022 02:12:39 -0700 (PDT) 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; bh=KhSTzdRpHyXekvkZIF9m/LOjh+6cejD2HdUoypu9ses=; b=ZVzioVA5sy4vcuF2Jxrk0fMhwmk5CYBqKaEHNCpvSoDKxaMbYhZQY1qWl0e3XXGNkR uciIy5joLXfTNhViLfl6/xnM2gCOX5iiXBiVvP7rJI1fFX/glPeGroxP/5bk4FjdvB1s y0MmuDZo6CK0n7JHELehWNYwL2t+0rv7S/1QQ= 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; bh=KhSTzdRpHyXekvkZIF9m/LOjh+6cejD2HdUoypu9ses=; b=YIdGy8RfhRYLBKFOCAJNrIAL8HxKC5RJ0MkQZkdYwi79tECDkAq/n91iKBgFFSDLjM dcR0/Llgl4SfOgJRoIz5W38F5QpPyWgb0irHkRUxGbkl2+gRvLUZrFTXivFZDdQrspCw rcxCyK/nPBKIo4YYtjv7buK9hdGVCGfbS4E9JFDkcV7ZGY7XUYypngq7w0wW35+oBZKG g0Oe3AP4XXhf1lYGKB/vdJY0uANuuNoG6oD/niSc2hv2eo4iMid2gL0a+qnr/K1B8vSj mimhD3vkmo+riA3YrXDNiEfd3y+deezwqGo+T8N8oD+6v4A/SshwoDVqOolF+/8BsUlp 4/IQ== X-Gm-Message-State: ACrzQf1h5qHSoRrKn4HGluG4kv88mQHaWOs0gB3vmtr4uujvvBXGOV4p 1vqLoQxs0fIOBQ+1J42Sm0DkOA== X-Received: by 2002:a05:6402:280f:b0:44e:ee5c:da6b with SMTP id h15-20020a056402280f00b0044eee5cda6bmr24416248ede.256.1663751557701; Wed, 21 Sep 2022 02:12:37 -0700 (PDT) Received: from alco.roam.corp.google.com ([2620:0:1059:10:160b:cee7:2e8b:f72c]) by smtp.gmail.com with ESMTPSA id v4-20020a17090690c400b00771cb506149sm1031913ejw.59.2022.09.21.02.12.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Sep 2022 02:12:37 -0700 (PDT) From: Ricardo Ribalda Date: Wed, 21 Sep 2022 11:12:15 +0200 Subject: [PATCH v2 6/7] media: uvcvideo: Implement mask for V4L2_CTRL_TYPE_MENU MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20220920-resend-v4l2-compliance-v2-6-7c0942040004@chromium.org> References: <20220920-resend-v4l2-compliance-v2-0-7c0942040004@chromium.org> In-Reply-To: <20220920-resend-v4l2-compliance-v2-0-7c0942040004@chromium.org> To: Mauro Carvalho Chehab Cc: Laurent Pinchart , linux-media@vger.kernel.org, Hans Verkuil , Ricardo Ribalda , linux-kernel@vger.kernel.org X-Mailer: b4 0.11.0-dev-d93f8 X-Developer-Signature: v=1; a=openpgp-sha256; l=5496; i=ribalda@chromium.org; h=from:subject:message-id; bh=3O1Bf/bPg/WbVl6ONzWeNxOkFgRnu/o7Bwr9BS5NZfw=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjKtV8EANwfFUu639K5SXGL7nFzHWEf3rUpwLwNlb3 MNPVEm2JAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCYyrVfAAKCRDRN9E+zzrEiO2DEA ChX+CwU8v9tyMQAnCoM0NvVlT8+PduID9y0DpVKuP+CLKOajwy5Vr1HPtKpDOXAruPIL40R1segP/I +KvBp01RXIq7/+u7f5xHnBJwLEb7MOKjAYQAyOiaeA4A0USLGt/o0qbfva0I+gCPfXisQNFLX4rOf7 Ha1m6o7n03n7b8mNllHbBPVqW+HTZrzQoHVQwlI+xn9uUeO3OZzHFBUawHZAtihqPWQFWum51uMynV 4WmGHpdqcytlkKkxURhlvjNEP/jsXS9jeU5D7I5O+p5EYpLUE/7c87tRjzvf+9fFfSBSw0g/zIPK8r WxUeiVraLyX48GHXh8z+uZpkSxobxfdwhW9NwmQMMhbS6RGJ/0u2ezhiu6SXwzcBasFd7fTWYgO5Zr 0lHtKyhqbWVbgOdHWheiYqmeTRJbnAFvpN0e4r9GZaAIgPQ+yMY0su0u4Lk/ixeQoW6ahzDyB+BUTb CaTLF/lyMzYC14jqCII3EbtUk1K54i8C4UVtaF5H5RH1TW7oUFxzmZ8BdgUvQBayMeRwUq0M4e6Pkx 83rMxa86Wp1w8pcgjLLalPWz+DtnhsRBvfilYEX1WuUpaRVMfg0F/im5k7lQIoNcJzj0KGcG+dyBLd crE7gS2yHFKlhtZ1JngWWJbI0Ghe94Br1o9WeGc+HGsOfIm1lVQx/0rW2NsQ== 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 Replace the count with a mask field that lets us choose not only the max value, but also the minimum value and what values are valid in between. Signed-off-by: Ricardo Ribalda Suggested-by: Laurent Pinchart diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 526572044e82..df273b829961 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -6,6 +6,7 @@ * Laurent Pinchart (laurent.pinchart@ideasonboard.com) */ +#include #include #include #include @@ -524,7 +525,7 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { .v4l2_type = V4L2_CTRL_TYPE_MENU, .data_type = UVC_CTRL_DATA_TYPE_BITMASK, .menu_info = exposure_auto_controls, - .menu_count = ARRAY_SIZE(exposure_auto_controls), + .menu_mask = BIT_MASK(ARRAY_SIZE(exposure_auto_controls)), .slave_ids = { V4L2_CID_EXPOSURE_ABSOLUTE, }, }, { @@ -730,7 +731,7 @@ static const struct uvc_control_mapping uvc_ctrl_mappings_uvc11[] = { .v4l2_type = V4L2_CTRL_TYPE_MENU, .data_type = UVC_CTRL_DATA_TYPE_ENUM, .menu_info = power_line_frequency_controls, - .menu_count = ARRAY_SIZE(power_line_frequency_controls) - 1, + .menu_mask = BIT_MASK(ARRAY_SIZE(power_line_frequency_controls) - 1), }, }; @@ -744,7 +745,7 @@ static const struct uvc_control_mapping uvc_ctrl_mappings_uvc15[] = { .v4l2_type = V4L2_CTRL_TYPE_MENU, .data_type = UVC_CTRL_DATA_TYPE_ENUM, .menu_info = power_line_frequency_controls, - .menu_count = ARRAY_SIZE(power_line_frequency_controls), + .menu_mask = BIT_MASK(ARRAY_SIZE(power_line_frequency_controls)), }, }; @@ -974,7 +975,9 @@ static s32 __uvc_ctrl_get_value(struct uvc_control_mapping *mapping, const struct uvc_menu_info *menu = mapping->menu_info; unsigned int i; - for (i = 0; i < mapping->menu_count; ++i, ++menu) { + for (i = 0; BIT(i) <= mapping->menu_mask; ++i, ++menu) { + if (!test_bit(i, &mapping->menu_mask)) + continue; if (menu->value == value) { value = i; break; @@ -1212,12 +1215,14 @@ static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, switch (mapping->v4l2_type) { case V4L2_CTRL_TYPE_MENU: - v4l2_ctrl->minimum = 0; - v4l2_ctrl->maximum = mapping->menu_count - 1; + v4l2_ctrl->minimum = ffs(mapping->menu_mask) - 1; + v4l2_ctrl->maximum = fls(mapping->menu_mask) - 1; v4l2_ctrl->step = 1; menu = mapping->menu_info; - for (i = 0; i < mapping->menu_count; ++i, ++menu) { + for (i = 0; BIT(i) <= mapping->menu_mask; ++i, ++menu) { + if (!test_bit(i, &mapping->menu_mask)) + continue; if (menu->value == v4l2_ctrl->default_value) { v4l2_ctrl->default_value = i; break; @@ -1338,7 +1343,7 @@ int uvc_query_v4l2_menu(struct uvc_video_chain *chain, goto done; } - if (query_menu->index >= mapping->menu_count) { + if (!test_bit(query_menu->index, &mapping->menu_mask)) { ret = -EINVAL; goto done; } @@ -1853,8 +1858,13 @@ int uvc_ctrl_set(struct uvc_fh *handle, break; case V4L2_CTRL_TYPE_MENU: - if (xctrl->value < 0 || xctrl->value >= mapping->menu_count) + if (xctrl->value < (ffs(mapping->menu_mask) - 1) || + xctrl->value > (fls(mapping->menu_mask) - 1)) return -ERANGE; + + if (!test_bit(xctrl->value, &mapping->menu_mask)) + return -EINVAL; + value = mapping->menu_info[xctrl->value].value; /* @@ -2301,7 +2311,7 @@ static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, INIT_LIST_HEAD(&map->ev_subs); - size = sizeof(*mapping->menu_info) * mapping->menu_count; + size = sizeof(*mapping->menu_info) * fls(mapping->menu_mask); map->menu_info = kmemdup(mapping->menu_info, size, GFP_KERNEL); if (map->menu_info == NULL) { kfree(map->name); diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index 9c05776f11d1..abdb9ca7eed6 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -2675,7 +2675,7 @@ static const struct uvc_control_mapping uvc_ctrl_power_line_mapping_limited = { .v4l2_type = V4L2_CTRL_TYPE_MENU, .data_type = UVC_CTRL_DATA_TYPE_ENUM, .menu_info = power_line_frequency_controls_limited, - .menu_count = ARRAY_SIZE(power_line_frequency_controls_limited), + .menu_mask = BIT_MASK(ARRAY_SIZE(power_line_frequency_controls_limited)), }; static const struct uvc_device_info uvc_ctrl_power_line_limited = { diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c index d95168cdc2d1..e6792fd46bf5 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -80,7 +80,7 @@ static int uvc_ioctl_ctrl_map(struct uvc_video_chain *chain, goto free_map; } - map->menu_count = xmap->menu_count; + map->menu_mask = BIT_MASK(xmap->menu_count); break; default: diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index 644d5fcf2eef..7e2339fc256e 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -255,7 +255,7 @@ struct uvc_control_mapping { u32 data_type; const struct uvc_menu_info *menu_info; - u32 menu_count; + unsigned long menu_mask; u32 master_id; s32 master_manual; -- b4 0.11.0-dev-d93f8