Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp13442570pxu; Sun, 3 Jan 2021 15:20:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJzBO7jka3w3DeyOeTm6MVa7PKEKHu2bfIMg/I5QoBT9dJE0WHT7q1K8ZmpDuq66khdEk5/1 X-Received: by 2002:a17:906:408f:: with SMTP id u15mr65957897ejj.84.1609716001800; Sun, 03 Jan 2021 15:20:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609716001; cv=none; d=google.com; s=arc-20160816; b=HesLFWCFs6GNz/O46kPPWU8kJWqOneQVZVHZ6xWvM9NtlzIQ/2k+TfSWjZfFzqvHda T03jwuv491wo/yzBAzidliyfxJXf02uP+t9mBqiPMw1XTSiTVikDf9Qnx7sQ0715/iik CY9CL0xmT/VW91wZPaCFkHm14ViaPyfqyUBLmlTy+w4BAi5b3z4SId6XCTzrWM+hh1Bw 6ZOIyxvpRgkfQTAr7tVdCUYwZX7lNjLx6IVlwKHXgeVHAJHbAzvB/e4bgmY11mnGEi6r LbkcdIrOKPehuCOfc2S4yNwyiPkMJxwgyAv0dVrRfO2QrdE+GKehHve2vqxePb0j5wdR d6/g== 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=nSHC5UlNieNu4bBk+m3lt5nuTpfGzGP8mOOMr3doLJI=; b=b2PDmRQV1PZqHVPODe5vlOr/gb01cgWj4+il63ad5rJNPON6V/hzX1eyf11L5Z7EGm JvqlYCu33yu5IaCAi6QS+GcmmCTo2kUPbsa8SGkAMTJpBGJDPJbsmpdWwhFcu3CBYdbe BWukU3Cm+/GY9z3BptYX62DFbzTkC5vt6jQojAPJd+GLYGeGhuQcc2Ws6bK3gOyY1C8q Zrx30u86wTpJQIuJ3+zpQZGlshWxA3bPx6h1aqqKqX2+1C1DizjiP8V9OJB1vIPYKoiL z2LBOxX0jWLEEEl4b64R81gMS/U+jeKO9GrRsMEztGyoDb1Iw0gNWuRCkgHXURw1E3ee y6FA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Ob2LJ9Ed; 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 h8si27354227ejq.268.2021.01.03.15.19.38; Sun, 03 Jan 2021 15:20:01 -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=Ob2LJ9Ed; 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 S1728087AbhACXOl (ORCPT + 99 others); Sun, 3 Jan 2021 18:14:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727810AbhACXOV (ORCPT ); Sun, 3 Jan 2021 18:14:21 -0500 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 316BFC0617A4; Sun, 3 Jan 2021 15:13:12 -0800 (PST) Received: by mail-wr1-x42f.google.com with SMTP id c5so30002993wrp.6; Sun, 03 Jan 2021 15:13: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=nSHC5UlNieNu4bBk+m3lt5nuTpfGzGP8mOOMr3doLJI=; b=Ob2LJ9EdnGe0X+oxGKg6JeYQkREZJXye94UyBY9EFxE8ZsTFlTUecP9PKdytQsackQ U9sfwx39clBffLr9fe/P/2CHNBHZIPWid8O2TORLoFvkT5SHRLVknGARbzHgjXLT4pst cKTigEFkV0zmdwR8j1bS8OSuTLzwuUQj1npmbSMROSbbOZSQ53tZ2LLd2owXII1ZZbPZ 1aB0sihVdelw9ebXBKMmDXY/W4VRf6KmAxmYCDNq0F4uR7AdUx6OMb1txRYEpxyJO+Re 40l9jvBC5c2aO3xm7UsIshuIRaXDI+976TLAFVrWi4G4Y7bIR5WzRnFkrgwpl3JmmQoN Ln9Q== 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=nSHC5UlNieNu4bBk+m3lt5nuTpfGzGP8mOOMr3doLJI=; b=q5H1lFDPHJnohtoV6umnXCxiYG+DgTpZOVuv7Qh308QSvcRmW+U/i7Zr7tTzYSUNY1 JFtuZOQIQInwRzRzODbK4WGY+97Muwaw5POpmLRsZoAerz0TQBcIVd0LuCkUpvF6AWcw aBEYzWOsy/pQOMVuJykbse/dh3/SOoFnf3KbELKr9M1Xlzse0yJ7zFvzOOlxHNyGOVaq sWJg+f/7CsO4Fg5ZBw4vg29ICo6tkZcLVinFwVNfhlSn7H76cmaC4XvXtejoervDFluU v5Xwrny+z996QT8gvQPCSd4XoNApNQ1Tk1ndJkPIa2Pgk2eUJUi4tIoHEQrAmhVQ/05p u6dA== X-Gm-Message-State: AOAM531vWvrGKRku/RmNp2+gXrJXdvrtXVP9U80e+Y/z+UPgToVBjFXE qrysEvjbJkv5qILpS9O/X0R/Pio4Lfn+dA/f X-Received: by 2002:adf:94e1:: with SMTP id 88mr51584053wrr.341.1609715590980; Sun, 03 Jan 2021 15:13:10 -0800 (PST) Received: from valhalla.home ([2.29.208.120]) by smtp.gmail.com with ESMTPSA id h9sm32571018wme.11.2021.01.03.15.13.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Jan 2021 15:13:10 -0800 (PST) From: Daniel Scally To: 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 Cc: 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, 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, slongerbeam@gmail.com, heikki.krogerus@linux.intel.com, linus.walleij@linaro.org Subject: [PATCH v4 13/15] acpi: Add acpi_dev_get_next_match_dev() and helper macro Date: Sun, 3 Jan 2021 23:12:33 +0000 Message-Id: <20210103231235.792999-14-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210103231235.792999-1-djrscally@gmail.com> References: <20210103231235.792999-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 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