Skip to content

Commit 57b8543

Browse files
raagjadavrafaeljw
authored andcommitted
ACPI: bus: update acpi_dev_uid_match() to support multiple types
According to the ACPI specification, a _UID object can evaluate to either a numeric value or a string. Update acpi_dev_uid_match() to support _UID matching for both integer and string types. Suggested-by: Mika Westerberg <mika.westerberg@linux.intel.com> Signed-off-by: Raag Jadav <raag.jadav@intel.com> [ rjw: Rename auxiliary macros, relocate kerneldoc comment ] Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 33cc938 commit 57b8543

3 files changed

Lines changed: 43 additions & 25 deletions

File tree

drivers/acpi/utils.c

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -824,25 +824,6 @@ bool acpi_check_dsm(acpi_handle handle, const guid_t *guid, u64 rev, u64 funcs)
824824
}
825825
EXPORT_SYMBOL(acpi_check_dsm);
826826

827-
/**
828-
* acpi_dev_uid_match - Match device by supplied UID
829-
* @adev: ACPI device to match.
830-
* @uid2: Unique ID of the device.
831-
*
832-
* Matches UID in @adev with given @uid2.
833-
*
834-
* Returns:
835-
* - %true if matches.
836-
* - %false otherwise.
837-
*/
838-
bool acpi_dev_uid_match(struct acpi_device *adev, const char *uid2)
839-
{
840-
const char *uid1 = acpi_device_uid(adev);
841-
842-
return uid1 && uid2 && !strcmp(uid1, uid2);
843-
}
844-
EXPORT_SYMBOL_GPL(acpi_dev_uid_match);
845-
846827
/**
847828
* acpi_dev_hid_uid_match - Match device by supplied HID and UID
848829
* @adev: ACPI device to match.

include/acpi/acpi_bus.h

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,10 +764,49 @@ static inline bool acpi_device_can_poweroff(struct acpi_device *adev)
764764
adev->power.states[ACPI_STATE_D3_HOT].flags.explicit_set);
765765
}
766766

767-
bool acpi_dev_uid_match(struct acpi_device *adev, const char *uid2);
768767
bool acpi_dev_hid_uid_match(struct acpi_device *adev, const char *hid2, const char *uid2);
769768
int acpi_dev_uid_to_integer(struct acpi_device *adev, u64 *integer);
770769

770+
static inline bool acpi_str_uid_match(struct acpi_device *adev, const char *uid2)
771+
{
772+
const char *uid1 = acpi_device_uid(adev);
773+
774+
return uid1 && uid2 && !strcmp(uid1, uid2);
775+
}
776+
777+
static inline bool acpi_int_uid_match(struct acpi_device *adev, u64 uid2)
778+
{
779+
u64 uid1;
780+
781+
return !acpi_dev_uid_to_integer(adev, &uid1) && uid1 == uid2;
782+
}
783+
784+
#define TYPE_ENTRY(type, x) \
785+
const type: x, \
786+
type: x
787+
788+
#define ACPI_STR_TYPES(match) \
789+
TYPE_ENTRY(unsigned char *, match), \
790+
TYPE_ENTRY(signed char *, match), \
791+
TYPE_ENTRY(char *, match), \
792+
TYPE_ENTRY(void *, match)
793+
794+
/**
795+
* acpi_dev_uid_match - Match device by supplied UID
796+
* @adev: ACPI device to match.
797+
* @uid2: Unique ID of the device.
798+
*
799+
* Matches UID in @adev with given @uid2.
800+
*
801+
* Returns: %true if matches, %false otherwise.
802+
*/
803+
#define acpi_dev_uid_match(adev, uid2) \
804+
_Generic(uid2, \
805+
/* Treat @uid2 as a string for acpi string types */ \
806+
ACPI_STR_TYPES(acpi_str_uid_match), \
807+
/* Treat as an integer otherwise */ \
808+
default: acpi_int_uid_match)(adev, uid2)
809+
771810
void acpi_dev_clear_dependencies(struct acpi_device *supplier);
772811
bool acpi_dev_ready_for_enumeration(const struct acpi_device *device);
773812
struct acpi_device *acpi_dev_get_next_consumer_dev(struct acpi_device *supplier,

include/linux/acpi.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,9 @@ const char *acpi_get_subsystem_id(acpi_handle handle);
756756
#define ACPI_HANDLE(dev) (NULL)
757757
#define ACPI_HANDLE_FWNODE(fwnode) (NULL)
758758

759+
/* Get rid of the -Wunused-variable for adev */
760+
#define acpi_dev_uid_match(adev, uid2) (adev && false)
761+
759762
#include <acpi/acpi_numa.h>
760763

761764
struct fwnode_handle;
@@ -772,11 +775,6 @@ static inline bool acpi_dev_present(const char *hid, const char *uid, s64 hrv)
772775

773776
struct acpi_device;
774777

775-
static inline bool acpi_dev_uid_match(struct acpi_device *adev, const char *uid2)
776-
{
777-
return false;
778-
}
779-
780778
static inline bool
781779
acpi_dev_hid_uid_match(struct acpi_device *adev, const char *hid2, const char *uid2)
782780
{

0 commit comments

Comments
 (0)