Skip to contentSkip to conversation

ACPI: scan: Utilize match_string() API

PATCH Applied Andy Shevchenko 2 participants 2 messages Apr 10, 2021 – Apr 12, 2021 ACPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ACPI: scan: Utilize match_string() API

We have already an API to match a string in the array of strings. Utilize it instead of open coded analogues.

---
 drivers/acpi/scan.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)
drivers/acpi/scan.c +10 -12
index b1d1f1a8ce69..bba6b529cf6c 100644
@@ -756,27 +756,25 @@ static bool acpi_info_matches_ids(struct acpi_device_info *info,
 				  const char * const ids[])
 {
 	struct acpi_pnp_device_id_list *cid_list = NULL;
-	int i;
+	int i, index;
 
 	if (!(info->valid & ACPI_VALID_HID))
 		return false;
 
+	index = match_string(ids, -1, info->hardware_id.string);
+	if (index >= 0)
+		return true;
+
 	if (info->valid & ACPI_VALID_CID)
 		cid_list = &info->compatible_id_list;
 
-	for (i = 0; ids[i]; i++) {
-		int j;
+	if (!cid_list)
+		return false;
 
-		if (!strcmp(info->hardware_id.string, ids[i]))
+	for (i = 0; i < cid_list->count; i++) {
+		index = match_string(ids, -1, cid_list->ids[i].string);
+		if (index >= 0)
 			return true;
-
-		if (!cid_list)
-			continue;
-
-		for (j = 0; j < cid_list->count; j++) {
-			if (!strcmp(cid_list->ids[j].string, ids[i]))
-				return true;
-		}
 	}
 
 	return false;
Signature · 1 line
2.31.1
maintainer Applied
#1 lore raw
Quoted 42 lines · Andy Shevchenko

We have already an API to match a string in the array of strings. Utilize it instead of open coded analogues.

---
 drivers/acpi/scan.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)
drivers/acpi/scan.c +10 -6
index b1d1f1a8ce69..bba6b529cf6c 100644
@@ -756,27 +756,25 @@ static bool acpi_info_matches_ids(struct acpi_device_info *info,
                                  const char * const ids[])
 {
        struct acpi_pnp_device_id_list *cid_list = NULL;
-       int i;
+       int i, index;
 
        if (!(info->valid & ACPI_VALID_HID))
                return false;
 
+       index = match_string(ids, -1, info->hardware_id.string);
+       if (index >= 0)
+               return true;
+
        if (info->valid & ACPI_VALID_CID)
                cid_list = &info->compatible_id_list;
 
-       for (i = 0; ids[i]; i++) {
-               int j;
+       if (!cid_list)
+               return false;
 
-               if (!strcmp(info->hardware_id.string, ids[i]))
+       for (i = 0; i < cid_list->count; i++) {
+               index = match_string(ids, -1, cid_list->ids[i].string);
+               if (index >= 0)
                        return true;
-
-               if (!cid_list)

drivers/acpi/scan.c static bool acpi_info_matches_ids(struct acpi_device_info *info,

Quoted 10 lines
drivers/acpi/scan.c +0 -7
-                       continue;
-
-               for (j = 0; j < cid_list->count; j++) {
-                       if (!strcmp(cid_list->ids[j].string, ids[i]))
-                               return true;
-               }
        }
 
        return false;
--

Applied as 5.13 material, thanks!