Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp497132iog; Fri, 17 Jun 2022 07:34:33 -0700 (PDT) X-Google-Smtp-Source: AGRyM1svgZVagX5RmUe0qmaf0WDKA/Baep+6az+Y5WY9KmDBZzGhHKd+wo6Yq9+lGJTXlxUTvEWG X-Received: by 2002:a17:906:dc8f:b0:70e:5e7a:cc59 with SMTP id cs15-20020a170906dc8f00b0070e5e7acc59mr9686601ejc.423.1655476472829; Fri, 17 Jun 2022 07:34:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655476472; cv=none; d=google.com; s=arc-20160816; b=lO7zUtmdG3ZAc1Dfl1C0cYIMxBUDCJp5NEMeXzOBz1mR24+fo6LVlcV65qQLPkLnRG m67JfAcbSXgWWPH6yysUHghj7DMSDJC4qfxJ4jkfSy1cgDHLwB2bc/06QzJWDYg3r42y GZ8HwouF68OhpB8fFiVvZrvIKC1L8DuAUntPAjTUGVTwKz8s8LJymGFJGC+oO4DDFCov ORovU7TL8bCW042lMPm6ZZ1u3jNf09F8qcp22OyAU1WFHiDHpjDxFRfO7zyrPjRn3+F0 2pVVxjRTMtXq5OchLx+JTtx8No3eodUhXRvBbdh45xN1KB906aTXwfUQlfK+bKBrAxNX m+rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=dpaZ8e8VGQb+BpielLCrmJsF4upPaG4g9PcgtNKJNx8=; b=kwFLOVia/Y6qnLZJz2QQFQzSCEMMGZu65BxvOQPotUwBWbau/55EWemKcaENwGP0ok WjJX5Or17HeLI63gvwAoG4Shtc371HunIWTX1/i8NS5yh9hbKWQBFF69FPlgFE+O0WNK YN640xwS6BBBAelDR43oFOh8Of1i95VwzPHRMrWwo8Uz42x+UFUTtQbE7MCyVaTDf8z9 7hmaKbCfCJluKQgu2duxH6AQuzc1Z9BbbXdNP9hMbRcSkq1d/ggdBpxbDsEsjbH9G15Y sQn5Nl7kPYBrOlNKQWDlLmnlw9BwGLX5z05YqfaiYiEt+tk1BqoKA1SjaXKQPi3RuH/f GEKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=WZ27kY1C; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gn9-20020a1709070d0900b006e7d38a8843si6385341ejc.443.2022.06.17.07.33.51; Fri, 17 Jun 2022 07:34:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=WZ27kY1C; 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 S1382606AbiFQOHg (ORCPT + 99 others); Fri, 17 Jun 2022 10:07:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381543AbiFQOHf (ORCPT ); Fri, 17 Jun 2022 10:07:35 -0400 Received: from mail-oa1-x33.google.com (mail-oa1-x33.google.com [IPv6:2001:4860:4864:20::33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4319FF11 for ; Fri, 17 Jun 2022 07:07:34 -0700 (PDT) Received: by mail-oa1-x33.google.com with SMTP id 586e51a60fabf-fb6b4da1dfso5706805fac.4 for ; Fri, 17 Jun 2022 07:07:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=dpaZ8e8VGQb+BpielLCrmJsF4upPaG4g9PcgtNKJNx8=; b=WZ27kY1CncLf6C6gidqBYDfqwWoYVu7cndc5pjkptu6pXJ8OXdVklLOceW5B5yr05C Y6zbok6paHAJSNxOGA39aAnlFw4VTUW35dIyL8BKUgsyvLX2/4hyHYTXLybsw6BjLY+m C8FqVNljqoBnokRx5UZzldzcWQiLq4RPYF6Is= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=dpaZ8e8VGQb+BpielLCrmJsF4upPaG4g9PcgtNKJNx8=; b=srlrVRXEavh6cwjdbF1m0nIsYeNE66PMNhDp6DBcRNB2LPEZ1qyVMEpX6m9cAwzCuC 9VTiGGRq34i7WWTlPzc98wNAvwBKsneIJHaMRNKIbCuptD0YdAsRO7Yqw7BdKJ7XPQ/r QpLiRDNnoE3LZfdqOoSYJOHUAXJAIo6lxMhvH+AtbrFa7YIYHjraEHcWIHqD5AhdbxbK bhIdRA2eFeKCRAvaWL6IySgdpsX01S4EQqAz3nKvfdZ4dOcY5FgTDu7Ij/9gFcBAFfZe ThYoxL9xvdyNN3BGkqQNMmqqMzhS7qO7XJUb3hDRzvQk+fxvti3GFCj+ODCjENJr0avo tFVA== X-Gm-Message-State: AJIora8x+cuwuu4+HiCquvt8TGPAxe1+PZePDpd7sJiRAgWzXPPPwnRW jUyM6Oi+5R0bXFxSSEahdXJfx0oqSBkyJw9h X-Received: by 2002:a05:6870:e98b:b0:fe:219a:2449 with SMTP id r11-20020a056870e98b00b000fe219a2449mr11651926oao.228.1655474853304; Fri, 17 Jun 2022 07:07:33 -0700 (PDT) Received: from mail-oa1-f42.google.com (mail-oa1-f42.google.com. [209.85.160.42]) by smtp.gmail.com with ESMTPSA id k19-20020a056830243300b0060603221255sm2481975ots.37.2022.06.17.07.07.31 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 17 Jun 2022 07:07:32 -0700 (PDT) Received: by mail-oa1-f42.google.com with SMTP id 586e51a60fabf-101bc0d279cso649667fac.0 for ; Fri, 17 Jun 2022 07:07:31 -0700 (PDT) X-Received: by 2002:a05:6870:4799:b0:f1:46f8:6ea4 with SMTP id c25-20020a056870479900b000f146f86ea4mr5544524oaq.223.1655474851271; Fri, 17 Jun 2022 07:07:31 -0700 (PDT) MIME-Version: 1.0 References: <20220617103645.71560-1-ribalda@chromium.org> <20220617103645.71560-3-ribalda@chromium.org> In-Reply-To: From: Ricardo Ribalda Date: Fri, 17 Jun 2022 16:07:20 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v7 2/8] media: uvcvideo: Add support for per-device control mapping overrides To: Laurent Pinchart Cc: Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, tfiga@chromium.org, senozhatsky@chromium.org, yunkec@google.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.7 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,T_SCC_BODY_TEXT_LINE 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 Hi Laurent On Fri, 17 Jun 2022 at 15:44, Laurent Pinchart wrote: > > Hi Ricardo, > > Thank you for the patch. > > On Fri, Jun 17, 2022 at 12:36:39PM +0200, Ricardo Ribalda wrote: > > Some devices do not implement all their controls in a way that complies > > with the UVC specification. This is for instance the case for several > > devices that do not support the disabled mode for the power line > > frequency control. Add a mechanism to allow per-device control mapping > > overrides to avoid errors when accessing non-compliant controls. > > > > Signed-off-by: Ricardo Ribalda > > Signed-off-by: Laurent Pinchart > > --- > > drivers/media/usb/uvc/uvc_ctrl.c | 35 ++++++++++++++++++++++++++------ > > drivers/media/usb/uvc/uvcvideo.h | 1 + > > 2 files changed, 30 insertions(+), 6 deletions(-) > > > > diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c > > index a709ebbb4d69..092decfdaa62 100644 > > --- a/drivers/media/usb/uvc/uvc_ctrl.c > > +++ b/drivers/media/usb/uvc/uvc_ctrl.c > > @@ -2403,9 +2403,8 @@ static void uvc_ctrl_init_ctrl(struct uvc_video_chain *chain, > > { > > const struct uvc_control_info *info = uvc_ctrls; > > const struct uvc_control_info *iend = info + ARRAY_SIZE(uvc_ctrls); > > - const struct uvc_control_mapping *mapping = uvc_ctrl_mappings; > > - const struct uvc_control_mapping *mend = > > - mapping + ARRAY_SIZE(uvc_ctrl_mappings); > > + const struct uvc_control_mapping *mapping; > > + const struct uvc_control_mapping *mend; > > > > /* XU controls initialization requires querying the device for control > > * information. As some buggy UVC devices will crash when queried > > @@ -2433,14 +2432,38 @@ static void uvc_ctrl_init_ctrl(struct uvc_video_chain *chain, > > if (!ctrl->initialized) > > return; > > > > - /* Process common mappings first. */ > > - for (; mapping < mend; ++mapping) { > > + /* > > + * First check if the device provides a custom mapping for this control, > > + * used to override standard mappings for non-conformant devices. Don't > > + * process standard mappings if a custom mapping is found. This > > + * mechanism doesn't support combining standard and custom mappings for > > + * a single control. > > + */ > > + if (chain->dev->info->mappings) { > > + bool custom = false; > > + unsigned int i; > > + > > + for (i = 0; (mapping = chain->dev->info->mappings[i]); ++i) { > > + if (uvc_entity_match_guid(ctrl->entity, mapping->entity) && > > + ctrl->info.selector == mapping->selector) { > > + __uvc_ctrl_add_mapping(chain, ctrl, mapping); > > + custom = true; > > + } > > + } > > + > > + if (custom) > > + return; > > + } > > + > > + /* Process common mappings next. */ > > + mend = mapping + ARRAY_SIZE(uvc_ctrl_mappings); > > I don't think mapping has the right value here, it could even be > uninitialized. Let's make this > > mapping = uvc_ctrl_mappings; > mend = mapping + ARRAY_SIZE(uvc_ctrl_mappings); > > for (; mapping < mend; ++mapping) { > > to match the code below. ups, sorry about that :( . Will send as a new version > > > + for (mapping = uvc_ctrl_mappings; mapping < mend; ++mapping) { > > if (uvc_entity_match_guid(ctrl->entity, mapping->entity) && > > ctrl->info.selector == mapping->selector) > > __uvc_ctrl_add_mapping(chain, ctrl, mapping); > > } > > > > - /* And then version-specific mappings. */ > > + /* Finally process version-specific mappings. */ > > if (chain->dev->uvc_version < 0x0150) { > > mapping = uvc_ctrl_mappings_uvc11; > > mend = mapping + ARRAY_SIZE(uvc_ctrl_mappings_uvc11); > > diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h > > index c5b4febd2d94..fff5c5c99a3d 100644 > > --- a/drivers/media/usb/uvc/uvcvideo.h > > +++ b/drivers/media/usb/uvc/uvcvideo.h > > @@ -667,6 +667,7 @@ struct uvc_device_info { > > u32 quirks; > > u32 meta_format; > > u16 uvc_version; > > + const struct uvc_control_mapping **mappings; > > }; > > > > struct uvc_device { > > -- > Regards, > > Laurent Pinchart -- Ricardo Ribalda