Skip to content

Commit a3a62ca

Browse files
raagjadavrafaeljw
authored andcommitted
ACPI: utils: Introduce acpi_dev_uid_match() for matching _UID
Introduce acpi_dev_uid_match() helper that matches the device with supplied _UID string. Signed-off-by: Raag Jadav <[email protected]> Reviewed-by: Mika Westerberg <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent bb3dcf0 commit a3a62ca

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

drivers/acpi/utils.c

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -768,28 +768,51 @@ bool acpi_check_dsm(acpi_handle handle, const guid_t *guid, u64 rev, u64 funcs)
768768
}
769769
EXPORT_SYMBOL(acpi_check_dsm);
770770

771+
/**
772+
* acpi_dev_uid_match - Match device by supplied UID
773+
* @adev: ACPI device to match.
774+
* @uid2: Unique ID of the device.
775+
*
776+
* Matches UID in @adev with given @uid2.
777+
*
778+
* Returns:
779+
* - %true if matches.
780+
* - %false otherwise.
781+
*/
782+
bool acpi_dev_uid_match(struct acpi_device *adev, const char *uid2)
783+
{
784+
const char *uid1 = acpi_device_uid(adev);
785+
786+
return uid1 && uid2 && !strcmp(uid1, uid2);
787+
}
788+
EXPORT_SYMBOL_GPL(acpi_dev_uid_match);
789+
771790
/**
772791
* acpi_dev_hid_uid_match - Match device by supplied HID and UID
773792
* @adev: ACPI device to match.
774793
* @hid2: Hardware ID of the device.
775794
* @uid2: Unique ID of the device, pass NULL to not check _UID.
776795
*
777-
* Matches HID and UID in @adev with given @hid2 and @uid2.
778-
* Returns true if matches.
796+
* Matches HID and UID in @adev with given @hid2 and @uid2. Absence of @uid2
797+
* will be treated as a match. If user wants to validate @uid2, it should be
798+
* done before calling this function.
799+
*
800+
* Returns:
801+
* - %true if matches or @uid2 is NULL.
802+
* - %false otherwise.
779803
*/
780804
bool acpi_dev_hid_uid_match(struct acpi_device *adev,
781805
const char *hid2, const char *uid2)
782806
{
783807
const char *hid1 = acpi_device_hid(adev);
784-
const char *uid1 = acpi_device_uid(adev);
785808

786809
if (strcmp(hid1, hid2))
787810
return false;
788811

789812
if (!uid2)
790813
return true;
791814

792-
return uid1 && !strcmp(uid1, uid2);
815+
return acpi_dev_uid_match(adev, uid2);
793816
}
794817
EXPORT_SYMBOL(acpi_dev_hid_uid_match);
795818

include/acpi/acpi_bus.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,7 @@ static inline bool acpi_device_can_poweroff(struct acpi_device *adev)
760760
adev->power.states[ACPI_STATE_D3_HOT].flags.explicit_set);
761761
}
762762

763+
bool acpi_dev_uid_match(struct acpi_device *adev, const char *uid2);
763764
bool acpi_dev_hid_uid_match(struct acpi_device *adev, const char *hid2, const char *uid2);
764765
int acpi_dev_uid_to_integer(struct acpi_device *adev, u64 *integer);
765766

include/linux/acpi.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,11 @@ static inline bool acpi_dev_present(const char *hid, const char *uid, s64 hrv)
787787

788788
struct acpi_device;
789789

790+
static inline bool acpi_dev_uid_match(struct acpi_device *adev, const char *uid2)
791+
{
792+
return false;
793+
}
794+
790795
static inline bool
791796
acpi_dev_hid_uid_match(struct acpi_device *adev, const char *hid2, const char *uid2)
792797
{

0 commit comments

Comments
 (0)