Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp301910pxu; Thu, 7 Jan 2021 05:33:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJwf9P7S7Js8D05bSAusU61yFJh+tt/ht3kwSKI4dWgrh89V2gf2R9ynakX1JQnBGUR79iu5 X-Received: by 2002:a17:906:b7d6:: with SMTP id fy22mr6358047ejb.219.1610026412809; Thu, 07 Jan 2021 05:33:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610026412; cv=none; d=google.com; s=arc-20160816; b=Stu5BACc4KPTis6RAFWe7S1z9X00z6KFo/AlkmoHQxYwg4hwbCmDRt/Dc0bfRj2yL9 MEYQ6kQtQ44PIGSJf+lNAV37SlE6gZHmlyRhA+aTZw9lVGA/hR/SpI6h/cYgnbWNWPsD Z+aEkjnIrnV6YXHXi3G6EViMFipSeSIrLt3qgTfBx8EGywSBS3TNiS3sOWTIl/waCSI1 kM3iO90OsKffz1rMrQMHpp+SKcfm1W0iorc0e8jVeoPjibnOMHVgBQISo4tIgNis+QQu JzhmMeEtpHGqbE7uXlH2+ZIJDGvUSwa2iqIDpi9algHTCbmOJmvkWnX/D1Or6DQWIal7 +dqQ== 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=6Le4zT3Fvpu6jC0cQUY4eirqzD42KUANZUESAszTPTg=; b=MKVDZPvgIdwEVcKxayapyWKVYnm5Orj7Hk14mCsHb9SZFgCBrfWrXxXzniwffuBUuw xCk4uxCkGlc9SGel5p2kD+z9rDgtrpOz/MUQzAC0QlcwXEhefMdWrqfFsapCOL3qAbmS /AGI1Su47IltshSabQ9XxnmTAzzrZqPiM+hUV1HmaAooifiEJaTOz+6l6JRqvfoBn46z QSPkdkDlmGppHKliGBfzCqJrMdi1Q/of/U+kgVw3q8B5pEH0ovnZPS9uIL9SYss7JWsa 1y0hMrA3LIo8d6VojiEuZcIStPD4lv6JE0KTWWzldghqmvyTutOEpkILA6ljPMmQxiXG CE9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=HtFPlwNQ; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jw12si2262502ejb.176.2021.01.07.05.33.08; Thu, 07 Jan 2021 05:33:32 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=HtFPlwNQ; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728698AbhAGNaa (ORCPT + 99 others); Thu, 7 Jan 2021 08:30:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728642AbhAGNaV (ORCPT ); Thu, 7 Jan 2021 08:30:21 -0500 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8872C061290; Thu, 7 Jan 2021 05:29:12 -0800 (PST) Received: by mail-wm1-x335.google.com with SMTP id k10so5174835wmi.3; Thu, 07 Jan 2021 05:29:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6Le4zT3Fvpu6jC0cQUY4eirqzD42KUANZUESAszTPTg=; b=HtFPlwNQuwXeaXYVP5hW0BjqCDbNoiZ6QLsp2B3fIhxEgKbZk7lYAacvLabRP089xb 2J+KLQ8RK1DoCZ37RlfwZOxG8FkraiPiJXabQSPWIBQS0zVW2mktLD/3JvKfZA0miyGN MFfdvbPGypqeixq+zkdFnXL80nhVfFDSGY0Ia5MI3VzhE4NDJIK19KCqxE7uvBjLaXau xyPe37HjFdwEAmWXpOYOeECYLnoDxY9SO6sPZvBEVheEx6hcbGhu/ySxYAJJeTsE1xqM d66TRphF5A4ht0RBu/xa9n/H934s2Sti+5QGbD6yx5FE9QzUbvNco7v0FY7jeiQfVEJH xUKw== 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=6Le4zT3Fvpu6jC0cQUY4eirqzD42KUANZUESAszTPTg=; b=dYpK46xss4q3raL/o6KbeuJO0oVOdmWVt+L2ybYRgURdbQG8PVGmL+5scBrN82WOu3 HrdK5DArofCMQL46zIeKMvsvz2c4Wh8Lefyuiu5EBGJU2WVzn5/u2ts0q/zT00fydx4S y+wMURfn+8HGEtwzZZd2JwHfg79a+dDKdUV7rpPnTRPgMHXaIZXAILQJeuXVRMkt/amQ GYzVTyjQ1HUc0cZiKdLha5p3lvbmD5TWrLuJa4/OzibnVvkwSaUhQYjGlIypRU+/MGOI n52Gsv+8vb/J14MDZGM+UGds44wrL6DTfnV9G2KOGf2GpgNQppHA4S4/cJaJaJpOV/1F +vTA== X-Gm-Message-State: AOAM531lS7Q/drVDWCa/+Qx/rkPkeZVViOXk/vCfXIq6QL0TW2kyQdZk BPB5Kjs8fNjEe6Chybpb3RYBm3txPEFvjsH7 X-Received: by 2002:a7b:ce96:: with SMTP id q22mr8049722wmj.164.1610026151613; Thu, 07 Jan 2021 05:29:11 -0800 (PST) Received: from valhalla.home ([2.29.208.120]) by smtp.gmail.com with ESMTPSA id o83sm7660125wme.21.2021.01.07.05.29.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jan 2021 05:29:11 -0800 (PST) From: Daniel Scally To: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-media@vger.kernel.org, devel@acpica.org, rjw@rjwysocki.net, lenb@kernel.org, gregkh@linuxfoundation.org, mchehab@kernel.org, sergey.senozhatsky@gmail.com Cc: 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, andriy.shevchenko@linux.intel.com, 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, prabhakar.mahadev-lad.rj@bp.renesas.com, slongerbeam@gmail.com, heikki.krogerus@linux.intel.com Subject: [PATCH v5 13/15] ACPI / bus: Add acpi_dev_get_next_match_dev() and helper macro Date: Thu, 7 Jan 2021 13:28:36 +0000 Message-Id: <20210107132838.396641-14-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210107132838.396641-1-djrscally@gmail.com> References: <20210107132838.396641-1-djrscally@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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