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: 639610 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB6C5C61DB3 for ; Thu, 5 Jan 2023 13:56:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234195AbjAEN4H (ORCPT ); Thu, 5 Jan 2023 08:56:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234506AbjAENzV (ORCPT ); Thu, 5 Jan 2023 08:55:21 -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 00DF94ECA9 for ; Thu, 5 Jan 2023 05:53:16 -0800 (PST) Received: by mail-ej1-x62b.google.com with SMTP id qk9so90027220ejc.3 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=48J8/lNIK5/3+r7XCpLmE1EDI56Rk5V2KLWmZf5+Ge+KBIsk0qbYyjzGGYTPRC9ivP G2b94XCmCBGnWJzxu7orS8WnSdn84O5st0rIL7BV1GhFtFKOd4KWvYsfgLt0WFndIRXa kLSUJysxqYGyY9jP4PFAJMEA6oswT9gKxiF/ejcAus56Z6oWPuqQN2ETWQAiJkgOLzUx YZI4oXeFPRZYGLwlZ3oOFUBR51PEuJDSz0h5G2Nfc9o0GEzQ0vQSbNHH4/Fgp7xPizFZ u9kNlA1CFRUsslWYEgcThwGniG0Xy8FR1cie+tCzPFxFZBWMPxStwarg5X0YzfFiVB49 3mlg== X-Gm-Message-State: AFqh2kphu9ABLL2R9rQ9x0sShJcS7WLeD5oBQN4wgNoawDyP6TYm7I5d CdB7z39t6JwIl+t78LiW1qWlSA== X-Google-Smtp-Source: AMrXdXsrIg5VWskMm9cojCnRsO3whyhLzgBk+hufNJimzWdvytWr9UtvPvczNrMHxPPlcn+4TFdP/A== 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 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org 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: 639611 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 621BFC54EBE for ; Thu, 5 Jan 2023 13:56:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234047AbjAEN4E (ORCPT ); Thu, 5 Jan 2023 08:56:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234508AbjAENzV (ORCPT ); Thu, 5 Jan 2023 08:55:21 -0500 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E28B04F10E for ; Thu, 5 Jan 2023 05:53:17 -0800 (PST) Received: by mail-ej1-x629.google.com with SMTP id tz12so90215758ejc.9 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=hRJRQUZSkDQo61uVkv5BdPc0pAf1TKFE00oZzXbaXpGItj+6AdDRaXrOsmkxp6ec3f oo+VetJurV7Ve4poNOe9ORcMLe1wVq6Qwm8+yWvwfeoYbwwMJZQp/fkch2rDUCW2AECN ukXYpEHsdwN0dL/UKTLX6BrNzy1RdRQyB7DX/0MvM2sNInUf9MTDc0jJpMUsWe3WfNdR 0id/+DONOfHjwDMqJkXxxe0PuD91gZuVVE2HMtjqK0m+Wb7HBoFfnsxrCwYye1Bxj617 Q9wrxLbaiB/250f5jnFiED7eUEUUrEH0FzQaHuw5wcgy8jsUxQuwsrr+ImVo35rXvjau X7WQ== X-Gm-Message-State: AFqh2koG3iEBpvruGPFBP2v8lxqLbUU2BTTw6pljwPXB8ySdF9A8BDR9 ClWAD4BhaT9c29Php5Iucnbdnw== X-Google-Smtp-Source: AMrXdXvWL+hEKIbcpR394kWiSMIV995umfL4HC7P+6mK2BlYFx5R06LT9dSkoE4e4R3p5NJTjFJK3Q== 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 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org 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: 639609 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BCFDCC63709 for ; Thu, 5 Jan 2023 13:56:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234322AbjAEN4K (ORCPT ); Thu, 5 Jan 2023 08:56:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233789AbjAENz0 (ORCPT ); Thu, 5 Jan 2023 08:55:26 -0500 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC7DE4EC8F for ; Thu, 5 Jan 2023 05:53:18 -0800 (PST) Received: by mail-ej1-x632.google.com with SMTP id t17so90066209eju.1 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=VyUr5V27ZXhVOo4U0XH9APhzslW73CgsSCGdk0xFR8sSSjeoRDLsI31yrWh6ZOv6FR Zh/FlXJ+3+0vQZr25zxZjpELwItXzJm+XdEjEPWzsbYVWVXaKoto3IjQ3e4G2Fk7lpgd VQB0spk+k5LRFHbxka8qXQ9yaB1n5WzU+irMQTolpuBrI2CgrbaDTdmnGpNHAE3cEV1R 5CQAfthgl8uJzt+9+1/uGBRizSzUZuBNsXxBdojPj6INHwkrGW6EA7Zxv0g+wEEO/h+R hTiY6AAwm/N6RSYQYYh3l/eCXNXI4CY/tq4CGlDDCAm+zBFqKcJzNnemBrOXKKXToTGn s9kw== X-Gm-Message-State: AFqh2krkviAnR6K3JrnVHcHJlEovx7MdEv7uPiZITvrA6hVms7kTgXuZ qDvH+25yj5H/9i0AaEWVlSMK4w== X-Google-Smtp-Source: AMrXdXv44elPCiEVRpl+fjdUJ8F8ssFDQdBYx0YXbryye3AWrGLkUKiyMdC6A3WqUWzxIGQRr70b3g== 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 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Replace the count with a mask field that lets us choose not only the max value, but also the minimum value and what values are valid in between. Reviewed-by: Laurent Pinchart Signed-off-by: Ricardo Ribalda Suggested-by: Laurent Pinchart --- drivers/media/usb/uvc/uvc_ctrl.c | 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: 640254 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1C2D9C54EBD for ; Thu, 5 Jan 2023 13:56:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233792AbjAEN4B (ORCPT ); Thu, 5 Jan 2023 08:56:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233967AbjAENzX (ORCPT ); Thu, 5 Jan 2023 08:55:23 -0500 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82A194FCE6 for ; Thu, 5 Jan 2023 05:53:19 -0800 (PST) Received: by mail-ej1-x62d.google.com with SMTP id u9so90361566ejo.0 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=PQpN0dGryHxm3SolJGpNTC7KC0IpN21hbT+Up+ZZJJ4alRQQlxFGo3iTvLz8LlaeGh /w888vGH+t+WtyLGxMadmJL84kZvvNq2FcRxalB5w4eOWIdEy5WEJqcnmWfqitstzsgQ G+H9MDmR2w3ZOtTb/Fxb7p6VVkRvFYP4BqrCNtxGqy+OXX8jZ6lqnyQKWEc90ppyZ5HW h/NC8vRdNsjk7DODzmZzcCSmXAEYeqGl8I7f7btIsWjo834cXAYu1iMw0a9Ri5DWonma G5VXtuzi5e089spsE7PAp9EmHUysTq6EWfEE2jdVze33nMkerx6Ss4bh0yTliZXb65EJ GLXQ== X-Gm-Message-State: AFqh2kpk6GEUSspUilsPqi5r+1t+oBfzADOFoCpixotCBLN/OSbj1kXs c5tmXNstUd/jBVbT0REuUi28aA== X-Google-Smtp-Source: AMrXdXvOiPS9P0xlJpzRLQUHDkrNOud+i33QounGhFT/MCDIptlPUnBbebmAaNpQtfdDXf1sHCQ4bw== 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 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Convert the array of structs into an array of pointers, that way the mappings can be reused. Signed-off-by: Ricardo Ribalda --- 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: 640253 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78237C54EF1 for ; Thu, 5 Jan 2023 13:56:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234137AbjAEN4F (ORCPT ); Thu, 5 Jan 2023 08:56:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234511AbjAENzW (ORCPT ); Thu, 5 Jan 2023 08:55:22 -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 44ABD4FCE4 for ; Thu, 5 Jan 2023 05:53:19 -0800 (PST) Received: by mail-ej1-x62b.google.com with SMTP id qk9so90027563ejc.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=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=idRBjSrCEVzS3hHai5RKJd81qyFvZjiuMgXVAt3NJVCekR3c8eaIHhE9CCj0Md9aEw 69SbBf76LMp+MOdAN6rK86lXAyAgQMeJBZ3RG6YRWTd6HxLLFNyy8v6v+E5/tbQOdIi6 3cB4sv81sqFLq3n2hb6lGJVqPBehpUhNFuCdHWZudZcCj15Tle462GkV3HMd4A9QOJZ6 jUCUM72GlDfuyL7DVPc2c8THvBc3lpfuNtG8SbV3pzOJGfMGYfRiPUiByRjSZ45ewobz SlfHAqfo3oMf+liFUOaXL3foDCcotF1a3/ADYMu+E/JapQGZiC7wR7jTjJitQLFxBKcO kxbw== X-Gm-Message-State: AFqh2kqfSTA6wTR7GcC7wMnW27e1zkFtk7LeWKE8qklCWVKWP8Mfn5KA f9VU0HaZNG3PLM7u+JGpiSQ/Yw== X-Google-Smtp-Source: AMrXdXsyYjuYxWDGZ8yq+j5dtkgQZmpKpDtKSS02rAx1JeeFm46IK193HbeiefW02MvKifEVlWzoMg== 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 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org 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 --- 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: 640255 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41888C3DA7D for ; Thu, 5 Jan 2023 13:56:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233114AbjAEN4A (ORCPT ); Thu, 5 Jan 2023 08:56:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234515AbjAENzY (ORCPT ); Thu, 5 Jan 2023 08:55:24 -0500 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1CEE04FD70 for ; Thu, 5 Jan 2023 05:53:20 -0800 (PST) Received: by mail-ej1-x629.google.com with SMTP id fc4so90115166ejc.12 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=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=Ru0K3PIdDE/iPP4dBjigbN1XSkcaoghtmUQfIQQyh7OnoN4QAEQA+GZNuc2JZujTDN 9m62M8kw5eQjpg2N4G6MMENYlWRAaWAzKhtYB7/E/sZ8ScxFMOBxPPWF+J302A19NKAP zhreIxN6sQMJQ7ASfsb0gzfhntZfW3kxPUc6i3eokL937EPohHd+p3Y8b2RapeDWDqTA RjUm5biHvLaHn7Bm/mv6vwS2Zirpb/FmtriPsX484xD6+Yqbs1fS3VT6WxFBc3Y3d3aU C+6UFahbCI1fegy+hKKdrk7s/vd/SSs9+mVhup6DYzNK8pEAgi8Onlw7savouqF4uzVh 8fGw== X-Gm-Message-State: AFqh2kqEJWEu/8imZ+lRmPuQHJLfAiZcRuyut+9/xgJseRwvx3F/WogO 3YVAASYCVztz/mi2A0gV0ceS9w== X-Google-Smtp-Source: AMrXdXvH2PelQyv965276xdO7FAFuyEmVm31ObXjdX8BSN6Wb/JLyfFcw8ffi7QS4ztds3s5jj7M3A== 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 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org 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 --- 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: 640252 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A526C63705 for ; Thu, 5 Jan 2023 13:56:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234172AbjAEN4G (ORCPT ); Thu, 5 Jan 2023 08:56:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232901AbjAENz1 (ORCPT ); Thu, 5 Jan 2023 08:55:27 -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 486AF4BD6E for ; Thu, 5 Jan 2023 05:53:22 -0800 (PST) Received: by mail-ej1-x62b.google.com with SMTP id gh17so90305856ejb.6 for ; Thu, 05 Jan 2023 05:53:22 -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=xxs3jUcudDXV371rZ4B4qvV2wMKGK/W+xTmBGZHTg27ycmcgwI3RiwXanOUoNxcWCL l8wxm+8PRhJpZghOFdQmYI5aVS/sn/9wUwy3F5SeABOzkl2dwXQBbQLcM5r1WPRnDm9V AycriCj1TzWLbGtPoS7/UfI14Bg7l1VGeIC4uJ1TATmO/F5QvhXXUiCd4te9YJvcFq5C Hmv6uOAHYcVjV9z5I2CaJirhDLQFgFVZSr49GDAcOkWqL9fiY//ISiaIycK5cIZb85tS n1VftvY4mU8gFD/xAre6roOBS5PDt4D3+LHs0ZbNO39yjNyeX+/PsFr+SyygrQh3zhFN DWSQ== X-Gm-Message-State: AFqh2kq/1Zy7gnpS0Iff620+rXdKbdf9Xbg3GBGd3DakmZVwU4V9HyTM ByLqYVDpfVmAscHFexACxqaH5A== X-Google-Smtp-Source: AMrXdXswahqibIq9zURDhnn/0/0Y3myUpBQjmGHmQ/LRlYIk0P2eK+1E5GQHOX+YyD+IGliC3e0pug== 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 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Instead of duplicating the menu info, use the one from the core. Also, do not use extra memory for 1:1 mappings. Signed-off-by: Ricardo Ribalda Suggested-by: Laurent Pinchart --- drivers/media/usb/uvc/uvc_ctrl.c | 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 {