From a3a62ca256ab1d1ba771ee243ec4a8e8b7856f08 Mon Sep 17 00:00:00 2001 From: Raag Jadav Date: Tue, 24 Oct 2023 11:50:13 +0530 Subject: 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 Reviewed-by: Mika Westerberg Signed-off-by: Rafael J. Wysocki --- drivers/acpi/utils.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'drivers/acpi/utils.c') diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c index 2ea14648a661..07ee0d23a188 100644 --- a/drivers/acpi/utils.c +++ b/drivers/acpi/utils.c @@ -768,20 +768,43 @@ bool acpi_check_dsm(acpi_handle handle, const guid_t *guid, u64 rev, u64 funcs) } EXPORT_SYMBOL(acpi_check_dsm); +/** + * acpi_dev_uid_match - Match device by supplied UID + * @adev: ACPI device to match. + * @uid2: Unique ID of the device. + * + * Matches UID in @adev with given @uid2. + * + * Returns: + * - %true if matches. + * - %false otherwise. + */ +bool acpi_dev_uid_match(struct acpi_device *adev, const char *uid2) +{ + const char *uid1 = acpi_device_uid(adev); + + return uid1 && uid2 && !strcmp(uid1, uid2); +} +EXPORT_SYMBOL_GPL(acpi_dev_uid_match); + /** * acpi_dev_hid_uid_match - Match device by supplied HID and UID * @adev: ACPI device to match. * @hid2: Hardware ID of the device. * @uid2: Unique ID of the device, pass NULL to not check _UID. * - * Matches HID and UID in @adev with given @hid2 and @uid2. - * Returns true if matches. + * Matches HID and UID in @adev with given @hid2 and @uid2. Absence of @uid2 + * will be treated as a match. If user wants to validate @uid2, it should be + * done before calling this function. + * + * Returns: + * - %true if matches or @uid2 is NULL. + * - %false otherwise. */ bool acpi_dev_hid_uid_match(struct acpi_device *adev, const char *hid2, const char *uid2) { const char *hid1 = acpi_device_hid(adev); - const char *uid1 = acpi_device_uid(adev); if (strcmp(hid1, hid2)) return false; @@ -789,7 +812,7 @@ bool acpi_dev_hid_uid_match(struct acpi_device *adev, if (!uid2) return true; - return uid1 && !strcmp(uid1, uid2); + return acpi_dev_uid_match(adev, uid2); } EXPORT_SYMBOL(acpi_dev_hid_uid_match); -- cgit v1.2.3 From 3a3cc54605e4854b241ac3e2771b6f2a77aedd90 Mon Sep 17 00:00:00 2001 From: Raag Jadav Date: Tue, 24 Oct 2023 11:50:15 +0530 Subject: ACPI: utils: use acpi_dev_uid_match() for matching _UID Convert manual _UID references to use the standard ACPI helper. Signed-off-by: Raag Jadav Signed-off-by: Rafael J. Wysocki --- drivers/acpi/utils.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'drivers/acpi/utils.c') diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c index 07ee0d23a188..558464c088bf 100644 --- a/drivers/acpi/utils.c +++ b/drivers/acpi/utils.c @@ -886,8 +886,7 @@ static int acpi_dev_match_cb(struct device *dev, const void *data) if (acpi_match_device_ids(adev, match->hid)) return 0; - if (match->uid && (!adev->pnp.unique_id || - strcmp(adev->pnp.unique_id, match->uid))) + if (match->uid && !acpi_dev_uid_match(adev, match->uid)) return 0; if (match->hrv == -1) -- cgit v1.2.3