Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp3776659pxu; Mon, 30 Nov 2020 10:01:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJzD/EvfyRpjwOKxKBB4ZpgaQUReQHi1WjkkxWgmd+JkqivCnvikBaItn7h4/8Uj9VwLLAgf X-Received: by 2002:aa7:dccd:: with SMTP id w13mr23457536edu.385.1606759300515; Mon, 30 Nov 2020 10:01:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606759300; cv=none; d=google.com; s=arc-20160816; b=aLRNkjwJ+teA1A0lfB0h2OQAZFw7yEhqvcmZpQ2mHwFXsARvLqhKT2qnh3pAFJNQLz h+e0OIL2fJKv0nkJKXkyPTUFOK1BRgaDi9e3mZPT30VK4wvqkoHfkvksxRttmRYRXHPy ju3H363WxIYE01zUkRtJ8CRjif5kOK4AzdQo3ayHGNXjziXF2HQkNNYpLc+b2kB8AiAO WKDDv8396FTJ+8khzPNi2X4vio8zw6LVN4LbEzJ3pvHODF2elIBTaJttr5c3rSKmyq2g HMopcjHZrnwudJ7eAaiqjaMqVA3p9VRBhrZY5dwKI0B48+N+GLUOOndn+8vwaZrO4KKE M+vQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :ironport-sdr:ironport-sdr; bh=m3+jxzP59ZOw8vJRW8cdYcg7A1qoisl53SQp1tss3Tg=; b=erctpcVmMTRaCwP24ZiY+1p1Q2U0cLTVfHhtS9a79cufxLl5gMUg5ZUUb5/6m/9RV8 KdES2yJqN/07jk0DpPAtGjuVfo6V3fLjjeNWHuYe34vuEeaXF1fgp50J1lia7lgXjKOQ 0/asglP6T54QDw+YX+REmNuiGYwdHSyQJBVkv7Z9MWTm3HGBG+e3KSSgtHwgVpp/u6Kx oixVsHkenqrz3pAatqCJmJN0XMryhXqSY+9J+uSTQquyucjrlFye6KDZpRXPcEKmwulp 1eYDy2pZ1Orjb/nJD5qSX56ub29TYPAFdQjvnhWPGWWtRJJ31UqkiLZLZD6mfeRI34yh W9Cw== 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n2si11981414edi.362.2020.11.30.10.01.15; Mon, 30 Nov 2020 10:01:40 -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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729459AbgK3R7l (ORCPT + 99 others); Mon, 30 Nov 2020 12:59:41 -0500 Received: from mga09.intel.com ([134.134.136.24]:16820 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729446AbgK3R7l (ORCPT ); Mon, 30 Nov 2020 12:59:41 -0500 IronPort-SDR: hAP0otCnQayn8j5L8V99EgKl6yyKCVa7ZoL/80PDHlnZMZhrN8RXfFfG9vjjGAAG6+4Zd97ZdE 4hwDBK4EZ32Q== X-IronPort-AV: E=McAfee;i="6000,8403,9821"; a="172837830" X-IronPort-AV: E=Sophos;i="5.78,382,1599548400"; d="scan'208";a="172837830" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2020 09:58:00 -0800 IronPort-SDR: xwu/OPLpcaaxnVx9HQl8RwomhX/vccrWefNJbtu0WOfrQ89+BA0p13Cq2WWue95QDOxYOXhbAF c0qiRlTjH9Eg== X-IronPort-AV: E=Sophos;i="5.78,382,1599548400"; d="scan'208";a="372582184" Received: from smile.fi.intel.com (HELO smile) ([10.237.68.40]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2020 09:57:53 -0800 Received: from andy by smile with local (Exim 4.94) (envelope-from ) id 1kjnRu-00B6Gs-EU; Mon, 30 Nov 2020 19:58:54 +0200 Date: Mon, 30 Nov 2020 19:58:54 +0200 From: Andy Shevchenko To: Daniel Scally Cc: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-gpio@vger.kernel.org, linux-i2c@vger.kernel.org, linux-media@vger.kernel.org, devel@acpica.org, rjw@rjwysocki.net, lenb@kernel.org, gregkh@linuxfoundation.org, mika.westerberg@linux.intel.com, linus.walleij@linaro.org, bgolaszewski@baylibre.com, wsa@kernel.org, yong.zhi@intel.com, sakari.ailus@linux.intel.com, bingbu.cao@intel.com, tian.shu.qiu@intel.com, mchehab@kernel.org, robert.moore@intel.com, erik.kaneda@intel.com, pmladek@suse.com, rostedt@goodmis.org, sergey.senozhatsky@gmail.com, linux@rasmusvillemoes.dk, kieran.bingham+renesas@ideasonboard.com, jacopo+renesas@jmondi.org, laurent.pinchart+renesas@ideasonboard.com, jorhand@linux.microsoft.com, kitakar@gmail.com, heikki.krogerus@linux.intel.com Subject: Re: [PATCH 12/18] acpi: Add acpi_dev_get_next_match_dev() and macro to iterate through acpi_devices matching a given _HID Message-ID: <20201130175854.GU4077@smile.fi.intel.com> References: <20201130133129.1024662-1-djrscally@gmail.com> <20201130133129.1024662-13-djrscally@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201130133129.1024662-13-djrscally@gmail.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Nov 30, 2020 at 01:31:23PM +0000, 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 > Suggested-by: Andy Shevchenko > Signed-off-by: Daniel Scally > --- > Changes since RFC v3: > > - Patch introduced > > 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..c177165c8db2 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 a3abcc4b7d9f..0a028ba967d3 100644 > --- a/include/acpi/acpi_bus.h > +++ b/include/acpi/acpi_bus.h > @@ -688,9 +688,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 > -- With Best Regards, Andy Shevchenko