From patchwork Thu Jan 5 13:52:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 39589 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp311411wrt; Thu, 5 Jan 2023 05:57:26 -0800 (PST) X-Google-Smtp-Source: AMrXdXsuL64a4tY5NfjYY2BxZtKi13mI6wTrPAuv2GUbZ5TNTiPbLE57U6RcZ4HLMBV2kNIIu3gW X-Received: by 2002:a17:906:2859:b0:7c1:32:3574 with SMTP id s25-20020a170906285900b007c100323574mr36037431ejc.12.1672927046553; Thu, 05 Jan 2023 05:57:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672927046; cv=none; d=google.com; s=arc-20160816; b=LmezLzYHYL07grwhsU5akFp+HfPJLt8kUqDSErxl5RM2FT1mqVq21Dcz+ztU8Dde1c LOvTLC74bVw9YC7bjP8DWCL9ryEtQPm+BWFz/X8rJVBSBqkdbyqnCEmjErfZk+pj9w6o /Te9d5T55K3e+CBfqgAzosIDbhFGXZ0niDEtH3dkd/PObO2N9V93vQbHkC1V6y9XgCfQ DMi3uW/FopSr8BsRkamiW186ORiDBOUK2HclCPnD8hWImavMOtJiv1iWCVUBHcUr0TVf UvQ8PCphjIUVANm50DER5wxpuOK+jv5BORpYwNVZWxRqJq5j1pIGNLFp2jQmQQpP4QqQ YPvQ== 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=wwpb044KqtjBhtl1Bm719/ilzZh9PY8FBAW1s12for8=; b=KDE/WPpPMGFMM2gRfPlwooDAekWSnuYp3DAs3GAGjMUP2nDL4nr98yPzU6NS6xi/ep 3Qld2BkRpYI6MCELN+HdbfPeO6cpvASnXPbhKg00V+7I+6HNKis2SD86ICB30ezKCqXd 31MHlUl8c/i/7XP8M9qSdWN7qGmuYJq2eb0tX6xsimue5ZcaE+Ul+Mq/KkvzSogPoF7P qCnfYhuYa70evnanomAN3LSGnFCjHwtrjKc7j2ayQiyNMtje2c38678AXdIOW8Q4ScTR f7Crf80AJDdjBu9H1rqBmOYlWKsfbycmVMVrL5CzAxeLt+EsTRMD7YWgAGE7Ny/3WuHs vTpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ZYMrlUCb; 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 b14-20020a056402278e00b0046b2840ca3dsi36564274ede.474.2023.01.05.05.57.02; Thu, 05 Jan 2023 05:57:26 -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=ZYMrlUCb; 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 S234375AbjAEN4T (ORCPT + 99 others); Thu, 5 Jan 2023 08:56:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234498AbjAENzV (ORCPT ); Thu, 5 Jan 2023 08:55:21 -0500 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00CD34EC93 for ; Thu, 5 Jan 2023 05:53:16 -0800 (PST) Received: by mail-ej1-x62c.google.com with SMTP id x22so90154091ejs.11 for ; Thu, 05 Jan 2023 05:53:16 -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=wwpb044KqtjBhtl1Bm719/ilzZh9PY8FBAW1s12for8=; b=ZYMrlUCbRxHnFzr8zaLMwgwXxcqPD0BqE9J7pn/nLICBPF7i0mVyIBbvfhYGtrC2A3 O14lbBksh4tUrKNB5XOxv+qd7nH1vxd98bEw6gDaXz33ZfTVIcwMW/VpLCSRL1HrUlM1 ipQUqgXb6OYvSSyPMawrFEWxNv1v357UsqZvk= 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=wwpb044KqtjBhtl1Bm719/ilzZh9PY8FBAW1s12for8=; b=LQdt4WbqMkcozTjPAcNbfnF37h6/KgGMAZIMst6EfPFiKd14EIZHnvMWwuTz0N/ifS gUsvsE8UQF3HegWesTGT+SOU6SD8cdclfWgKzyrfm4XnmgoEuPiyAdV9rcVTSK+TArl1 CdUopbxmlm863KD60f6GpQwe571nD+VZCTJoJ/b7uN04cywtmjhBZExcdftl6L3Uu3Yn 7dJI7KDybabdst+0UbWu5OPihbPzAipdTwTUMKR+6vJfoxmG8xTf+arHXbN1t3PeKcLS 0NytqQ7jucapQjbxOsuY8o4G+YZXc4AKdRrFuBKgzcox59iypoDy8hsQdfRJAVFOqmJF ADQg== X-Gm-Message-State: AFqh2kqVyYewdPdExxCbCHWnURznPvjjqT9Pr+ND6YSaILAsPn61q7by RdQVoNitqgF+1om4/PU+Ay3KdA== X-Received: by 2002:a17:906:144a:b0:78d:f455:b4d5 with SMTP id q10-20020a170906144a00b0078df455b4d5mr45426428ejc.60.1672926795598; Thu, 05 Jan 2023 05:53:15 -0800 (PST) Received: from alco.roam.corp.google.com ([2620:0:1059:10:43c3:8ac4:5d6f:2251]) by smtp.gmail.com with ESMTPSA id x11-20020a170906b08b00b007806c1474e1sm16459084ejy.127.2023.01.05.05.53.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Jan 2023 05:53:15 -0800 (PST) From: Ricardo Ribalda Date: Thu, 05 Jan 2023 14:52:52 +0100 Subject: [PATCH v2 1/7] Revert "media: uvcvideo: Fix power line control for Lenovo Integrated Camera" MIME-Version: 1.0 Message-Id: <20230105-uvc-gcc5-v2-1-2ba6c660d6f5@chromium.org> References: <20230105-uvc-gcc5-v2-0-2ba6c660d6f5@chromium.org> In-Reply-To: <20230105-uvc-gcc5-v2-0-2ba6c660d6f5@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab Cc: Ricardo Ribalda , linux-media@vger.kernel.org, Yunke Cao , linux-kernel@vger.kernel.org, Sergey Senozhatsky X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=3972; i=ribalda@chromium.org; h=from:subject:message-id; bh=NB7jQ6QoKPyFq1qlyN4fB4I79KDSooYKz0aYGFsDK/0=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjttY9tEZb73sYruETdZwdLJ0gV88cNYKG1Nx86Bu1 Tu9wjCSJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY7bWPQAKCRDRN9E+zzrEiNEDD/ wPk9NdfRCdNp9BX4cKabhZGov01wsU9WYT/Z6u0I4snGVOydguAgqZC+l6W2jcfCh7GPxlXMGWtcJp OCJVoQXUVq6nMjo/nOSNr494ZGqWkesAhSKYFlpOeWw+kO2A1kR76XQj4MmK7Md5HS5VcMT22Z83Jq wwdDdmI+7cPs5Y2hLspwRKYkmOklyaaMFtzxXdfCOAfuGnkq+wrTJad49QmI3akWDQ6aCcuuO8V6DK LGOhkKae12nDmzgy8GM6cYlNoGyUgB/j5dHY6fAyF7EDBXeu2Bha0/5pxTUJ0TTTaQxZEy0OUT2J2/ 8aUrLdLyi2pwZTkDU3nGNAHFEAamVU0+xYt59OjD0LXEdEB3yRjuhhzx6PUOZ/8rS9fxT4fbqWcV/e tlVDPKzEU/eTWf8GVUZUP57ZqQuQFaSGsHl+pHjllZzeTa0wm8iZQ0BmUU1JdXQZQvoiNO83FsNVM9 Ylk1lv566KtdYjvEts50fTVIHGLscp0r/Bi5Q0h0DXdBblgl2kF+RtJuPb93vzVNy4NIxE2XFsVEin aNbkuxPjjscbGRCGsVHFkXjaMNkFYa+E0R43FfREkM3dx0QOHRKtXLqH8k2HN74RPjM92wcFwSP/aO GNIE6mpe+dlV0Yp6o1hQ7/9GpNctzQxmv9CjOWMRQl3qlfz/InfaGwakeSnA== X-Developer-Key: i=ribalda@chromium.org; a=openpgp; fpr=9EC3BB66E2FC129A6F90B39556A0D81F9F782DA9 X-Spam-Status: No, score=-0.5 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,SUBJECT_DRUG_GAP_L autolearn=no 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?1754191150492589482?= X-GMAIL-MSGID: =?utf-8?q?1754191150492589482?= This reverts commit fb1316b0ff3fc3cd98637040ee17ab7be753aac7. As today, the minimum version of GCC required to build the kernel is 5.1, which does not support static const structure initialization. Error: drivers/media/usb/uvc/uvc_ctrl.c:737:2: error: initializer element is not a compile-time constant Fixes: fb1316b0ff3f ("media: uvcvideo: Fix power line control for Lenovo Integrated Camera") Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_ctrl.c | 24 +++++++++++------------- drivers/media/usb/uvc/uvc_driver.c | 16 ---------------- drivers/media/usb/uvc/uvcvideo.h | 1 - 3 files changed, 11 insertions(+), 30 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index e07b56bbf853..06bb3822c05d 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -722,20 +722,18 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { }, }; -const struct uvc_control_mapping uvc_ctrl_power_line_mapping_uvc11 = { - .id = V4L2_CID_POWER_LINE_FREQUENCY, - .entity = UVC_GUID_UVC_PROCESSING, - .selector = UVC_PU_POWER_LINE_FREQUENCY_CONTROL, - .size = 2, - .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), -}; - static const struct uvc_control_mapping uvc_ctrl_mappings_uvc11[] = { - uvc_ctrl_power_line_mapping_uvc11, + { + .id = V4L2_CID_POWER_LINE_FREQUENCY, + .entity = UVC_GUID_UVC_PROCESSING, + .selector = UVC_PU_POWER_LINE_FREQUENCY_CONTROL, + .size = 2, + .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), + }, }; static const struct uvc_control_mapping uvc_ctrl_mappings_uvc15[] = { diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index 72c025d8e20b..2f59ee80a0af 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -2378,13 +2378,6 @@ MODULE_PARM_DESC(timeout, "Streaming control requests timeout"); * Driver initialization and cleanup */ -static const struct uvc_device_info uvc_ctrl_power_line_uvc11 = { - .mappings = (const struct uvc_control_mapping *[]) { - &uvc_ctrl_power_line_mapping_uvc11, - NULL, /* Sentinel */ - }, -}; - static const struct uvc_menu_info power_line_frequency_controls_limited[] = { { 1, "50 Hz" }, { 2, "60 Hz" }, @@ -2988,15 +2981,6 @@ static const struct usb_device_id uvc_ids[] = { .bInterfaceSubClass = 1, .bInterfaceProtocol = 0, .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_FORCE_BPP) }, - /* Lenovo Integrated Camera */ - { .match_flags = USB_DEVICE_ID_MATCH_DEVICE - | USB_DEVICE_ID_MATCH_INT_INFO, - .idVendor = 0x30c9, - .idProduct = 0x0093, - .bInterfaceClass = USB_CLASS_VIDEO, - .bInterfaceSubClass = 1, - .bInterfaceProtocol = UVC_PC_PROTOCOL_15, - .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_uvc11 }, /* Sonix Technology USB 2.0 Camera */ { .match_flags = USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_INT_INFO, diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index ae0066eceffd..a8eec43cd860 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -747,7 +747,6 @@ int uvc_status_start(struct uvc_device *dev, gfp_t flags); void uvc_status_stop(struct uvc_device *dev); /* Controls */ -extern const struct uvc_control_mapping uvc_ctrl_power_line_mapping_uvc11; extern const struct v4l2_subscribed_event_ops uvc_ctrl_sub_ev_ops; int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, From patchwork Thu Jan 5 13:52:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 39592 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp311606wrt; Thu, 5 Jan 2023 05:58:02 -0800 (PST) X-Google-Smtp-Source: AMrXdXuqXXk63VjIvHA4KqVsReHkQvmprIhpLWLiKTBw6PX476b2d8l55VOq9DtlBOR9MdentmSe X-Received: by 2002:a17:906:f250:b0:7c1:528:bc02 with SMTP id gy16-20020a170906f25000b007c10528bc02mr44496742ejb.41.1672927081841; Thu, 05 Jan 2023 05:58:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672927081; cv=none; d=google.com; s=arc-20160816; b=LjwCpeoKzAEqIU2GDc7kFa/hC/Cw47d60gneea+QntWu2kkMGE/6Xx5HNfPD1sAjKr mJMbj2G1aWHCLibhpbbECe30kkrkPWErErURbWy3rindiyhc0OvaKynoESyD4MZLX9Z5 L3yVlby8qJl4TaEbrav2YpuC/lSr0Tzy3jMm5wfLBi8YMstV0u0x2QA7086MSEOgyRxd FywGcT1MeJ/mvgVs5ee6o93TWWwrMJCjv0vhDXAc4CNK930UEhb/vOIJVk07koV7wOYX XHYNqNuBn2zIxaQdDEj+LSFeWDmqkH8HIAj/EG9lK6QMyPL9CE7xtciqu6yZRUyFN1fw hLVQ== 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=KBGZezEaxNT5mYG63q3/p+giIEe5CEbFfULH3PLbvPA=; b=RUFBVtjmgnxe3K7L93CScUTb1MTvnAkPFQn/r+UayM2rsXGaaftpCQHldlhat3CpOO apE002cgdE1nCYYCQBQHWQyIj5eHqteAsENXFm8UAR4y8gd61300gcWyMrjk2FHq8leX Xd0GOiNPXItPdGosfzMbWhN4GGkCV5szQpTqEGvePgXKZOOgYk4IJAKqrbq17S3FrRgr SfI9VxhnlET13YJBzU8f9Lx85XwKHVWHusRjw2A/ckhri0GAuRjm8JtYDgXlFsX1/1l5 Qb80Ua4yz+iMDPq8vjcXtykASyiQk0XhDcx1Nyeg+NbStC9wYS+RKelz/H6ue0VURLef kTUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ha7nB7dh; 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 gb19-20020a170907961300b00781dbee4273si33209161ejc.514.2023.01.05.05.57.37; Thu, 05 Jan 2023 05:58:01 -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=ha7nB7dh; 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 S233829AbjAEN4i (ORCPT + 99 others); Thu, 5 Jan 2023 08:56:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233981AbjAENzZ (ORCPT ); Thu, 5 Jan 2023 08:55:25 -0500 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E37004F112 for ; Thu, 5 Jan 2023 05:53:17 -0800 (PST) Received: by mail-ej1-x62e.google.com with SMTP id u19so90160949ejm.8 for ; Thu, 05 Jan 2023 05:53:17 -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=KBGZezEaxNT5mYG63q3/p+giIEe5CEbFfULH3PLbvPA=; b=ha7nB7dh6AnVB76mhxbhh8HsobWs10km0yuGl0mjt61iw/Jhi8PZMlYOCu/9JSMmX9 POoBzUiMatfNKMspA9cO4CK5YVWziEvrWVf116/aoxoFEMD/eRNA3QXqvJN8iYYh9RX9 JOvqsmVAsPri4qiAQlfYUBfivizvECC7J2qtk= 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=KBGZezEaxNT5mYG63q3/p+giIEe5CEbFfULH3PLbvPA=; b=5pitkCk1BbqhkbEpCWA62howj0bmOtUVannaJV1t9plfwK3gtVouwRYWIDZ0sYKsE3 kweQTS7rcO/9G2BuuEnmmpxz2WsQNPsPZkr8YjZLigYGIkrXZPRT0bYfitjjHu5dNUcz YD5V1kahHjszTmT+fwZHREG3l4oYW1DsnnaZ6zSB6AJLCtRDrCT5D7UKRV+uNks4lXEf /4T5Ryevv/yyxk+xU0WQDoWD6Pzei+JkDntcf8xGtHgaGOn9WOjlwL3m+41II7SMz3y6 +RL1n0Sz4lTlkfEOOUoOtHWV0mdgVVJ4u1s6V9fc4m08iZ4V7j8gOfNhMLJBmYVi6SkD xyBg== X-Gm-Message-State: AFqh2kq8jbPFoUVvyxS8UrWYMgkc2mLsjqB+a+jeKnDLbcC3On87Egte mxiWDfoDND9ICLEURIc6CfJ48D19wl0K/0UsI/A= X-Received: by 2002:a17:907:d50e:b0:7b1:316c:38f5 with SMTP id wb14-20020a170907d50e00b007b1316c38f5mr45507481ejc.30.1672926796528; Thu, 05 Jan 2023 05:53:16 -0800 (PST) Received: from alco.roam.corp.google.com ([2620:0:1059:10:43c3:8ac4:5d6f:2251]) by smtp.gmail.com with ESMTPSA id x11-20020a170906b08b00b007806c1474e1sm16459084ejy.127.2023.01.05.05.53.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Jan 2023 05:53:16 -0800 (PST) From: Ricardo Ribalda Date: Thu, 05 Jan 2023 14:52:53 +0100 Subject: [PATCH v2 2/7] Revert "media: uvcvideo: Implement mask for V4L2_CTRL_TYPE_MENU" MIME-Version: 1.0 Message-Id: <20230105-uvc-gcc5-v2-2-2ba6c660d6f5@chromium.org> References: <20230105-uvc-gcc5-v2-0-2ba6c660d6f5@chromium.org> In-Reply-To: <20230105-uvc-gcc5-v2-0-2ba6c660d6f5@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab Cc: Ricardo Ribalda , linux-media@vger.kernel.org, Yunke Cao , linux-kernel@vger.kernel.org, Sergey Senozhatsky X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=6121; i=ribalda@chromium.org; h=from:subject:message-id; bh=Bll6tbezraJ/a0Cf4Y3tLo27i37SeM2dqnIYPB0QUok=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjttY/b7bCcBop5GwSyb/1YFamleXQAd6qIqP2JHx1 qY7UH0qJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY7bWPwAKCRDRN9E+zzrEiHayEA Cfi85jtOUubPwcJiNUckr9rdVK9KWxh04irky5T/yMtCiLB4GCzJnrrCg1ZFv9Y2c5avnu05kOJvy0 fR2Bq3EQ3i9lZs1ZLq2OD2DLCDD+9KQwHWY/kwY8ixEfYflFKk6mm/VO27RtbDwPHT/1kQuuCmRPUU MXI91USBrnGJBsbvDxOLN4OFwkXAK6Bfarfw+/N5b6rOwf0K+BJzHfl9TS0cmUAQDOaQXp6Zp6OJuG pt3Az/NbbSKFL8TEF/dSOHg4RuREm4i/qZvy0KtT/OzJzbI1mrCVXW4/DvyarOPUqox4MRq5cjvmXY GeesdEKfDgQOSiBXOzjfGu8k8E7bAvv0gYD+Vbv0diRj/UPvqWGAas5pVe1jrS6MkbXlZQ6GfgkeWi z9F4Ev5liP+aVJSj20jqhCFgQFkFkCGp182BQ9sN4hTyXzox9zWCjkXkDj7PQ6RoV2SdhFX30IMXq1 GZ+Rw6bhbCLQ+b52X/o+s6Nsp4ELUKksGvk6VGxxEIOtA9v9szJab6LbLXgEWIUfQ5j8dkPdWFlmZZ maQkb9c97wVmA76INBqtdu0UyUBzWcT7J7O88XTBZErcVGbSzz0JfbHDv9TqxRHY6AidbwF3aZcyCz gvnySmUumXriNVIXQ8CoTa/49uFa+kqPwMdaYGIkrAURho74BesR+G5E39vQ== 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?1754191187390684146?= X-GMAIL-MSGID: =?utf-8?q?1754191187390684146?= This reverts commit 2ada36ecf16dcd32b56554f01ce38f273bc16efc. BIT_MASK is nothing more than BIT(). Fixes: 2ada36ecf16d ("media: uvcvideo: Implement mask for V4L2_CTRL_TYPE_MENU") Signed-off-by: Ricardo Ribalda --- 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, 13 insertions(+), 25 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 06bb3822c05d..ffa0e2654264 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -6,7 +6,6 @@ * Laurent Pinchart (laurent.pinchart@ideasonboard.com) */ -#include #include #include #include @@ -526,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_mask = BIT_MASK(ARRAY_SIZE(exposure_auto_controls)), + .menu_count = ARRAY_SIZE(exposure_auto_controls), .slave_ids = { V4L2_CID_EXPOSURE_ABSOLUTE, }, }, { @@ -732,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_mask = BIT_MASK(ARRAY_SIZE(power_line_frequency_controls) - 1), + .menu_count = ARRAY_SIZE(power_line_frequency_controls) - 1, }, }; @@ -746,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_mask = BIT_MASK(ARRAY_SIZE(power_line_frequency_controls)), + .menu_count = ARRAY_SIZE(power_line_frequency_controls), }, }; @@ -976,9 +975,7 @@ 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; BIT(i) <= mapping->menu_mask; ++i, ++menu) { - if (!test_bit(i, &mapping->menu_mask)) - continue; + for (i = 0; i < mapping->menu_count; ++i, ++menu) { if (menu->value == value) { value = i; break; @@ -1231,14 +1228,12 @@ static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, switch (mapping->v4l2_type) { case V4L2_CTRL_TYPE_MENU: - v4l2_ctrl->minimum = ffs(mapping->menu_mask) - 1; - v4l2_ctrl->maximum = fls(mapping->menu_mask) - 1; + v4l2_ctrl->minimum = 0; + v4l2_ctrl->maximum = mapping->menu_count - 1; v4l2_ctrl->step = 1; menu = mapping->menu_info; - for (i = 0; BIT(i) <= mapping->menu_mask; ++i, ++menu) { - if (!test_bit(i, &mapping->menu_mask)) - continue; + for (i = 0; i < mapping->menu_count; ++i, ++menu) { if (menu->value == v4l2_ctrl->default_value) { v4l2_ctrl->default_value = i; break; @@ -1359,7 +1354,7 @@ int uvc_query_v4l2_menu(struct uvc_video_chain *chain, goto done; } - if (!test_bit(query_menu->index, &mapping->menu_mask)) { + if (query_menu->index >= mapping->menu_count) { ret = -EINVAL; goto done; } @@ -1873,13 +1868,8 @@ int uvc_ctrl_set(struct uvc_fh *handle, break; case V4L2_CTRL_TYPE_MENU: - if (xctrl->value < (ffs(mapping->menu_mask) - 1) || - xctrl->value > (fls(mapping->menu_mask) - 1)) + if (xctrl->value < 0 || xctrl->value >= mapping->menu_count) return -ERANGE; - - if (!test_bit(xctrl->value, &mapping->menu_mask)) - return -EINVAL; - value = mapping->menu_info[xctrl->value].value; /* @@ -2316,7 +2306,7 @@ static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, INIT_LIST_HEAD(&map->ev_subs); - size = sizeof(*mapping->menu_info) * fls(mapping->menu_mask); + size = sizeof(*mapping->menu_info) * mapping->menu_count; map->menu_info = kmemdup(mapping->menu_info, size, GFP_KERNEL); if (!map->menu_info) goto err_nomem; diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index 2f59ee80a0af..6d08457ecb9c 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -7,7 +7,6 @@ */ #include -#include #include #include #include @@ -2392,7 +2391,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_mask = BIT_MASK(ARRAY_SIZE(power_line_frequency_controls_limited)), + .menu_count = 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 ed2525e7e2a5..3edb54c086b2 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -6,7 +6,6 @@ * Laurent Pinchart (laurent.pinchart@ideasonboard.com) */ -#include #include #include #include @@ -81,7 +80,7 @@ static int uvc_ioctl_ctrl_map(struct uvc_video_chain *chain, goto free_map; } - map->menu_mask = BIT_MASK(xmap->menu_count); + map->menu_count = xmap->menu_count; break; default: diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index a8eec43cd860..41ba0bbd8171 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -115,7 +115,7 @@ struct uvc_control_mapping { u32 data_type; const struct uvc_menu_info *menu_info; - unsigned long menu_mask; + u32 menu_count; u32 master_id; s32 master_manual; From patchwork Thu Jan 5 13:52:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 39588 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp311407wrt; Thu, 5 Jan 2023 05:57:26 -0800 (PST) X-Google-Smtp-Source: AMrXdXvDSlstdWRQ1XaaCIoz2EYuqfE2sIBkPpixplGtBlhlDk4d0rCuPy8/jeNYelFmV557jhWW X-Received: by 2002:a17:906:edd6:b0:84d:138a:316 with SMTP id sb22-20020a170906edd600b0084d138a0316mr988249ejb.36.1672927046191; Thu, 05 Jan 2023 05:57:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672927046; cv=none; d=google.com; s=arc-20160816; b=cuJSmOsX1rTyx6SwEKHk4l0ocOvdYuLQWWZk9vLqjRrwnVqc7lvfE70HFkUCuzs5sj lJWXO6Nfm3qrTurm5JdYIY+3oeTX9mFjNwZbE2Gs1mzYrLJYKxNI8N9TuOT7Qo74FLZo xrc2Kgrew57jDbF/1eY9L2TdiwX2NhXL1QWs2hxmNNboxFOAtSSCs9VWPZsY+73DMBKZ Ql7igdF9u9CLPgf61IlPoH5BMIVnNKbDTJMzAI3BqGK/db6NpSpEpj1UKj1DhXCaEpN3 rbMiLuoRryahwNwmxwgZyrzYmUkpuqIX4ovHSRwA8eWlunseRF0IfqXMhAHO0TYnYBys FLSg== 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=i22sBtg5sgJPjmyCPs4YT31o+9MgBiTxsORfyqFHwvE=; b=f+I/XPUAnui2rZZgvIocWt2kq2QfSxO96zKFnCQ4T1izxdLjkJoJBB7Fi9/Cgxv2Lr 7wpZ/bsORcSZrYHPSBrKJrl8C406rgK5kuBxC4eyXB97IHtGIlK9z0fX/TH7DFrr6wkx Fgaj+zKHaYtkinMZIfqBx670NTpaJWQxJP6ad1Aizt2eNYX+cg9nlPZCEcryBQqxbAu3 uMG7S7sg93c7yZOgzuxxPU+v4DFlgF7qdusxr3T9YQM+vgQOezrM4Y0mPlMZcn7zGd+8 L5gea582i5SVwJt0bayDr1WDC8MWwUVnfIGO3oK387/kVyWpCOVIOZv/5+phh9J5/m2+ 9T6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=TivNd1L3; 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 un2-20020a170907cb8200b007ade4c97618si28014368ejc.930.2023.01.05.05.57.02; Thu, 05 Jan 2023 05:57:26 -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=TivNd1L3; 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 S234588AbjAEN4Y (ORCPT + 99 others); Thu, 5 Jan 2023 08:56:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234510AbjAENzW (ORCPT ); Thu, 5 Jan 2023 08:55:22 -0500 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B39614F119 for ; Thu, 5 Jan 2023 05:53:18 -0800 (PST) Received: by mail-ej1-x62f.google.com with SMTP id m18so90017241eji.5 for ; Thu, 05 Jan 2023 05:53:18 -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=i22sBtg5sgJPjmyCPs4YT31o+9MgBiTxsORfyqFHwvE=; b=TivNd1L3MetgrHzNbzrqF6gsxMkFN+oRpnymkK0S9KBqugBCT7Tx3zd4VLTYoj8VJS kb1DJ3+wEMtRymOQnMfKO2bh9xPMNKt+rsmrP9ipHYKnp5in1/euDOO/yNMGI4zln7aH KLoesQ4J+7t4AFidOICzHCQGyAP4MgThHrlz0= 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=i22sBtg5sgJPjmyCPs4YT31o+9MgBiTxsORfyqFHwvE=; b=AYgYqf20uga6m0OjZmj5TMLgVl3zP5uKAEM4uSzFYPG4+SVXparVEo02NhNumkiIG8 +heK4J8ZQTKrGhH4GeJDvILpbM1qWTWuLZXnWl8vyutYZpNM3qLhvknajD5M6duuIoKn czgkmAsiVCK7vU9lBIODI9or0hbkPDRqfL/TOwfKPp4+YqktRYZpreA49xEK8XIciWVP r7jimxVd7B+H5vdn8gy/Ygv20hg1BcSLrnVq3UvkRqEeK9TG0v1ySLxMAtYYittAywFo 0ZmNLJ5OXXti2dmNuHysAX7iH/P9s+lTo+0ReQl2/fbbO/ycL5abILHzU9XazTmAyizS +QaA== X-Gm-Message-State: AFqh2kqexFUThFER8+O1yhW7m1+qeVG6+8Z7PsVTMkOGnyY410+PXuxG i/3vKP6hKjK4oSQ111s19kq3XA== X-Received: by 2002:a17:907:6d0c:b0:7c1:652:d109 with SMTP id sa12-20020a1709076d0c00b007c10652d109mr52072097ejc.35.1672926797359; Thu, 05 Jan 2023 05:53:17 -0800 (PST) Received: from alco.roam.corp.google.com ([2620:0:1059:10:43c3:8ac4:5d6f:2251]) by smtp.gmail.com with ESMTPSA id x11-20020a170906b08b00b007806c1474e1sm16459084ejy.127.2023.01.05.05.53.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Jan 2023 05:53:17 -0800 (PST) From: Ricardo Ribalda Date: Thu, 05 Jan 2023 14:52:54 +0100 Subject: [PATCH v2 3/7] media: uvcvideo: Implement mask for V4L2_CTRL_TYPE_MENU MIME-Version: 1.0 Message-Id: <20230105-uvc-gcc5-v2-3-2ba6c660d6f5@chromium.org> References: <20230105-uvc-gcc5-v2-0-2ba6c660d6f5@chromium.org> In-Reply-To: <20230105-uvc-gcc5-v2-0-2ba6c660d6f5@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab Cc: Ricardo Ribalda , linux-media@vger.kernel.org, Yunke Cao , linux-kernel@vger.kernel.org, Sergey Senozhatsky X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=6328; i=ribalda@chromium.org; h=from:subject:message-id; bh=c0qCW+bmUSyESwPogSJMQMg1NsP7nOLTyNEVHbIZYzQ=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjttZAEklFRkFOGUsnQefFhlT5IB3ZM/mBPIRcA6kM rXJNK7aJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY7bWQAAKCRDRN9E+zzrEiAfBEA CQNUUXxTzxVcBAMm8hAnHAajrQRxKGBvD7aTNdAAikwRG6xuy9/0e11wWC1kb0thvwsOcQDim4+hEy USQ0jCMMpObC1coBPBRw0CMLe9sfpia1yPvVqbjpSsCiO3bkAKnpnTTiX8THH0bOrUVL2z47SIOJHj Azvg4br79VefCqsK2u8XLEH6PiI7ltxjYnhJ6fXnvmLBZhroVd6Bcc5I3txQNaO3WmzP86Oceq8aP4 vf06CVwUi8oSWQiI5Am9B7Z/V4Wc2odJW71ADi6L1GyX2NyEOMmYdGA20df996MUcpYQrUM3LEhoGA JTg21NYE4f6xNHCzOKzP0KShstF5eUHIU4lsdPOWBFWeuQDh7+GlFj1nDQxu8Y8pDXF0mtEcGeYy21 PTwxe00XouzV3yTgN3CVSpU5ouNSo4I0XS4Oe1UAxc12KqYJEwiUMEPFsz/Y933DGbsgLzaIvkqI7H 2BH0ycEd+1ffu8/9n4dxJ76qiUUh8GbJO8rK2U5Tp2vDZbmVBwmygEpj/UeNQaF8rM/maoDQmXhDRk cfzlniiHHpXuKweUWv7/bPRkRU9GdmQ6HLD1sQALiULmh1pvsNPot1m8HNswrvFg5mmW3dIcgnC6J9 gyuQiPtZNH0veMEWueeaINv1+UXdZdq9rllEtGnCLVc83NrssSGlQQ7DISqg== 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?1754191150509371788?= X-GMAIL-MSGID: =?utf-8?q?1754191150509371788?= 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 | 33 +++++++++++++++++++++++---------- drivers/media/usb/uvc/uvc_driver.c | 4 +++- drivers/media/usb/uvc/uvc_v4l2.c | 3 ++- drivers/media/usb/uvc/uvcvideo.h | 2 +- 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index ffa0e2654264..2ebe5cc18ad9 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,8 @@ 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 = + GENMASK(ARRAY_SIZE(exposure_auto_controls) - 1, 0), .slave_ids = { V4L2_CID_EXPOSURE_ABSOLUTE, }, }, { @@ -731,7 +733,8 @@ 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 = GENMASK(V4L2_CID_POWER_LINE_FREQUENCY_60HZ, + V4L2_CID_POWER_LINE_FREQUENCY_DISABLED), }, }; @@ -745,7 +748,8 @@ 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 = GENMASK(V4L2_CID_POWER_LINE_FREQUENCY_AUTO, + V4L2_CID_POWER_LINE_FREQUENCY_DISABLED), }, }; @@ -975,7 +979,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 +1234,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 +1362,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 +1876,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; /* @@ -2306,7 +2319,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) goto err_nomem; diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index 6d08457ecb9c..e659670ea2d8 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 @@ -2391,7 +2392,8 @@ 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 = + GENMASK(ARRAY_SIZE(power_line_frequency_controls_limited) - 1, 0), }; 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..0774a11360c0 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 = GENMASK(xmap->menu_count - 1, 0); break; default: diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index 41ba0bbd8171..a8eec43cd860 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -115,7 +115,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 Thu Jan 5 13:52:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 39594 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp311636wrt; Thu, 5 Jan 2023 05:58:07 -0800 (PST) X-Google-Smtp-Source: AMrXdXsGgXorexHphbrdaFiMnQR5M8EvdPsrt/hiukqVCWF/0eD67chGSs8j8HiTFoQgsJj2Ygv6 X-Received: by 2002:a17:906:d0d0:b0:7c1:23f2:5b51 with SMTP id bq16-20020a170906d0d000b007c123f25b51mr50017517ejb.60.1672927087802; Thu, 05 Jan 2023 05:58:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672927087; cv=none; d=google.com; s=arc-20160816; b=MXBrTuCMa4YKJgnRDPogalwWn8lO+zqh4L7lhTWKl7wFA7WRRCDN+STyEq74EPzFiy 5eSV9obxsI1z+TCKPgtloRfD6jTdk0ogQIKrEo5HGlEsDiVikEoATn4du1UU02iR1XWw CFaxBi5wvA1Df0AqI0g/M4F+ckXPbq4Yk9MNFIkt9fRMn/vG6s1kxcCF3520Y5RfznWC hVd2zFNPko+g3BX8qUyV1l+RwpSSr/PPV4zLz7aiq97IhMYSq8N2dOMPGRwD0/Y6lGaG 6yJRjpPUKorn7JpP5Sg1+3kzsjPYoHrZl+fzD/fDfQJdW0cjjquM+0tzZ596JldqBLFK G7Mw== 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=T2+QEDBh605/YOw8UIx/peFMX1PrmbZbNImTnYA7xrk=; b=uZAuS19aFaPE5tyK62KB6YLp6kJa/5SqgF9evNFLQkgVHegpPn8gACI+XQdiUECqZn fTxQNkCyuXuwvFCcp2G62jE7w5xL+UpVCSqzKoPxBl7lq8R2s0eCxTaTlN+y98Js5Om/ vbKr1PmNpxwXwZc6bXOHFTARaIgYupmgdA+Zdmf96QkOELq3xlL3aKHeyMfVZ2rr0hPF voua7NJefPxjbeic8AwMKvn1o7TK+jWpKOZEqJRA5IE+pAOtJDSBYF/rcW+yBc15DHXx DjUJz7VasC10uj3dRS5Y/ioTJXrlo3SWItPkpXTt3le8oPNMbV2mrzA+TI9RQgbAdUOL TrIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Pa8qDTnm; 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 sc27-20020a1709078a1b00b0078dfe6dc4d2si35445949ejc.33.2023.01.05.05.57.44; Thu, 05 Jan 2023 05:58:07 -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=Pa8qDTnm; 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 S234012AbjAEN4t (ORCPT + 99 others); Thu, 5 Jan 2023 08:56:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233905AbjAENz0 (ORCPT ); Thu, 5 Jan 2023 08:55:26 -0500 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 868324FCF1 for ; Thu, 5 Jan 2023 05:53:19 -0800 (PST) Received: by mail-ej1-x634.google.com with SMTP id qk9so90027496ejc.3 for ; Thu, 05 Jan 2023 05:53:19 -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=T2+QEDBh605/YOw8UIx/peFMX1PrmbZbNImTnYA7xrk=; b=Pa8qDTnmM4CCZR9hDOxE4L6eQlUqS3whJeBbol8B3ZfCp0ImrDG85CGnDNMkWLUpEI cyeAmbrjGIVDCHgCFDebWET990dzSJ0Od2LAi4tuJ9R4syhOMLeUq2Hzrvwppn1SpMeU qII00JtWfSY/QW9qCfuwpoznDMM8arRdvSC7U= 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=T2+QEDBh605/YOw8UIx/peFMX1PrmbZbNImTnYA7xrk=; b=X+BcAStglXKxK2xOGe2W2UGzKSSBCQYzCBbxW4F+99UYQlZwcPru6P32k1vnu8iJ2v VRS+DGaVAfyrYsN0mZrfi7VEX1edN1TiHJZ2K5KQDFkiKxq/lq/A5mgsPCLqM9OEMBYV tNoPtgmVexN+KAcW5LF178NkHZs9gPCAghPpkUU5rqfFpk0z/HBylepWEfan2A7Wp808 scophMkFhQbLDZIr0Vzh/W5CWH1GqB8ffWy4FWGLWEmqi3Saa93BXryO4q9OVmQOu27H N4ijaq65/T2iEY1X9THD4YaevQMKUiCeKRPuknh3yv0+WdCBgxKd7sfMaodygGlq12/5 WivQ== X-Gm-Message-State: AFqh2kpUJWskv0vr3AIDJJcws7IQtd0nX58plu6yvkDcAWbqyKz7dDtD B9Pv40sFySspBtIUm3PJhg3gaCUJ7MEmsK/VGEw= X-Received: by 2002:a17:906:309a:b0:819:7d8f:9684 with SMTP id 26-20020a170906309a00b008197d8f9684mr48271943ejv.72.1672926798078; Thu, 05 Jan 2023 05:53:18 -0800 (PST) Received: from alco.roam.corp.google.com ([2620:0:1059:10:43c3:8ac4:5d6f:2251]) by smtp.gmail.com with ESMTPSA id x11-20020a170906b08b00b007806c1474e1sm16459084ejy.127.2023.01.05.05.53.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Jan 2023 05:53:17 -0800 (PST) From: Ricardo Ribalda Date: Thu, 05 Jan 2023 14:52:55 +0100 Subject: [PATCH v2 4/7] media: uvcvideo: Refactor uvc_ctrl_mappings_uvcXX MIME-Version: 1.0 Message-Id: <20230105-uvc-gcc5-v2-4-2ba6c660d6f5@chromium.org> References: <20230105-uvc-gcc5-v2-0-2ba6c660d6f5@chromium.org> In-Reply-To: <20230105-uvc-gcc5-v2-0-2ba6c660d6f5@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab Cc: Ricardo Ribalda , linux-media@vger.kernel.org, Yunke Cao , linux-kernel@vger.kernel.org, Sergey Senozhatsky X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=4328; i=ribalda@chromium.org; h=from:subject:message-id; bh=cN0QwI5lzK55LyNPAeknpt5DPiDQGV+bwKxrSvbPPOE=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjttZBNkD4q+2Q7aefxS41plv3QM7InsrCrV9PyINO S37kWQ6JAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY7bWQQAKCRDRN9E+zzrEiKLED/ wP0Bkdbhq0lYQCguiYJa2kj8DafZ76fY4GvBAhUIgt0QafUiP5D83pWTopu5h4w5kn4ihLpPnEhS5C HSzWN7+4sYdKqQED7wzOnmqF3H+LJrXKWBFwGk1ovLtWzf/0jz6L7dQPCi8QKdr1jjIKgFSk5/29gH lHLn5pnvAyvNvIl2iLg84a7kr6RaC9leFxadw3WJOG1Q6lweQTkBJxzquoJ2ikabUVlMqy11TY6GIe HYWM0ybYUmo9RkwdzdyGyq7HIk7d0oUpJ942htp55+ShGuTozFuZvuPZWGZgVs1UzyzKdAPYzDXTb+ bSroRm0nigqHUznxLrTJJffQB0jNnHA/T5YZ0OuBJl7ibSjXwCMeId8ChV7K1/NuxMYcrd6AMqSFmS qXRAIpGq/bnwZfLfNy8BsutnL+vlbEKPNb5ibpSkbdhll5MTktixKn7VqATc607KpSHA5JBbf35eag KE6GSv2hfvJt7aBvFY3177OfFi9w8i2qT8s3CvRsgjgy2hsnb6E8q0SWEl2CncPyRjZqSJK8Zk6sua RyxU6u1WxaJvdOVzCvlxfBuiwsUCJNubBJmkGm9tRNuKHU+6hdBYfaE29NHvtB2//aGbHUVqEHLLFG NJ8anavt6VS7i3oI2IzhHWQaRYuuFOwWCCi6oRFRmdmVmQm6CNGISuWdXyYA== 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?1754191193929272132?= X-GMAIL-MSGID: =?utf-8?q?1754191193929272132?= Convert the array of structs into an array of pointers, that way the mappings can be reused. Signed-off-by: Ricardo Ribalda Reviewed-by: Laurent Pinchart --- drivers/media/usb/uvc/uvc_ctrl.c | 81 +++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 42 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 2ebe5cc18ad9..9af64f7a23d3 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -723,34 +723,40 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { }, }; -static const struct uvc_control_mapping uvc_ctrl_mappings_uvc11[] = { - { - .id = V4L2_CID_POWER_LINE_FREQUENCY, - .entity = UVC_GUID_UVC_PROCESSING, - .selector = UVC_PU_POWER_LINE_FREQUENCY_CONTROL, - .size = 2, - .offset = 0, - .v4l2_type = V4L2_CTRL_TYPE_MENU, - .data_type = UVC_CTRL_DATA_TYPE_ENUM, - .menu_info = power_line_frequency_controls, - .menu_mask = GENMASK(V4L2_CID_POWER_LINE_FREQUENCY_60HZ, - V4L2_CID_POWER_LINE_FREQUENCY_DISABLED), - }, +static const struct uvc_control_mapping uvc_ctrl_power_line_mapping_uvc11 = { + .id = V4L2_CID_POWER_LINE_FREQUENCY, + .entity = UVC_GUID_UVC_PROCESSING, + .selector = UVC_PU_POWER_LINE_FREQUENCY_CONTROL, + .size = 2, + .offset = 0, + .v4l2_type = V4L2_CTRL_TYPE_MENU, + .data_type = UVC_CTRL_DATA_TYPE_ENUM, + .menu_info = power_line_frequency_controls, + .menu_mask = GENMASK(V4L2_CID_POWER_LINE_FREQUENCY_60HZ, + V4L2_CID_POWER_LINE_FREQUENCY_DISABLED), }; -static const struct uvc_control_mapping uvc_ctrl_mappings_uvc15[] = { - { - .id = V4L2_CID_POWER_LINE_FREQUENCY, - .entity = UVC_GUID_UVC_PROCESSING, - .selector = UVC_PU_POWER_LINE_FREQUENCY_CONTROL, - .size = 2, - .offset = 0, - .v4l2_type = V4L2_CTRL_TYPE_MENU, - .data_type = UVC_CTRL_DATA_TYPE_ENUM, - .menu_info = power_line_frequency_controls, - .menu_mask = GENMASK(V4L2_CID_POWER_LINE_FREQUENCY_AUTO, - V4L2_CID_POWER_LINE_FREQUENCY_DISABLED), - }, +static const struct uvc_control_mapping *uvc_ctrl_mappings_uvc11[] = { + &uvc_ctrl_power_line_mapping_uvc11, + NULL, /* Sentinel */ +}; + +static const struct uvc_control_mapping uvc_ctrl_power_line_mapping_uvc15 = { + .id = V4L2_CID_POWER_LINE_FREQUENCY, + .entity = UVC_GUID_UVC_PROCESSING, + .selector = UVC_PU_POWER_LINE_FREQUENCY_CONTROL, + .size = 2, + .offset = 0, + .v4l2_type = V4L2_CTRL_TYPE_MENU, + .data_type = UVC_CTRL_DATA_TYPE_ENUM, + .menu_info = power_line_frequency_controls, + .menu_mask = GENMASK(V4L2_CID_POWER_LINE_FREQUENCY_AUTO, + V4L2_CID_POWER_LINE_FREQUENCY_DISABLED), +}; + +static const struct uvc_control_mapping *uvc_ctrl_mappings_uvc15[] = { + &uvc_ctrl_power_line_mapping_uvc15, + NULL, /* Sentinel */ }; /* ------------------------------------------------------------------------ @@ -2506,8 +2512,7 @@ static void uvc_ctrl_prune_entity(struct uvc_device *dev, static void uvc_ctrl_init_ctrl(struct uvc_video_chain *chain, struct uvc_control *ctrl) { - const struct uvc_control_mapping *mappings; - unsigned int num_mappings; + const struct uvc_control_mapping **mappings; unsigned int i; /* @@ -2574,21 +2579,13 @@ static void uvc_ctrl_init_ctrl(struct uvc_video_chain *chain, } /* Finally process version-specific mappings. */ - if (chain->dev->uvc_version < 0x0150) { - mappings = uvc_ctrl_mappings_uvc11; - num_mappings = ARRAY_SIZE(uvc_ctrl_mappings_uvc11); - } else { - mappings = uvc_ctrl_mappings_uvc15; - num_mappings = ARRAY_SIZE(uvc_ctrl_mappings_uvc15); - } - - for (i = 0; i < num_mappings; ++i) { - const struct uvc_control_mapping *mapping = &mappings[i]; + mappings = (chain->dev->uvc_version < 0x0150) ? uvc_ctrl_mappings_uvc11 + : uvc_ctrl_mappings_uvc15; - if (uvc_entity_match_guid(ctrl->entity, mapping->entity) && - ctrl->info.selector == mapping->selector) - __uvc_ctrl_add_mapping(chain, ctrl, mapping); - } + for (i = 0; mappings[i]; ++i) + if (uvc_entity_match_guid(ctrl->entity, mappings[i]->entity) && + ctrl->info.selector == mappings[i]->selector) + __uvc_ctrl_add_mapping(chain, ctrl, mappings[i]); } /* From patchwork Thu Jan 5 13:52:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 39590 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp311574wrt; Thu, 5 Jan 2023 05:57:58 -0800 (PST) X-Google-Smtp-Source: AMrXdXu3ELTmqYOKBKUmzIFIF32mfP7QubvJRXtY00OjWSppfBCR5muCQtsdrScT5CVFVZwQeUfA X-Received: by 2002:aa7:da42:0:b0:46c:2034:f481 with SMTP id w2-20020aa7da42000000b0046c2034f481mr54002751eds.8.1672927077922; Thu, 05 Jan 2023 05:57:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672927077; cv=none; d=google.com; s=arc-20160816; b=nfFWvQu5O3DXT4i+zGR286N+7h7ZQPV3ixCRFyylrvIAojYs/3hHlvvY19AXZm0Ef7 mZ3pi+s2pYhzqTf/414dMVMVVFCTYaBPPMOT2VRII9fvJ6UTUXz+W6Qp2iImaqpelfX+ E5latJa6WZnRnwEpyBOUTC53IW+jM9AnJQGaBuls0Cuwke4dfUCb/sDobSxOkuKxkt28 0tmX6pkV6vhp/Y9HkvTmCFJPB8uM8+kZhO/G7yLtXWvxnzIGbM1Ka9WDa8Oz5PzGDQke oY6pFbOyPfYr26GcAERfU3ra/GN28AnyILC5wCTQD7FEF9gFYNLKm41VcnRt56goeAcU c7Dw== 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=2RMA+soBb7ISYDgZGukscenX9Gq6ESDTcYuOQgtCRPU=; b=xygg8T1n8q66Nnt7vzo2QmiSefZE4Im/zUtOs/QVrEjjzlXeeqx2U7Rp18iOfyfIQn pb3G9WOO9ufFi30A7iy9v+MWh2fM+44ROk1adQOMdwi4gCv66wOfFcfUT+rdBEXdoQtn fSQAh2O0I4aFEYePyJD+gPzzbcXGteLpbVjeQaWD2s4uMxmy6OP9KwlqhVLjWZkoTZaG LiFSWVvNRmZ1B4HvVlBiDhvC/iGYeoItAJrklkvaNYSqZsL2YGplBtbZI26tq485Eaa1 vOD1QtTys4iF/v3sIsX8Rfd4kiaMb5lC5juiXt3YM9XcrlVSQ3STfb03nx5Gd3U5UJxL meOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="TAPmw+y/"; 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 m20-20020aa7d354000000b0047866149cdasi29334960edr.388.2023.01.05.05.57.34; Thu, 05 Jan 2023 05:57:57 -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="TAPmw+y/"; 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 S233545AbjAEN4d (ORCPT + 99 others); Thu, 5 Jan 2023 08:56:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234520AbjAENz0 (ORCPT ); Thu, 5 Jan 2023 08:55:26 -0500 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 441BA50052 for ; Thu, 5 Jan 2023 05:53:20 -0800 (PST) Received: by mail-ej1-x62e.google.com with SMTP id m18so90017420eji.5 for ; Thu, 05 Jan 2023 05:53:20 -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=2RMA+soBb7ISYDgZGukscenX9Gq6ESDTcYuOQgtCRPU=; b=TAPmw+y/LoYpb8ERNgeVU5ZMhp1Kwg8BHj2s0Y4AnMlt3Bc/0dOXyGT8zINdnQ9j0i NvbW19vYhExGrXXhLMNxY3AUU5G5Bb5Cmpsh8Y7LeALcZIAksx1LKuQkgkYWFwTz2wCf 49Hp+W8zgpRvfHxLCNczX752pmUENDL/H0VfI= 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=2RMA+soBb7ISYDgZGukscenX9Gq6ESDTcYuOQgtCRPU=; b=MESg1BEHmJlrbTe+QFeJybYwlnx8OTBXo2woIKtA0wAJ1VWBAFrx3cgCgTbzmsLox3 DtIWZ9KOtxq34k5ulDMnT9B7vwQe9vnwDqpJKt11s2AUFjigUJ8Yawq+gh3L5oWJ+4hR pRfgBN247c5hKa5o7C8fKUaGQt6TzGarLCl4OA1dNp/HVYQclbQ4EtCfD8sqAyGfbKBd djmaNKVPWaA4mKY52ohDVW9iVkOHTNeplpZezaj8eFlFx78a/ygslbl5/1c4FWpoMYj5 IbvkWtXTMCHrWVaHkOHTMZaJnlhfOdpLTXrz7jbq544tL3uL8rc2VOJz4K0/WkAKIO8z r3gg== X-Gm-Message-State: AFqh2kq31t4ZYtWFvM7a/wGYyi5oaSQDIFzNnl43p8izK5Zh90fp+uiH 0+fOSUxJMbTyCDF2jZgHq4nweg== X-Received: by 2002:a17:907:cb14:b0:849:ea61:511e with SMTP id um20-20020a170907cb1400b00849ea61511emr43083613ejc.44.1672926798876; Thu, 05 Jan 2023 05:53:18 -0800 (PST) Received: from alco.roam.corp.google.com ([2620:0:1059:10:43c3:8ac4:5d6f:2251]) by smtp.gmail.com with ESMTPSA id x11-20020a170906b08b00b007806c1474e1sm16459084ejy.127.2023.01.05.05.53.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Jan 2023 05:53:18 -0800 (PST) From: Ricardo Ribalda Date: Thu, 05 Jan 2023 14:52:56 +0100 Subject: [PATCH v2 5/7] media: uvcvideo: Refactor power_line_frequency_controls_limited MIME-Version: 1.0 Message-Id: <20230105-uvc-gcc5-v2-5-2ba6c660d6f5@chromium.org> References: <20230105-uvc-gcc5-v2-0-2ba6c660d6f5@chromium.org> In-Reply-To: <20230105-uvc-gcc5-v2-0-2ba6c660d6f5@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab Cc: Ricardo Ribalda , linux-media@vger.kernel.org, Yunke Cao , linux-kernel@vger.kernel.org, Sergey Senozhatsky X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=3076; i=ribalda@chromium.org; h=from:subject:message-id; bh=DwtzhBtzoWhod5MLtGXm+KQO/xP0T/ezlf1lPZGLRkA=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjttZEDva4TTVOKcDo4v43+ndHUK9dLIrDPT8n8aMs sBoKU0yJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY7bWRAAKCRDRN9E+zzrEiFhqEA CNBJb3H3POfgL7x1Njja/ruBSNtRUZ63U4RjdkjqJdnXrhJf9IfvwW04yCfhEGxmJII79tyXeSbQ1k BQbO+u+voKO/yqHqMnPtxCdVI60r59UhgsuXlQO8ABYps2ve3vBXE46k4VAhfKaCyUvVQZOu4S9oRz IBFZJxh3p7zACo1I+/j6eme5T3QzL6j0vrHpOjhMYcCBk3tOBQpaSFkW7N0Aaqw5JKrwM4uctRYCEw wGFHfyMlxt4oqG/bA7Hsz0IB3YRaqSc5NWzAms1NDehNktfJ/gEM1f6TIHjvWQanzCigx5sARqYTzt OW9MLR5PtyMEIfqUrPEu7uP99XJuj1Wg4v0OcDa4burHjvwiO7ZY0uwh5RyAYlwveKnOwj+TXGwKEs XB6tbYJ+rKgN7317tJYMFuLwS02FqBFO/kDapEZXwqfcC43QlOeyAwjUc8BesWEOr7UucejoDpBe9o 3EDb20tonKSP3cohDVPzNfJQZeB/Q8XTh7BK6A/utB7fFQACa6NZDhqsgf7Lf6ZJ0x3bXcigwPg+oA 7JcNx90g58tJ0H12HDG6uyimozdPPPuoUtyKf2g67S10WQffIM9a4XvkDuRa/FNJrfaaZXGvJzmJv4 UwpA3aBhYMazx29R75Nz8nGbOgpzl5hTz80yhnhwuRohHxLJ2mIBfKr6GD4A== 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?1754191183858576706?= X-GMAIL-MSGID: =?utf-8?q?1754191183858576706?= Move the control mapping to uvc_ctrl.c. This way we do not have references to UVC controls or V4L2 controls in uvc_driver.c Signed-off-by: Ricardo Ribalda Reviewed-by: Laurent Pinchart --- drivers/media/usb/uvc/uvc_ctrl.c | 13 +++++++++++++ drivers/media/usb/uvc/uvc_driver.c | 18 ------------------ drivers/media/usb/uvc/uvcvideo.h | 1 + 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 9af64f7a23d3..f559a1ac6e3c 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -723,6 +723,19 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { }, }; +const struct uvc_control_mapping uvc_ctrl_power_line_mapping_limited = { + .id = V4L2_CID_POWER_LINE_FREQUENCY, + .entity = UVC_GUID_UVC_PROCESSING, + .selector = UVC_PU_POWER_LINE_FREQUENCY_CONTROL, + .size = 2, + .offset = 0, + .v4l2_type = V4L2_CTRL_TYPE_MENU, + .data_type = UVC_CTRL_DATA_TYPE_ENUM, + .menu_info = power_line_frequency_controls, + .menu_mask = GENMASK(V4L2_CID_POWER_LINE_FREQUENCY_60HZ, + V4L2_CID_POWER_LINE_FREQUENCY_50HZ), +}; + static const struct uvc_control_mapping uvc_ctrl_power_line_mapping_uvc11 = { .id = V4L2_CID_POWER_LINE_FREQUENCY, .entity = UVC_GUID_UVC_PROCESSING, diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index e659670ea2d8..37d2b08bc8b2 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -2378,24 +2378,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, - .selector = UVC_PU_POWER_LINE_FREQUENCY_CONTROL, - .size = 2, - .offset = 0, - .v4l2_type = V4L2_CTRL_TYPE_MENU, - .data_type = UVC_CTRL_DATA_TYPE_ENUM, - .menu_info = power_line_frequency_controls_limited, - .menu_mask = - GENMASK(ARRAY_SIZE(power_line_frequency_controls_limited) - 1, 0), -}; - static const struct uvc_device_info uvc_ctrl_power_line_limited = { .mappings = (const struct uvc_control_mapping *[]) { &uvc_ctrl_power_line_mapping_limited, diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index a8eec43cd860..1b2d9f327583 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -747,6 +747,7 @@ int uvc_status_start(struct uvc_device *dev, gfp_t flags); void uvc_status_stop(struct uvc_device *dev); /* Controls */ +extern const struct uvc_control_mapping uvc_ctrl_power_line_mapping_limited; extern const struct v4l2_subscribed_event_ops uvc_ctrl_sub_ev_ops; int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, From patchwork Thu Jan 5 13:52:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 39591 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp311581wrt; Thu, 5 Jan 2023 05:57:58 -0800 (PST) X-Google-Smtp-Source: AMrXdXtsLWhLbg5CiWKhDzwvqrseNbdxEbdbUhkN5vxEZtaJKM4o16IFP5CmcIGFL97TMk65Lm04 X-Received: by 2002:a17:907:2c6c:b0:828:7581:f01f with SMTP id ib12-20020a1709072c6c00b008287581f01fmr39086246ejc.23.1672927078648; Thu, 05 Jan 2023 05:57:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672927078; cv=none; d=google.com; s=arc-20160816; b=r46rI7U4Lu+M+o9E+Hqu3gTJc64rb7l8aCJn/T3A6wjWAElMh3xftEcEp8rHAydlEP IQR4F9xo2ctV6oMiOarDMVi97AG3+sfKQx/KDmh2tWAL0sKpiDB/FLQGxFfM7bG03UMq Nhm+xhYjLMkU7VEsIMPKB7k2tfTUFMibEBOulz578mnV0AtmhOtHkQ7330Tc/lE8W8FF bl0DN0DK/ZUH9QI2jcbJ+JwGAdCGe5xB3xpzqRIkPvOP9uKK6BL6wAzFi0BXZou/psA6 voIep4zC4IMK2QrzZOK1R9mlw5gZySlDLR+LNbfJ/mqmJrKO4uR2GMLBFyicwDPX6OHS FOPg== 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=sjquDUj+Pkh3sX3Nb739RCA0OIWzHWBMegfajevm7GM=; b=rfxl8p5XP4TCU2DmPwbEl3LzA3ktDzGiGj65NfdDheDzrI6PkVPi7h9mwQAdQ/zjlN F0QMjWuK3xp7Eub5p4rR75wsFWPM1JzKCfaR4EFcHcHNil2r8ZtGujXxFEtIv+ngIKom Pk6ZonMABjED0uVhPrFfAKFWR+CLNkpdd+XW0wKzHB12Lj8Grky+yGic6/b97WbWq6mf lFGCSLyskoA7SQ3Yio3lx8J/NkSvVkXwGv+LV5E7kM34WNybFyL8KBknKAMmNVWjB322 6L4TRquAXyfxbK62npbmR7xtxYsNkTC7Um4aYY7VuiCENeHnA3BP1shtNuF4ygWLIg0X 3ZeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="k93+/ngH"; 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 dd8-20020a1709069b8800b007ae74740fa4si34710455ejc.275.2023.01.05.05.57.34; Thu, 05 Jan 2023 05:57:58 -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="k93+/ngH"; 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 S234634AbjAEN43 (ORCPT + 99 others); Thu, 5 Jan 2023 08:56:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233914AbjAENz0 (ORCPT ); Thu, 5 Jan 2023 08:55:26 -0500 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DCA15005F for ; Thu, 5 Jan 2023 05:53:21 -0800 (PST) Received: by mail-ej1-x62b.google.com with SMTP id t17so90066455eju.1 for ; Thu, 05 Jan 2023 05:53:21 -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=sjquDUj+Pkh3sX3Nb739RCA0OIWzHWBMegfajevm7GM=; b=k93+/ngHoI/xdxPrMldx7VCfDuLVtw5GP1vHdLHCEYvd6l5FtQtVn1T9CteRiHSK5B 7dQ1l8u3N1ykmcIzYE/vsr5DuELzWvo9oIqVpQdEO8eeWKFVZKoeKXDIzz3bwEl1yuVk zfZcBe5y4J7NffPPPFwr3BWiNNofQzKn/q/Y4= 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=sjquDUj+Pkh3sX3Nb739RCA0OIWzHWBMegfajevm7GM=; b=ZXTHfpTNhpwDXP4WPxihsmpsmBQPjPJLWxJtkAnYVtg4cILz2T/F/nVAj9um4UVThQ i/1nJ5Z1LdDhr7ZfdhG3jmU/z7JkMFIVdGoQstkBIC21/wog47whcVgpWb0GmL6Bm74/ DardCEX7xWpaytV/lXClG24ZsZ2AH13xwKgFTfiMR2c7dD2HGLdn0mVzVzTTqlV7w85e DfNvwNYXqw/pBrK2BLtmFJUkXSIrc3JSl0Tz2QD7bCYgEUm4qIFL6syYEly+YofDZKR/ RyTkcS+iCRzM6BXjfpIIAW3e3jPDQQ3XltsPR42bDDv03Ol/NKDwSHK5ZIN/a10jTsy/ 3/og== X-Gm-Message-State: AFqh2kp2LBakjw0GqEFM0fpSuZ8Ag0hYov8vPYTVXZvxYikpgc0A9tcE /QLTsaS7cCHZBchZ9HelfDi8nA== X-Received: by 2002:a17:906:ce4d:b0:849:a231:e503 with SMTP id se13-20020a170906ce4d00b00849a231e503mr38443183ejb.49.1672926799745; Thu, 05 Jan 2023 05:53:19 -0800 (PST) Received: from alco.roam.corp.google.com ([2620:0:1059:10:43c3:8ac4:5d6f:2251]) by smtp.gmail.com with ESMTPSA id x11-20020a170906b08b00b007806c1474e1sm16459084ejy.127.2023.01.05.05.53.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Jan 2023 05:53:19 -0800 (PST) From: Ricardo Ribalda Date: Thu, 05 Jan 2023 14:52:57 +0100 Subject: [PATCH v2 6/7] media: uvcvideo: Fix power line control for Lenovo Integrated Camera MIME-Version: 1.0 Message-Id: <20230105-uvc-gcc5-v2-6-2ba6c660d6f5@chromium.org> References: <20230105-uvc-gcc5-v2-0-2ba6c660d6f5@chromium.org> In-Reply-To: <20230105-uvc-gcc5-v2-0-2ba6c660d6f5@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab Cc: Ricardo Ribalda , linux-media@vger.kernel.org, Yunke Cao , linux-kernel@vger.kernel.org, Sergey Senozhatsky X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=3606; i=ribalda@chromium.org; h=from:subject:message-id; bh=YcPdxuXc6e/MVQTKSpvQxEjmmIRWxl3uxbcqXKNQm+o=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjttZGZ0Iq14zpMyjUhg2dn1eR/Vv5bx5PpNod+Vx4 CxsIn36JAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY7bWRgAKCRDRN9E+zzrEiL8BD/ 97Mt7IwMd9kghnskq4VR56QmcQpNpbpWNvsTriv5ngN9WMHXvib/mKpInWWqth9td482tbC+WrAEzc mFsRUe3hg+6C4VlfV7ly3J46mO7edihuDnu9OPq+Y8wEW6Yr5Qp7pORQg9B2zow9r8ar8LW3I8eEBM ttXVJFHjbPVlinVlXSRZDi49yeqtaqeI9Ox3degAKgUB1MmYBYeYvSHneA2jcZFD72pRLeCPh05JQP 5bvAOTH6nNq42DbY3Me2pPN9ncKJw2wG7xobBk//5PrgDQ5GOwjBBV101HXF88KUsdMYq7SubVwBXC RN5vz92w/Cx65/4mB8/V1K2nN4jh4w7NLKNh1ZmYSTLpo44gCbzE7CKKSOMf9TGAUwUIUfVXAgK2S9 PVqTRpaxeO91nfgPaJ7BfNG5VQhdb86DaGXt4sIzd/5m2K8/Tz9ETPv0xQYC7mrBxzT8XaGw2IG0oz JASMYr5v4D5DQsaS2xQofd4jdQrzGzsGtOvCbQo/Jzbiib5TLXDVR9xscnkHUeiMBLlig46UJ0XQxf Gd1Pq05A5p0MVpVjkqMrMbecKT5BkBxK1nKh7FbTxEct5oOBzECYkBs9Mo58yJqQ8/jc77rQqDE9e8 mQhLLLaB6/0G4YLICcf65HNdaJdbIQc4VHPoyUCzMOr64N9WkyhJ3ZnNetTw== X-Developer-Key: i=ribalda@chromium.org; a=openpgp; fpr=9EC3BB66E2FC129A6F90B39556A0D81F9F782DA9 X-Spam-Status: No, score=-0.5 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,SUBJECT_DRUG_GAP_L autolearn=no 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?1754191184261791409?= X-GMAIL-MSGID: =?utf-8?q?1754191184261791409?= The device does not implement the power line control correctly. It is a UVC 1.5 device, but implements the PLC control as a UVC 1.1 device. Add the corresponding control mapping override. Bus 003 Device 002: ID 30c9:0093 Lenovo Integrated Camera Device Descriptor: bLength 18 bDescriptorType 1 bcdUSB 2.01 bDeviceClass 239 Miscellaneous Device bDeviceSubClass 2 bDeviceProtocol 1 Interface Association bMaxPacketSize0 64 idVendor 0x30c9 idProduct 0x0093 bcdDevice 0.07 iManufacturer 3 Lenovo iProduct 1 Integrated Camera iSerial 2 8SSC21J75356V1SR2830069 bNumConfigurations 1 Signed-off-by: Ricardo Ribalda Reviewed-by: Laurent Pinchart --- drivers/media/usb/uvc/uvc_ctrl.c | 2 +- drivers/media/usb/uvc/uvc_driver.c | 16 ++++++++++++++++ drivers/media/usb/uvc/uvcvideo.h | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index f559a1ac6e3c..28ef9b2024a1 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -736,7 +736,7 @@ const struct uvc_control_mapping uvc_ctrl_power_line_mapping_limited = { V4L2_CID_POWER_LINE_FREQUENCY_50HZ), }; -static const struct uvc_control_mapping uvc_ctrl_power_line_mapping_uvc11 = { +const struct uvc_control_mapping uvc_ctrl_power_line_mapping_uvc11 = { .id = V4L2_CID_POWER_LINE_FREQUENCY, .entity = UVC_GUID_UVC_PROCESSING, .selector = UVC_PU_POWER_LINE_FREQUENCY_CONTROL, diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index 37d2b08bc8b2..57c948d47bbf 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -2385,6 +2385,13 @@ static const struct uvc_device_info uvc_ctrl_power_line_limited = { }, }; +static const struct uvc_device_info uvc_ctrl_power_line_uvc11 = { + .mappings = (const struct uvc_control_mapping *[]) { + &uvc_ctrl_power_line_mapping_uvc11, + NULL, /* Sentinel */ + }, +}; + static const struct uvc_device_info uvc_quirk_probe_minmax = { .quirks = UVC_QUIRK_PROBE_MINMAX, }; @@ -2964,6 +2971,15 @@ static const struct usb_device_id uvc_ids[] = { .bInterfaceSubClass = 1, .bInterfaceProtocol = 0, .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_FORCE_BPP) }, + /* Lenovo Integrated Camera */ + { .match_flags = USB_DEVICE_ID_MATCH_DEVICE + | USB_DEVICE_ID_MATCH_INT_INFO, + .idVendor = 0x30c9, + .idProduct = 0x0093, + .bInterfaceClass = USB_CLASS_VIDEO, + .bInterfaceSubClass = 1, + .bInterfaceProtocol = UVC_PC_PROTOCOL_15, + .driver_info = (kernel_ulong_t)&uvc_ctrl_power_line_uvc11 }, /* Sonix Technology USB 2.0 Camera */ { .match_flags = USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_INT_INFO, diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index 1b2d9f327583..31c33eb0edf5 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -748,6 +748,7 @@ void uvc_status_stop(struct uvc_device *dev); /* Controls */ extern const struct uvc_control_mapping uvc_ctrl_power_line_mapping_limited; +extern const struct uvc_control_mapping uvc_ctrl_power_line_mapping_uvc11; extern const struct v4l2_subscribed_event_ops uvc_ctrl_sub_ev_ops; int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, From patchwork Thu Jan 5 13:52:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 39593 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp311611wrt; Thu, 5 Jan 2023 05:58:02 -0800 (PST) X-Google-Smtp-Source: AMrXdXspSiTrsfDVSS7/2vhooySGwKKZWdGlrlGSpeVoGCW5a7VFBCR5eOrFiSoXjWDfLftwsMli X-Received: by 2002:a17:906:8492:b0:7ad:8f6f:806d with SMTP id m18-20020a170906849200b007ad8f6f806dmr45535626ejx.24.1672927082696; Thu, 05 Jan 2023 05:58:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672927082; cv=none; d=google.com; s=arc-20160816; b=VvoyPLIWud+ia1qJPHFIR6rKHH+SQYY6/1US6iUuOvcsiysFfnVHlVOo5gpHoH8s1u ghyEzB/S3aM7BZlCtWVVlJ6OsCO9W64XENXaunyY8wUXOOma8p1zWHzh7d190Eu2U00Z ghTHi51KlvqetC06WmkySfFJkZcqHOCqvHvGVkuX/XgZregW8ZjUvJDShfrQeKQM3mp7 W21PVw9xcsa7nURRdEiXZ9kvBLG2IKxlegjLcv8YX6W2hS6xdopmD4/dQECP+XDWlku4 ThNgLTz24AGeaqZDKWFIsrBLVlaWjBusMDZOPV1FRmIH3nFKIdqXQo4wktkQfhqo3duY FC1w== 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=7MeFBvW17iGnsCcj82DHSwKB7XpQUqOmaboAmgVuBOU=; b=rqvKBTdclyP+ov65d3l7v8sZCOmdkna9NI6Xn7sY0WBC658rCzOwfb/tkf0Bb5zYWI phy2l+YzqxOsbEmzFhSasle+jEzBADpw/8NUQWVUeop1SbkYAHA5RlUAIkhruQV6QxeU hCbtS6cQiOEjMFmFwdJPMEPuhRBdq5vOrneUExUGWAaf6POEkI80GOPEyw3fEwflJSec 31kVP8NSZFQRbKtqpTt8SDqaEqTZ1ixNDXPXfdsVLbg7qPGVH8+QmQ3d8ENkYEtFglCU Es/d+IlQ3wM22ifoUmsYTfNdMMDTGCZxgc1KknntGyRqpbZo08BKW/olDcvQmQcGbG8F VxhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=BLDTadc0; 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 hb33-20020a170907162100b007d11af995b2si3896152ejc.680.2023.01.05.05.57.38; Thu, 05 Jan 2023 05:58:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=BLDTadc0; 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 S233966AbjAEN4n (ORCPT + 99 others); Thu, 5 Jan 2023 08:56:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231561AbjAENz0 (ORCPT ); Thu, 5 Jan 2023 08:55:26 -0500 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4753D4BD73 for ; Thu, 5 Jan 2023 05:53:21 -0800 (PST) Received: by mail-ej1-x62f.google.com with SMTP id m18so90017635eji.5 for ; Thu, 05 Jan 2023 05:53:21 -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=7MeFBvW17iGnsCcj82DHSwKB7XpQUqOmaboAmgVuBOU=; b=BLDTadc0WPWJ4z5zc6bsb/Bf/L6gBQCEBjtMPlJ4PReFVLby3HH0HIvmgdk2aNUA7H cg11AexWd5pVB5s76HhjR+JhXEcTXruybsLGTSFX/HGN9P9UuTc1tCk9OibtRUF4zSBU rJ5BWfzNzu+/RCZDlPrc7SjTEuZsfWmWsPDxU= 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=7MeFBvW17iGnsCcj82DHSwKB7XpQUqOmaboAmgVuBOU=; b=QMNKExyS2OsK9nRtN4tZNjuLcdR/7yGj3opOv05QG1F9l6TdBYxxsMro8u0Sqk0kiH gktXvr4W87SmdC0OdV9fSOH4RcNKYdBk7U9rQuHTZkw4GMTAzu3UfV6zdZ3ORRgTFxlB bIdEqvZZWV4QLZGy5867UvNOb5CorypgKphFn2Sxyjsqv5Zyl8kn7BbOjs5UtuJXDc1J gDPv1s1EcEmBOQI0VadfiDvlHqS7XBOwpxO1+l9BFXxinaNy3tC3JVtGWFPTIGM8TyFi 1cbwCpD9+RJXashNF+JbytA2QASuDae7CH1tI8DnvNL0A1HhxTmRKvXc1hbT97G/SGJb XEQw== X-Gm-Message-State: AFqh2kpy7d/3Dnva9l1GehvEyYHhiTNnauJUMKivtylI5aTpPamzLE2a tTujO6PHElxJdfZkX3I/f4jXjA== X-Received: by 2002:a17:906:49cd:b0:7c0:f684:9092 with SMTP id w13-20020a17090649cd00b007c0f6849092mr43243064ejv.37.1672926800820; Thu, 05 Jan 2023 05:53:20 -0800 (PST) Received: from alco.roam.corp.google.com ([2620:0:1059:10:43c3:8ac4:5d6f:2251]) by smtp.gmail.com with ESMTPSA id x11-20020a170906b08b00b007806c1474e1sm16459084ejy.127.2023.01.05.05.53.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Jan 2023 05:53:20 -0800 (PST) From: Ricardo Ribalda Date: Thu, 05 Jan 2023 14:52:58 +0100 Subject: [PATCH v2 7/7] media: uvcvideo: Use standard names for menus MIME-Version: 1.0 Message-Id: <20230105-uvc-gcc5-v2-7-2ba6c660d6f5@chromium.org> References: <20230105-uvc-gcc5-v2-0-2ba6c660d6f5@chromium.org> In-Reply-To: <20230105-uvc-gcc5-v2-0-2ba6c660d6f5@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab Cc: Ricardo Ribalda , linux-media@vger.kernel.org, Yunke Cao , linux-kernel@vger.kernel.org, Sergey Senozhatsky X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=13910; i=ribalda@chromium.org; h=from:subject:message-id; bh=KAO3wtvchNw9niVHGiqrZkP1Ih5WWG4CeWxKIm4q0cQ=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjttZH6oQDJfUwz2AVEG7JUwtn7v7/Tk6q3vm99wbj BgGdRyKJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY7bWRwAKCRDRN9E+zzrEiHuED/ 9lweyP5TQIvuV1j5we5YcoIIgLS+h6dki3SL7QBoo1I8DzPk6JcYtRmLyYS2MBBcfwzf7KCjaNOuXT WgQ8SLLzg6xiQovYa2xthnhTcfvlP5GJeBNqGmnY59ptB+SSDFhbZDPF9Fi3W9jCJ/vlpRB5gEo5Ql Of0deFUY4TL/J+qD+0ESHH/E5DPsQSEt7uXdktF7aDP9HhCEFjW6TBcBZxdRtkMbr0NlxW1gxvydtX TyghEe5xp0z9KGgmNb5qA89uEKrEUbBXEKVystJIt6e9mZL77mvFUZ08a4mgvLUEaWYDLP3Us3SOv9 Wzf/YdWjAWlUvrVDOAPAynul28rbjITSrYRSkT68S8SLhZqC9i2FV312zSyf5tD3mCGt2hKZ0pjETs HxYeBpF400tPSmYdKypaY51ZkJahlux50erlYb/0RjRr6i3wCTNz0tnJ6t9kuPx7OadSRUtqgm96ip pf6n0oaTJV53l+mQPcgFKAvH3ZoOhj0n3qr4F4Zb5EPpeC5/A6bpN//vOESs3EPflpTi7w9MLjEo6O KPMj5VJtOFMtgQXNoZObXvMAk0WdSrC6bPY5YeUgXjmZpUwmGxazsrIzTIGVQIkjKSm31id8xvP05w /ZfB5uPTXVupkw7K7jg4nHFOv0ruGy6O76cbRraeYyQiWEv7rGkRKWDq1bWw== 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?1754191188799656269?= X-GMAIL-MSGID: =?utf-8?q?1754191188799656269?= 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 Reviewed-by: Laurent Pinchart --- drivers/media/usb/uvc/uvc_ctrl.c | 122 +++++++++++++++++++++++++++------------ drivers/media/usb/uvc/uvc_v4l2.c | 105 ++++++++++++++++++++++++--------- drivers/media/usb/uvc/uvcvideo.h | 3 +- include/uapi/linux/uvcvideo.h | 4 +- 4 files changed, 168 insertions(+), 66 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 28ef9b2024a1..f5a9d67e0966 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,9 +537,9 @@ 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_mapping = exposure_auto_mapping, .menu_mask = - GENMASK(ARRAY_SIZE(exposure_auto_controls) - 1, 0), + GENMASK(ARRAY_SIZE(exposure_auto_mapping) - 1, 0), .slave_ids = { V4L2_CID_EXPOSURE_ABSOLUTE, }, }, { @@ -731,7 +743,6 @@ 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, .menu_mask = GENMASK(V4L2_CID_POWER_LINE_FREQUENCY_60HZ, V4L2_CID_POWER_LINE_FREQUENCY_50HZ), }; @@ -744,7 +755,6 @@ const struct uvc_control_mapping uvc_ctrl_power_line_mapping_uvc11 = { .offset = 0, .v4l2_type = V4L2_CTRL_TYPE_MENU, .data_type = UVC_CTRL_DATA_TYPE_ENUM, - .menu_info = power_line_frequency_controls, .menu_mask = GENMASK(V4L2_CID_POWER_LINE_FREQUENCY_60HZ, V4L2_CID_POWER_LINE_FREQUENCY_DISABLED), }; @@ -762,7 +772,6 @@ static const struct uvc_control_mapping uvc_ctrl_power_line_mapping_uvc15 = { .offset = 0, .v4l2_type = V4L2_CTRL_TYPE_MENU, .data_type = UVC_CTRL_DATA_TYPE_ENUM, - .menu_info = power_line_frequency_controls, .menu_mask = GENMASK(V4L2_CID_POWER_LINE_FREQUENCY_AUTO, V4L2_CID_POWER_LINE_FREQUENCY_DISABLED), }; @@ -995,13 +1004,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; } @@ -1212,7 +1225,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)); @@ -1257,11 +1269,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; } @@ -1360,11 +1376,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)); @@ -1386,22 +1402,39 @@ 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) { + int 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; + } + + /* + * So far, only V4L2_CID_EXPOSURE_AUTO falls into this category + * and its mappings (exposure_auto_mapping), are a bitmap. + */ + 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); @@ -1902,7 +1935,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 @@ -2327,7 +2360,8 @@ 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) { @@ -2338,10 +2372,22 @@ static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, INIT_LIST_HEAD(&map->ev_subs); - size = sizeof(*mapping->menu_info) * fls(mapping->menu_mask); - map->menu_info = kmemdup(mapping->menu_info, size, GFP_KERNEL); - if (!map->menu_info) - goto err_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 err_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 err_nomem; + } if (map->get == NULL) map->get = uvc_get_le_value; @@ -2364,7 +2410,8 @@ static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, return 0; err_nomem: - kfree(map->menu_info); + kfree(map->menu_names); + kfree(map->menu_mapping); kfree(map->name); kfree(map); return -ENOMEM; @@ -2686,7 +2733,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_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c index 0774a11360c0..06b4afbbf8b1 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -26,14 +26,84 @@ #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 done; + } + + 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 done; + } + } + + /* + * Always use the standard naming if available, otherwise copy the + * names supplied by userspace. + */ + if (!v4l2_ctrl_get_menu(map->id)) { + size = xmap->menu_count * sizeof(map->menu_names[0]); + map->menu_names = kzalloc(size, GFP_KERNEL); + if (!map->menu_names) { + ret = -ENOMEM; + goto done; + } + + 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 done; + } + } + } + + ret = uvc_ctrl_add_mapping(chain, map); + +done: + 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 +131,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 = GENMASK(xmap->menu_count - 1, 0); + 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 +1367,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 +1480,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 31c33eb0edf5..c5a1c1c9d49e 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -114,7 +114,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 {