public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Hans de Goede <hdegoede@redhat.com>,
	"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
	linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org,
	acpica-devel@lists.linuxfoundation.org
Cc: "Rafael J. Wysocki" <rafael@kernel.org>,
	Len Brown <lenb@kernel.org>,
	Robert Moore <robert.moore@intel.com>
Subject: [PATCH v1 2/3] ACPI: utils: Add acpi_get_first_match_physical_node()
Date: Mon, 23 Jan 2023 19:10:05 +0200	[thread overview]
Message-ID: <20230123171006.58274-2-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20230123171006.58274-1-andriy.shevchenko@linux.intel.com>

There are drivers that are using a logic that is combined in the offered
acpi_get_first_match_physical_node(). The rationale to have this helper
not only redunction of the lines of code, but improving the robustness
by properly handling the reference counters on the error paths.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/acpi/utils.c    | 28 ++++++++++++++++++++++++++++
 include/acpi/acpi_bus.h |  3 +++
 include/linux/acpi.h    |  6 ++++++
 3 files changed, 37 insertions(+)

diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
index 2ea14648a661..052e263d2246 100644
--- a/drivers/acpi/utils.c
+++ b/drivers/acpi/utils.c
@@ -965,6 +965,34 @@ acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv)
 }
 EXPORT_SYMBOL(acpi_dev_get_first_match_dev);
 
+/**
+ * acpi_get_first_match_physical_node - Return the physical node of 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 physical node of the first match of ACPI device if a matching
+ * device was present at the moment of invocation, or NULL otherwise.
+ *
+ * The caller is responsible for invoking put_device() on the returned device.
+ *
+ * See additional information in acpi_dev_present() as well.
+ */
+struct device *acpi_get_first_match_physical_node(const char *hid, const char *uid, s64 hrv)
+{
+	struct acpi_device *adev;
+	struct device *dev;
+
+	adev = acpi_dev_get_first_match_dev(hid, uid, hrv);
+	if (!adev)
+		return NULL;
+
+	dev = get_device(acpi_get_first_physical_node(adev));
+	acpi_dev_put(adev);
+	return dev;
+}
+EXPORT_SYMBOL(acpi_get_first_match_physical_node);
+
 /**
  * acpi_reduced_hardware - Return if this is an ACPI-reduced-hw machine
  *
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index 0584e9f6e339..e62af2f71362 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -777,6 +777,9 @@ acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv);
 	     adev;							\
 	     adev = acpi_dev_get_next_match_dev(adev, hid, uid, hrv))
 
+struct device *
+acpi_get_first_match_physical_node(const char *hid, const char *uid, s64 hrv);
+
 static inline struct acpi_device *acpi_dev_get(struct acpi_device *adev)
 {
 	return adev ? to_acpi_device(get_device(&adev->dev)) : NULL;
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 4b12dad5a8a4..29bae77d819a 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -814,6 +814,12 @@ acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv)
 	return NULL;
 }
 
+static inline struct device *
+acpi_get_first_match_physical_node(const char *hid, const char *uid, s64 hrv)
+{
+	return NULL;
+}
+
 static inline bool acpi_reduced_hardware(void)
 {
 	return false;
-- 
2.39.0


  reply	other threads:[~2023-01-23 17:14 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-23 17:10 [PATCH v1 1/3] ACPI: video: Fix refcounting in apple_gmux_backlight_present() Andy Shevchenko
2023-01-23 17:10 ` Andy Shevchenko [this message]
2023-01-25 15:21   ` [PATCH v1 2/3] ACPI: utils: Add acpi_get_first_match_physical_node() Andy Shevchenko
2023-01-23 17:10 ` [PATCH v1 3/3] ACPI: video: Switch to use acpi_get_first_match_physical_node() Andy Shevchenko
2023-01-23 17:46 ` [PATCH v1 1/3] ACPI: video: Fix refcounting in apple_gmux_backlight_present() Hans de Goede
2023-01-23 18:18   ` Andy Shevchenko
2023-01-23 19:24     ` Rafael J. Wysocki
2023-01-24  9:04       ` Andy Shevchenko
2023-01-23 22:10     ` Hans de Goede
2023-01-24  9:05       ` Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230123171006.58274-2-andriy.shevchenko@linux.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=acpica-devel@lists.linuxfoundation.org \
    --cc=hdegoede@redhat.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafael.j.wysocki@intel.com \
    --cc=rafael@kernel.org \
    --cc=robert.moore@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox