Skip to content

Commit 5db72fd

Browse files
andy-shevrafaeljw
authored andcommitted
ACPI: utils: Add acpi_dev_uid_to_integer() helper to get _UID as integer
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. Signed-off-by: Andy Shevchenko <[email protected]> Reviewed-by: Hans de Goede <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 521a547 commit 5db72fd

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

drivers/acpi/utils.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,30 @@ bool acpi_dev_hid_uid_match(struct acpi_device *adev,
793793
}
794794
EXPORT_SYMBOL(acpi_dev_hid_uid_match);
795795

796+
/**
797+
* acpi_dev_uid_to_integer - treat ACPI device _UID as integer
798+
* @adev: ACPI device to get _UID from
799+
* @integer: output buffer for integer
800+
*
801+
* Considers _UID as integer and converts it to @integer.
802+
*
803+
* Returns 0 on success, or negative error code otherwise.
804+
*/
805+
int acpi_dev_uid_to_integer(struct acpi_device *adev, u64 *integer)
806+
{
807+
const char *uid;
808+
809+
if (!adev)
810+
return -ENODEV;
811+
812+
uid = acpi_device_uid(adev);
813+
if (!uid)
814+
return -ENODATA;
815+
816+
return kstrtou64(uid, 0, integer);
817+
}
818+
EXPORT_SYMBOL(acpi_dev_uid_to_integer);
819+
796820
/**
797821
* acpi_dev_found - Detect presence of a given ACPI device in the namespace.
798822
* @hid: Hardware ID of the device.

include/acpi/acpi_bus.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,7 @@ static inline bool acpi_device_can_poweroff(struct acpi_device *adev)
733733
}
734734

735735
bool acpi_dev_hid_uid_match(struct acpi_device *adev, const char *hid2, const char *uid2);
736+
int acpi_dev_uid_to_integer(struct acpi_device *adev, u64 *integer);
736737

737738
void acpi_dev_clear_dependencies(struct acpi_device *supplier);
738739
bool acpi_dev_ready_for_enumeration(const struct acpi_device *device);

include/linux/acpi.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,11 @@ acpi_dev_hid_uid_match(struct acpi_device *adev, const char *hid2, const char *u
798798
return false;
799799
}
800800

801+
static inline int acpi_dev_uid_to_integer(struct acpi_device *adev, u64 *integer)
802+
{
803+
return -ENODEV;
804+
}
805+
801806
static inline struct acpi_device *
802807
acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv)
803808
{

0 commit comments

Comments
 (0)