Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp3318003pxb; Tue, 12 Jan 2021 11:29:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJxWfqOijKNA26pjDjmzC1EakWWraFySMbSL6qyoU6zwmzxpBJfL6n8QI1dZnV9mXps+BqhZ X-Received: by 2002:a17:906:3b4d:: with SMTP id h13mr240289ejf.289.1610479764174; Tue, 12 Jan 2021 11:29:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610479764; cv=none; d=google.com; s=arc-20160816; b=d9dVbXrBHT/ZJdh4xCBaNoJbRT40el/uwIF1ZB1If7DxKPOygLuUFuwUYGTDL9C5+4 JqRPiI0L2qQl3hFNZi4GAcjm6UqQ/+EO18j2Dr7eSXpFU1Qz+NG8ct3j4YmxZElwNT7c IaUyCVQyLYU88zWldycCoOtyGa74bCDP4kwz1qofa2wYg7cXCKz/BiT2xVd2y+40cXXV hJYMi3wsrOY1NEXeMiOPnfiqwiXIzqM2MMyLXtgkGjR/6a+Oak1Nl7MBjHmfPHaU6aIl 96gIeHQF1joNM+RGRjvFnSxVnelr7YPrpUzaPDCuQW8Nh5eYEBEj/n+xD4OkbKyqcEzb 1QRg== 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; bh=9jqlZeSwAhTGBCADje3hETLAAnd6ynOytXTvHrnyrdk=; b=FJ+ThygD4enpS3I07TvooZJFaWdpEZMKR9Kx2RSR8teRe4lB0fGeV/Ip8WYvKOqjS1 ItbGb9U46VCMoDUlS1hmDFqeUApe0EXOFx8UZIbhFIOIlFi6RqksV8WqyBx14VMPMx+L p85L7aVSsd699H7l8PDXNRnBWKbhoooVljXKORBPbOfijb8ZC+dvv0mVn/d/H8SyuhvR HoUocnF5wmNGpxqrQ6/eej47SsnhEDX5VFZQyLczK1Pd2U3ldofhSrL6Axxj+pCUvy1z eECQgYrFgAqh3TDqKN3jrOPQK5bSBxjIIY4knOddrv31M48kGrOpqr0jR1C2CREXg806 jgug== ARC-Authentication-Results: i=1; mx.google.com; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jx27si1444387ejb.250.2021.01.12.11.28.49; Tue, 12 Jan 2021 11:29:24 -0800 (PST) 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; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2393123AbhALTZ4 (ORCPT + 99 others); Tue, 12 Jan 2021 14:25:56 -0500 Received: from mail-oi1-f181.google.com ([209.85.167.181]:43757 "EHLO mail-oi1-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2393107AbhALTZz (ORCPT ); Tue, 12 Jan 2021 14:25:55 -0500 Received: by mail-oi1-f181.google.com with SMTP id q25so3511893oij.10; Tue, 12 Jan 2021 11:25:39 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=9jqlZeSwAhTGBCADje3hETLAAnd6ynOytXTvHrnyrdk=; b=oKV8QCpiMsRvUirdtN3WcbessmwlWT3n5lqOsAtBqHXX+FSdo9jPxshJtgq5nWc2rC XsTJGqEhOxEBQY2fEAsF90KpRkOkXW4/GGwRPr/lPNPmsNnuIWdZd/Q9u+nPNBmbk85W mOMZC6fQWohUhT/iyig3xvZLC6nmr4iNJXDV78MFoW/GGpJNn3AhXezrfjRgCl2Iq0Ay BJJZR1bdeYD+ix0DcvcI4ml/ldtVE43IbNMabmL21bj9skpt4FqRd+rkJSZkfIMwBNlg PUpfjABNYH1PUPLdyNNQNfTXzcIX6QiHr1bOYw9VBM/+SLMdKW8TohtbvY/DotBr5cBk pIGg== X-Gm-Message-State: AOAM530tSCDnlxPWyD5eiKjCnNmd8kQH+61OhZPQCj0MqD/ZBBBOhI51 niJJg2t0cuTJnkTxB8ZCyN8xmHomgxSq8PgdjBs= X-Received: by 2002:aca:4c1:: with SMTP id 184mr454926oie.157.1610479513823; Tue, 12 Jan 2021 11:25:13 -0800 (PST) MIME-Version: 1.0 References: <20210107132838.396641-1-djrscally@gmail.com> <20210107132838.396641-14-djrscally@gmail.com> In-Reply-To: <20210107132838.396641-14-djrscally@gmail.com> From: "Rafael J. Wysocki" Date: Tue, 12 Jan 2021 20:25:02 +0100 Message-ID: Subject: Re: [PATCH v5 13/15] ACPI / bus: Add acpi_dev_get_next_match_dev() and helper macro To: Daniel Scally Cc: Linux Kernel Mailing List , ACPI Devel Maling List , Linux Media Mailing List , "open list:ACPI COMPONENT ARCHITECTURE (ACPICA)" , "Rafael J. Wysocki" , Len Brown , Greg Kroah-Hartman , Mauro Carvalho Chehab , Sergey Senozhatsky , yong.zhi@intel.com, Sakari Ailus , Bingbu Cao , tian.shu.qiu@intel.com, Robert Moore , Erik Kaneda , Petr Mladek , Steven Rostedt , Andy Shevchenko , Rasmus Villemoes , Laurent Pinchart , Jacopo Mondi , Kieran Bingham , hverkuil-cisco@xs4all.nl, m.felsch@pengutronix.de, Niklas Soderlund , prabhakar.mahadev-lad.rj@bp.renesas.com, Steve Longerbeam , Heikki Krogerus Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 7, 2021 at 2:31 PM Daniel Scally wrote: > > To ensure we handle situations in which multiple sensors of the same > model (and therefore _HID) are present in a system, we need to be able > to iterate over devices matching a known _HID but unknown _UID and _HRV > - add acpi_dev_get_next_match_dev() to accommodate that possibility and > change acpi_dev_get_first_match_dev() to simply call the new function > with a NULL starting point. Add an iterator macro for convenience. > > Reviewed-by: Andy Shevchenko > Reviewed-by: Sakari Ailus > Suggested-by: Andy Shevchenko > Signed-off-by: Daniel Scally Acked-by: Rafael J. Wysocki > --- > Changes in v5: > > - Changed commit subject > > drivers/acpi/utils.c | 30 ++++++++++++++++++++++++++---- > include/acpi/acpi_bus.h | 7 +++++++ > 2 files changed, 33 insertions(+), 4 deletions(-) > > diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c > index d5411a166685..ddca1550cce6 100644 > --- a/drivers/acpi/utils.c > +++ b/drivers/acpi/utils.c > @@ -843,12 +843,13 @@ bool acpi_dev_present(const char *hid, const char *uid, s64 hrv) > EXPORT_SYMBOL(acpi_dev_present); > > /** > - * acpi_dev_get_first_match_dev - Return the first match of ACPI device > + * acpi_dev_get_next_match_dev - Return the next match of ACPI device > + * @adev: Pointer to the previous acpi_device matching this @hid, @uid and @hrv > * @hid: Hardware ID of the device. > * @uid: Unique ID of the device, pass NULL to not check _UID > * @hrv: Hardware Revision of the device, pass -1 to not check _HRV > * > - * Return the first match of ACPI device if a matching device was present > + * Return the next match of ACPI device if another matching device was present > * at the moment of invocation, or NULL otherwise. > * > * The caller is responsible to call put_device() on the returned device. > @@ -856,8 +857,9 @@ EXPORT_SYMBOL(acpi_dev_present); > * See additional information in acpi_dev_present() as well. > */ > struct acpi_device * > -acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv) > +acpi_dev_get_next_match_dev(struct acpi_device *adev, const char *hid, const char *uid, s64 hrv) > { > + struct device *start = adev ? &adev->dev : NULL; > struct acpi_dev_match_info match = {}; > struct device *dev; > > @@ -865,9 +867,29 @@ acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv) > match.uid = uid; > match.hrv = hrv; > > - dev = bus_find_device(&acpi_bus_type, NULL, &match, acpi_dev_match_cb); > + dev = bus_find_device(&acpi_bus_type, start, &match, acpi_dev_match_cb); > return dev ? to_acpi_device(dev) : NULL; > } > +EXPORT_SYMBOL(acpi_dev_get_next_match_dev); > + > +/** > + * acpi_dev_get_first_match_dev - Return the first match of ACPI device > + * @hid: Hardware ID of the device. > + * @uid: Unique ID of the device, pass NULL to not check _UID > + * @hrv: Hardware Revision of the device, pass -1 to not check _HRV > + * > + * Return the first match of ACPI device if a matching device was present > + * at the moment of invocation, or NULL otherwise. > + * > + * The caller is responsible to call put_device() on the returned device. > + * > + * See additional information in acpi_dev_present() as well. > + */ > +struct acpi_device * > +acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv) > +{ > + return acpi_dev_get_next_match_dev(NULL, hid, uid, hrv); > +} > EXPORT_SYMBOL(acpi_dev_get_first_match_dev); > > /* > diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h > index 6d1879bf9440..02a716a0af5d 100644 > --- a/include/acpi/acpi_bus.h > +++ b/include/acpi/acpi_bus.h > @@ -683,9 +683,16 @@ static inline bool acpi_device_can_poweroff(struct acpi_device *adev) > > bool acpi_dev_hid_uid_match(struct acpi_device *adev, const char *hid2, const char *uid2); > > +struct acpi_device * > +acpi_dev_get_next_match_dev(struct acpi_device *adev, const char *hid, const char *uid, s64 hrv); > struct acpi_device * > acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv); > > +#define for_each_acpi_dev_match(adev, hid, uid, hrv) \ > + for (adev = acpi_dev_get_first_match_dev(hid, uid, hrv); \ > + adev; \ > + adev = acpi_dev_get_next_match_dev(adev, hid, uid, hrv)) > + > static inline void acpi_dev_put(struct acpi_device *adev) > { > put_device(&adev->dev); > -- > 2.25.1 >