@@ -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
*
@@ -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;
@@ -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;
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(+)