Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp13791452pxu; Mon, 4 Jan 2021 04:45:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJyo07jDZbMBnox4yG5qmLectoYyt/KJGKIsWyv+dcl6LqKOB8ZoSxiSQP1xaVvWrsCQzVAR X-Received: by 2002:aa7:d919:: with SMTP id a25mr68739711edr.81.1609764333479; Mon, 04 Jan 2021 04:45:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609764333; cv=none; d=google.com; s=arc-20160816; b=TAh/bD/aEqMDUIEoM86EemEYAYW/1By2eCsvoU2p39tVV029WrEjqyx4ElEdvCnS/C wD03/Q7vesJ4wZXZVzr7iXb6+x2WHKn9ukEVR88UYMOf1t7cjP3BpIK8pbjMnM/wA7sy i6IOG2p0Sq2+WK8XOegfAIk4EuQYrpE/wTwl7wDZGrg6ASJcy5JzGpkPpl0Hkja7RV2B bUjxzJVjNi0r4O8c0+DKBGcC1kr/sSdGrBvgNjlvz5aBt1mYW8vMSSWHbHUKXC0/KZOB QfqRXXAqcr/8gaMoy5n22QT0auZ5DOIrrtik1vJS63Jo5VqmZOpw+saUKcXfWMfN35wC KEMA== 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=RwUATCTirc76PA9jYJiPAIaksuvG+914e/ZGd4UJW6A=; b=s6uSI5+jZFVc44QXF/BQDrAAmsmPCOS7iwWaumFkcNq4KejAtXhfjHKQ9M1TzNhDxH r5RnZLcYItjt/ut/2pG23oNeonEGqtzlVURjvLfi5pSkm5cllKPyNDeQ1phc/8HLFfXC tgcYVR6n0Xfdob1F/iHeyDjAP5EWaHD9cYJwZWm0iUsi30hfRinOK2ga/fQvRV4V+hqS tBBTFqmFcYTDxB0XtSY3rgCpBJSk1qecjqV5w5zfsqUadxwAtdPOOOV2uhrC1KHGHj2K GjdDzVQvA7oc+wLfuLnHSGdbs9/V/wXIYpbO+jlUOGdIHXrr4LxLkb++mm5nXaEIeisJ 0fXw== 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 s25si28749528ejz.414.2021.01.04.04.45.10; Mon, 04 Jan 2021 04:45:33 -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 S1726890AbhADMnU (ORCPT + 99 others); Mon, 4 Jan 2021 07:43:20 -0500 Received: from mga07.intel.com ([134.134.136.100]:18371 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726789AbhADMnU (ORCPT ); Mon, 4 Jan 2021 07:43:20 -0500 IronPort-SDR: 5pu6/Y+350I0eB63FcMdgH2pJAXZpYG58KeIk+Xcjr3qiCy+S/OmwiJ7/ozsZK2JYsMw3oNO5R 651eAV6+RZSw== X-IronPort-AV: E=McAfee;i="6000,8403,9853"; a="241029868" X-IronPort-AV: E=Sophos;i="5.78,474,1599548400"; d="scan'208";a="241029868" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Jan 2021 04:41:33 -0800 IronPort-SDR: BZJ0vJPCKSGEmCqRobP/9fXL4Hzw8UC6X/HWbkGKiYRna9+20Xa7UNo6F1J6X0Zby9o87oh7Hv 8AWg9dDfckww== X-IronPort-AV: E=Sophos;i="5.78,474,1599548400"; d="scan'208";a="401958746" 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; 04 Jan 2021 04:41:27 -0800 Received: from andy by smile with local (Exim 4.94) (envelope-from ) id 1kwPBs-001ZNb-71; Mon, 04 Jan 2021 14:42:28 +0200 Date: Mon, 4 Jan 2021 14:42:28 +0200 From: Andy Shevchenko To: Daniel Scally Cc: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-media@vger.kernel.org, devel@acpica.org, gregkh@linuxfoundation.org, rjw@rjwysocki.net, sergey.senozhatsky@gmail.com, mchehab@kernel.org, lenb@kernel.org, yong.zhi@intel.com, sakari.ailus@linux.intel.com, bingbu.cao@intel.com, tian.shu.qiu@intel.com, robert.moore@intel.com, erik.kaneda@intel.com, pmladek@suse.com, rostedt@goodmis.org, linux@rasmusvillemoes.dk, laurent.pinchart+renesas@ideasonboard.com, jacopo+renesas@jmondi.org, kieran.bingham+renesas@ideasonboard.com, hverkuil-cisco@xs4all.nl, m.felsch@pengutronix.de, niklas.soderlund+renesas@ragnatech.se, slongerbeam@gmail.com, heikki.krogerus@linux.intel.com, linus.walleij@linaro.org Subject: Re: [PATCH v4 13/15] acpi: Add acpi_dev_get_next_match_dev() and helper macro Message-ID: <20210104124228.GU4077@smile.fi.intel.com> References: <20210103231235.792999-1-djrscally@gmail.com> <20210103231235.792999-14-djrscally@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210103231235.792999-14-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 Sun, Jan 03, 2021 at 11:12:33PM +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. I guess we need Rafael's blessing on this. > Reviewed-by: Andy Shevchenko > Reviewed-by: Sakari Ailus > Suggested-by: Andy Shevchenko > Signed-off-by: Daniel Scally > --- > Changes in v4: > > - None > > 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 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