@@ -764,10 +764,71 @@ 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 );
768- bool acpi_dev_hid_uid_match (struct acpi_device * adev , const char * hid2 , const char * uid2 );
769767int acpi_dev_uid_to_integer (struct acpi_device * adev , u64 * integer );
770768
769+ static inline bool acpi_dev_hid_match (struct acpi_device * adev , const char * hid2 )
770+ {
771+ const char * hid1 = acpi_device_hid (adev );
772+
773+ return hid1 && hid2 && !strcmp (hid1 , hid2 );
774+ }
775+
776+ static inline bool acpi_str_uid_match (struct acpi_device * adev , const char * uid2 )
777+ {
778+ const char * uid1 = acpi_device_uid (adev );
779+
780+ return uid1 && uid2 && !strcmp (uid1 , uid2 );
781+ }
782+
783+ static inline bool acpi_int_uid_match (struct acpi_device * adev , u64 uid2 )
784+ {
785+ u64 uid1 ;
786+
787+ return !acpi_dev_uid_to_integer (adev , & uid1 ) && uid1 == uid2 ;
788+ }
789+
790+ #define TYPE_ENTRY (type , x ) \
791+ const type: x, \
792+ type: x
793+
794+ #define ACPI_STR_TYPES (match ) \
795+ TYPE_ENTRY(unsigned char *, match), \
796+ TYPE_ENTRY(signed char *, match), \
797+ TYPE_ENTRY(char *, match), \
798+ TYPE_ENTRY(void *, match)
799+
800+ /**
801+ * acpi_dev_uid_match - Match device by supplied UID
802+ * @adev: ACPI device to match.
803+ * @uid2: Unique ID of the device.
804+ *
805+ * Matches UID in @adev with given @uid2.
806+ *
807+ * Returns: %true if matches, %false otherwise.
808+ */
809+ #define acpi_dev_uid_match (adev , uid2 ) \
810+ _Generic(uid2, \
811+ /* Treat @uid2 as a string for acpi string types */ \
812+ ACPI_STR_TYPES (acpi_str_uid_match ), \
813+ /* Treat as an integer otherwise */ \
814+ default : acpi_int_uid_match )(adev , uid2 )
815+
816+ /**
817+ * acpi_dev_hid_uid_match - Match device by supplied HID and UID
818+ * @adev: ACPI device to match.
819+ * @hid2: Hardware ID of the device.
820+ * @uid2: Unique ID of the device, pass 0 or NULL to not check _UID.
821+ *
822+ * Matches HID and UID in @adev with given @hid2 and @uid2. Absence of @uid2
823+ * will be treated as a match. If user wants to validate @uid2, it should be
824+ * done before calling this function.
825+ *
826+ * Returns: %true if matches or @uid2 is 0 or NULL, %false otherwise.
827+ */
828+ #define acpi_dev_hid_uid_match (adev , hid2 , uid2 ) \
829+ (acpi_dev_hid_match(adev, hid2) && \
830+ (!(uid2) || acpi_dev_uid_match(adev, uid2)))
831+
771832void acpi_dev_clear_dependencies (struct acpi_device * supplier );
772833bool acpi_dev_ready_for_enumeration (const struct acpi_device * device );
773834struct acpi_device * acpi_dev_get_next_consumer_dev (struct acpi_device * supplier ,
0 commit comments