Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp866704pxf; Thu, 18 Mar 2021 13:31:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxXo6yQzO7yum7d9B1tC3bstenUbR1+eVnh9+m9N2IBQNSdU0edptl68EAX5rvNb2guNH9C X-Received: by 2002:a17:906:25c4:: with SMTP id n4mr392914ejb.359.1616099489070; Thu, 18 Mar 2021 13:31:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616099489; cv=none; d=google.com; s=arc-20160816; b=LwUpJXHIZ6T0xrC/zBMaxV0PsGiKiSQvNcLKq11tQIVEwO8Nj1TeXqQg/8NWzjXGvB O+XMPkHcqGngwVv1Was5o6oBpf6WYfJX+p2Li0eR0nV0r9k/y7xvuNz58IpAUYKbGxgc zNqsYG16AXbbnAXyS2j40/lSeXGVdtl7AEkfgoZ/mwlrwbtv0DbK2xZw6puirjBybWmM e7FY41btA5grq4hwpVvi4J3YWzb7VVwin048wrzwSXUcKceIc9uslW//0mxzgLk4L4dO nBx4HeM5ZhmcBR4v+LdwWsx9xYDEaxTgS6QBxDlBdFdob2BsLITLLv+X/3w7W87+8eNT 1m0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Vbmq6DvAp8/As0foK4j0pVO4aWYaVi9swp3Py2nra/g=; b=XYXEN62pupZLplQnfZGIyohqOQcGaj6ilfyB4XzPFDQjO/7r6cvQ1HF1VvrrZJa/l7 Gx5kTV5Rxd28H4hUti+9HdlIHQveSItXKob1YLbj2OAzAHQfp85gjDp3cagexGeom7Xz OnK5g8eNACgD9XpO+OGkb3SHSqVSbVjLsqQElaHcc8IuYPsyL1HMklhD9MB8qxIgM43r dFPSbFv9gJDH6lTvvxYV2rrX4HfByVKejx97PCjYxoY6k//NaZlaYyt5pIJFyO/sBYwo VhL13Tp5EYOoCskWNAdgnKevGVqST5WduzDsaBfpgFRXs4oNQ+7vJPu1ob93A4GRIrFy U8hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=V2Xumfmk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e24si2363472edv.373.2021.03.18.13.31.06; Thu, 18 Mar 2021 13:31:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=V2Xumfmk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S233187AbhCRU3q (ORCPT + 99 others); Thu, 18 Mar 2021 16:29:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233081AbhCRU3f (ORCPT ); Thu, 18 Mar 2021 16:29:35 -0400 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 DDF6CC06174A for ; Thu, 18 Mar 2021 13:29:34 -0700 (PDT) Received: by mail-ej1-x632.google.com with SMTP id t18so6010293ejc.13 for ; Thu, 18 Mar 2021 13:29:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Vbmq6DvAp8/As0foK4j0pVO4aWYaVi9swp3Py2nra/g=; b=V2XumfmkI7vrBf711i8aTXQUpLI+NLRNS7EA4B4cA6OYTWnwpf9TsBHR+9hoOnOp1+ flUO6cxvLKySfJYtyVh57mrI4lyI3uFWhlzfS4H6STmnmxOpFTBl7u8lJUVES3v1jC3d 0GzkxIdzWijKhYybuFhQGXm2HEBcuQWRSa42w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Vbmq6DvAp8/As0foK4j0pVO4aWYaVi9swp3Py2nra/g=; b=SYqGyH6i50Wp+SIYdzCK5AHWTmjiKCQhVjMBVq/frEg6Gh34Cl9JhsxNjYM0XlIihl OIKKRJvfoPjFv0YNk0ImyPvOP9JlnKA4xBYPc7GbohtzKOXVm+ZsonGgEESHSjvG3XcJ r/Ls9+PJauf9LL75Ekz6KKuXExK5ztI9wYxtxVrdVDiykNIXk5iA5Y7sh/hiYdfgRcnO cyxgoIyxKQYyOc5MK3hEinTp4Gyni9//UaJ419e8SwqtnCpkqf9URZooz7PZtnwcugCI KYODDAqGff4U7Bdp1l07xorbsPxbv1KZlncZCfMCTktU9Y2CUayoRWZ043DzpT6aoioz wrYA== X-Gm-Message-State: AOAM531SOg8jqF4GOu2iBQbyxgOsNXRbi3qaN7qgpf2zOzqZCG50/ZEd iSZwAG3uvfMeE0UREcmn76oz+w== X-Received: by 2002:a17:906:86c6:: with SMTP id j6mr381174ejy.197.1616099373675; Thu, 18 Mar 2021 13:29:33 -0700 (PDT) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id a22sm2533767ejr.89.2021.03.18.13.29.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Mar 2021 13:29:33 -0700 (PDT) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , Hans Verkuil , Sergey Senozhatsky , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, tfiga@chromium.org Cc: Ricardo Ribalda Subject: [PATCH v7 06/17] media: uvcvideo: refactor __uvc_ctrl_add_mapping Date: Thu, 18 Mar 2021 21:29:17 +0100 Message-Id: <20210318202928.166955-7-ribalda@chromium.org> X-Mailer: git-send-email 2.31.0.rc2.261.g7f71774620-goog In-Reply-To: <20210318202928.166955-1-ribalda@chromium.org> References: <20210318202928.166955-1-ribalda@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Pass the chain instead of the device. We want to keep the reference to the chain that controls belong to. We need to delay the initialization of the controls after the chains have been initialized. This is a cleanup needed for the next patches. Reviewed-by: Laurent Pinchart Reviewed-by: Hans Verkuil Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_ctrl.c | 41 ++++++++++++++++++++---------- drivers/media/usb/uvc/uvc_driver.c | 8 +++--- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index b3dde98499f4..b75da65115ef 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -2057,7 +2057,7 @@ static int uvc_ctrl_add_info(struct uvc_device *dev, struct uvc_control *ctrl, /* * Add a control mapping to a given control. */ -static int __uvc_ctrl_add_mapping(struct uvc_device *dev, +static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, struct uvc_control *ctrl, const struct uvc_control_mapping *mapping) { struct uvc_control_mapping *map; @@ -2086,7 +2086,7 @@ static int __uvc_ctrl_add_mapping(struct uvc_device *dev, map->set = uvc_set_le_value; list_add_tail(&map->list, &ctrl->info.mappings); - uvc_dbg(dev, CONTROL, "Adding mapping '%s' to control %pUl/%u\n", + uvc_dbg(chain->dev, CONTROL, "Adding mapping '%s' to control %pUl/%u\n", map->name, ctrl->info.entity, ctrl->info.selector); return 0; @@ -2168,7 +2168,7 @@ int uvc_ctrl_add_mapping(struct uvc_video_chain *chain, goto done; } - ret = __uvc_ctrl_add_mapping(dev, ctrl, mapping); + ret = __uvc_ctrl_add_mapping(chain, ctrl, mapping); if (ret < 0) atomic_dec(&dev->nmappings); @@ -2244,7 +2244,8 @@ static void uvc_ctrl_prune_entity(struct uvc_device *dev, * Add control information and hardcoded stock control mappings to the given * device. */ -static void uvc_ctrl_init_ctrl(struct uvc_device *dev, struct uvc_control *ctrl) +static void uvc_ctrl_init_ctrl(struct uvc_video_chain *chain, + struct uvc_control *ctrl) { const struct uvc_control_info *info = uvc_ctrls; const struct uvc_control_info *iend = info + ARRAY_SIZE(uvc_ctrls); @@ -2263,14 +2264,14 @@ static void uvc_ctrl_init_ctrl(struct uvc_device *dev, struct uvc_control *ctrl) for (; info < iend; ++info) { if (uvc_entity_match_guid(ctrl->entity, info->entity) && ctrl->index == info->index) { - uvc_ctrl_add_info(dev, ctrl, info); + uvc_ctrl_add_info(chain->dev, ctrl, info); /* * Retrieve control flags from the device. Ignore errors * and work with default flag values from the uvc_ctrl * array when the device doesn't properly implement * GET_INFO on standard controls. */ - uvc_ctrl_get_flags(dev, ctrl, &ctrl->info); + uvc_ctrl_get_flags(chain->dev, ctrl, &ctrl->info); break; } } @@ -2281,22 +2282,20 @@ static void uvc_ctrl_init_ctrl(struct uvc_device *dev, struct uvc_control *ctrl) for (; mapping < mend; ++mapping) { if (uvc_entity_match_guid(ctrl->entity, mapping->entity) && ctrl->info.selector == mapping->selector) - __uvc_ctrl_add_mapping(dev, ctrl, mapping); + __uvc_ctrl_add_mapping(chain, ctrl, mapping); } } /* * Initialize device controls. */ -int uvc_ctrl_init_device(struct uvc_device *dev) +static int uvc_ctrl_init_chain(struct uvc_video_chain *chain) { struct uvc_entity *entity; unsigned int i; - INIT_WORK(&dev->async_ctrl.work, uvc_ctrl_status_event_work); - /* Walk the entities list and instantiate controls */ - list_for_each_entry(entity, &dev->entities, list) { + list_for_each_entry(entity, &chain->entities, chain) { struct uvc_control *ctrl; unsigned int bControlSize = 0, ncontrols; u8 *bmControls = NULL; @@ -2316,7 +2315,7 @@ int uvc_ctrl_init_device(struct uvc_device *dev) } /* Remove bogus/blacklisted controls */ - uvc_ctrl_prune_entity(dev, entity); + uvc_ctrl_prune_entity(chain->dev, entity); /* Count supported controls and allocate the controls array */ ncontrols = memweight(bmControls, bControlSize); @@ -2338,7 +2337,7 @@ int uvc_ctrl_init_device(struct uvc_device *dev) ctrl->entity = entity; ctrl->index = i; - uvc_ctrl_init_ctrl(dev, ctrl); + uvc_ctrl_init_ctrl(chain, ctrl); ctrl++; } } @@ -2346,6 +2345,22 @@ int uvc_ctrl_init_device(struct uvc_device *dev) return 0; } +int uvc_ctrl_init_device(struct uvc_device *dev) +{ + struct uvc_video_chain *chain; + int ret; + + INIT_WORK(&dev->async_ctrl.work, uvc_ctrl_status_event_work); + + list_for_each_entry(chain, &dev->chains, list) { + ret = uvc_ctrl_init_chain(chain); + if (ret) + return ret; + } + + return 0; +} + /* * Cleanup device controls. */ diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index 30ef2a3110f7..35873cf2773d 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -2423,14 +2423,14 @@ static int uvc_probe(struct usb_interface *intf, if (v4l2_device_register(&intf->dev, &dev->vdev) < 0) goto error; - /* Initialize controls. */ - if (uvc_ctrl_init_device(dev) < 0) - goto error; - /* Scan the device for video chains. */ if (uvc_scan_device(dev) < 0) goto error; + /* Initialize controls. */ + if (uvc_ctrl_init_device(dev) < 0) + goto error; + /* Register video device nodes. */ if (uvc_register_chains(dev) < 0) goto error; -- 2.31.0.rc2.261.g7f71774620-goog