[SRU][J:linux-bluefield][PATCH v3 5/9] ACPI: utils: Add acpi_dev_uid_to_integer() helper to get _UID as integer

Haifei Luo haifeil at nvidia.com
Mon Mar 24 01:59:21 UTC 2025


From: Andy Shevchenko <andriy.shevchenko at linux.intel.com>

BugLink: https://bugs.launchpad.net/bugs/2103386

Some users interpret _UID only as integer and for them it's easier to
have an integer representation of _UID. Add respective helper for that.

Change-Id: I45a4a2432a16b34c2291e9b8df0a9807c2f8788c
Signed-off-by: Andy Shevchenko <andriy.shevchenko at linux.intel.com>
Reviewed-by: Hans de Goede <hdegoede at redhat.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki at intel.com>
(cherry picked from commit 5db72fdb74983a1e81331aadf99ae2305f277562)
Signed-off-by: Haifei Luo <haifeil at nvidia.com>
---
 drivers/acpi/utils.c    | 24 ++++++++++++++++++++++++
 include/acpi/acpi_bus.h |  1 +
 include/linux/acpi.h    |  5 +++++
 3 files changed, 30 insertions(+)

diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
index d5cedffeeff9..0b19b0e4c100 100644
--- a/drivers/acpi/utils.c
+++ b/drivers/acpi/utils.c
@@ -755,6 +755,30 @@ bool acpi_dev_hid_uid_match(struct acpi_device *adev,
 }
 EXPORT_SYMBOL(acpi_dev_hid_uid_match);
 
+/**
+ * acpi_dev_uid_to_integer - treat ACPI device _UID as integer
+ * @adev: ACPI device to get _UID from
+ * @integer: output buffer for integer
+ *
+ * Considers _UID as integer and converts it to @integer.
+ *
+ * Returns 0 on success, or negative error code otherwise.
+ */
+int acpi_dev_uid_to_integer(struct acpi_device *adev, u64 *integer)
+{
+	const char *uid;
+
+	if (!adev)
+		return -ENODEV;
+
+	uid = acpi_device_uid(adev);
+	if (!uid)
+		return -ENODATA;
+
+	return kstrtou64(uid, 0, integer);
+}
+EXPORT_SYMBOL(acpi_dev_uid_to_integer);
+
 /**
  * acpi_dev_found - Detect presence of a given ACPI device in the namespace.
  * @hid: Hardware ID of the device.
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index 7a85ae6b7b00..031272a93d51 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -693,6 +693,7 @@ 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);
+int acpi_dev_uid_to_integer(struct acpi_device *adev, u64 *integer);
 
 void acpi_dev_clear_dependencies(struct acpi_device *supplier);
 struct acpi_device *acpi_dev_get_first_consumer_dev(struct acpi_device *supplier);
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index d7ab324fa3d6..9502d9c26ee6 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -751,6 +751,11 @@ acpi_dev_hid_uid_match(struct acpi_device *adev, const char *hid2, const char *u
 	return false;
 }
 
+static inline int acpi_dev_uid_to_integer(struct acpi_device *adev, u64 *integer)
+{
+	return -ENODEV;
+}
+
 static inline struct acpi_device *
 acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv)
 {
-- 
2.34.1




More information about the kernel-team mailing list