Linux-ACPI Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v1 1/1] ACPI: scan: Utilize match_string() API
@ 2021-04-10 14:02 Andy Shevchenko
  2021-04-12 17:35 ` Rafael J. Wysocki
  0 siblings, 1 reply; 2+ messages in thread
From: Andy Shevchenko @ 2021-04-10 14:02 UTC (permalink / raw)
  To: Rafael J. Wysocki, linux-acpi, linux-kernel
  Cc: Rafael J. Wysocki, Len Brown, Andy Shevchenko

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

Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com>
---
 drivers/acpi/scan.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index b1d1f1a8ce69..bba6b529cf6c 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -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;
-- 
2.31.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v1 1/1] ACPI: scan: Utilize match_string() API
  2021-04-10 14:02 [PATCH v1 1/1] ACPI: scan: Utilize match_string() API Andy Shevchenko
@ 2021-04-12 17:35 ` Rafael J. Wysocki
  0 siblings, 0 replies; 2+ messages in thread
From: Rafael J. Wysocki @ 2021-04-12 17:35 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Rafael J. Wysocki, ACPI Devel Maling List,
	Linux Kernel Mailing List, Rafael J. Wysocki, Len Brown

On Sat, Apr 10, 2021 at 4:02 PM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
>
> We have already an API to match a string in the array of strings.
> Utilize it instead of open coded analogues.
>
> Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com>
> ---
>  drivers/acpi/scan.c | 22 ++++++++++------------
>  1 file changed, 10 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
> index b1d1f1a8ce69..bba6b529cf6c 100644
> --- a/drivers/acpi/scan.c
> +++ b/drivers/acpi/scan.c
> @@ -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;
> --

Applied as 5.13 material, thanks!

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-10 14:02 [PATCH v1 1/1] ACPI: scan: Utilize match_string() API Andy Shevchenko
2021-04-12 17:35 ` Rafael J. Wysocki

Linux-ACPI Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-acpi/0 linux-acpi/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-acpi linux-acpi/ https://lore.kernel.org/linux-acpi \
		linux-acpi@vger.kernel.org
	public-inbox-index linux-acpi

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-acpi


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git