linux-efi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] efi/dev-path-parser: Switch to acpi_dev_get_first_match_dev()
@ 2020-05-29 13:08 Andy Shevchenko
  2020-06-18 11:58 ` Andy Shevchenko
  0 siblings, 1 reply; 2+ messages in thread
From: Andy Shevchenko @ 2020-05-29 13:08 UTC (permalink / raw)
  To: Ard Biesheuvel, linux-efi; +Cc: Andy Shevchenko, Lukas Wunner

The acpi_dev_get_first_match_dev() helper will find and return
an ACPI device pointer of the first registered device in the system
by its HID and UID (if present). Use it instead of open coded variant.

Cc: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
v2: added Lukas to Cc (Ard), updated condition to handle UID=0 case
 drivers/firmware/efi/dev-path-parser.c | 43 +++++++++-----------------
 1 file changed, 14 insertions(+), 29 deletions(-)

diff --git a/drivers/firmware/efi/dev-path-parser.c b/drivers/firmware/efi/dev-path-parser.c
index 5c9625e552f4..d3e5123ab618 100644
--- a/drivers/firmware/efi/dev-path-parser.c
+++ b/drivers/firmware/efi/dev-path-parser.c
@@ -12,51 +12,36 @@
 #include <linux/efi.h>
 #include <linux/pci.h>
 
-struct acpi_hid_uid {
-	struct acpi_device_id hid[2];
-	char uid[11]; /* UINT_MAX + null byte */
-};
-
-static int __init match_acpi_dev(struct device *dev, const void *data)
-{
-	struct acpi_hid_uid hid_uid = *(const struct acpi_hid_uid *)data;
-	struct acpi_device *adev = to_acpi_device(dev);
-
-	if (acpi_match_device_ids(adev, hid_uid.hid))
-		return 0;
-
-	if (adev->pnp.unique_id)
-		return !strcmp(adev->pnp.unique_id, hid_uid.uid);
-	else
-		return !strcmp("0", hid_uid.uid);
-}
-
 static long __init parse_acpi_path(const struct efi_dev_path *node,
 				   struct device *parent, struct device **child)
 {
-	struct acpi_hid_uid hid_uid = {};
+	char hid[3 + 4 + 1];	/* 3 characters + 4 hex digits + null byte */
+	char uid[10 + 1];	/* UINT_MAX + null byte */
+	struct acpi_device *adev;
 	struct device *phys_dev;
 
 	if (node->header.length != 12)
 		return -EINVAL;
 
-	sprintf(hid_uid.hid[0].id, "%c%c%c%04X",
+	sprintf(hid, "%c%c%c%04X",
 		'A' + ((node->acpi.hid >> 10) & 0x1f) - 1,
 		'A' + ((node->acpi.hid >>  5) & 0x1f) - 1,
 		'A' + ((node->acpi.hid >>  0) & 0x1f) - 1,
 			node->acpi.hid >> 16);
-	sprintf(hid_uid.uid, "%u", node->acpi.uid);
+	sprintf(uid, "%u", node->acpi.uid);
 
-	*child = bus_find_device(&acpi_bus_type, NULL, &hid_uid,
-				 match_acpi_dev);
-	if (!*child)
+	adev = acpi_dev_get_first_match_dev(hid, uid, -1);
+	if (!adev && !node->acpi.uid)
+		adev = acpi_dev_get_first_match_dev(hid, NULL, -1);
+	if (!adev)
 		return -ENODEV;
 
-	phys_dev = acpi_get_first_physical_node(to_acpi_device(*child));
+	phys_dev = acpi_get_first_physical_node(adev);
 	if (phys_dev) {
-		get_device(phys_dev);
-		put_device(*child);
-		*child = phys_dev;
+		*child = get_device(phys_dev);
+		acpi_dev_put(adev);
+	} else {
+		*child = &adev->dev;
 	}
 
 	return 0;
-- 
2.26.2


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

* Re: [PATCH v2] efi/dev-path-parser: Switch to acpi_dev_get_first_match_dev()
  2020-05-29 13:08 [PATCH v2] efi/dev-path-parser: Switch to acpi_dev_get_first_match_dev() Andy Shevchenko
@ 2020-06-18 11:58 ` Andy Shevchenko
  0 siblings, 0 replies; 2+ messages in thread
From: Andy Shevchenko @ 2020-06-18 11:58 UTC (permalink / raw)
  To: Ard Biesheuvel, linux-efi; +Cc: Lukas Wunner

On Fri, May 29, 2020 at 04:08:22PM +0300, Andy Shevchenko wrote:
> The acpi_dev_get_first_match_dev() helper will find and return
> an ACPI device pointer of the first registered device in the system
> by its HID and UID (if present). Use it instead of open coded variant.

Lukas, any comment on this?

> Cc: Lukas Wunner <lukas@wunner.de>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
> v2: added Lukas to Cc (Ard), updated condition to handle UID=0 case
>  drivers/firmware/efi/dev-path-parser.c | 43 +++++++++-----------------
>  1 file changed, 14 insertions(+), 29 deletions(-)
> 
> diff --git a/drivers/firmware/efi/dev-path-parser.c b/drivers/firmware/efi/dev-path-parser.c
> index 5c9625e552f4..d3e5123ab618 100644
> --- a/drivers/firmware/efi/dev-path-parser.c
> +++ b/drivers/firmware/efi/dev-path-parser.c
> @@ -12,51 +12,36 @@
>  #include <linux/efi.h>
>  #include <linux/pci.h>
>  
> -struct acpi_hid_uid {
> -	struct acpi_device_id hid[2];
> -	char uid[11]; /* UINT_MAX + null byte */
> -};
> -
> -static int __init match_acpi_dev(struct device *dev, const void *data)
> -{
> -	struct acpi_hid_uid hid_uid = *(const struct acpi_hid_uid *)data;
> -	struct acpi_device *adev = to_acpi_device(dev);
> -
> -	if (acpi_match_device_ids(adev, hid_uid.hid))
> -		return 0;
> -
> -	if (adev->pnp.unique_id)
> -		return !strcmp(adev->pnp.unique_id, hid_uid.uid);
> -	else
> -		return !strcmp("0", hid_uid.uid);
> -}
> -
>  static long __init parse_acpi_path(const struct efi_dev_path *node,
>  				   struct device *parent, struct device **child)
>  {
> -	struct acpi_hid_uid hid_uid = {};
> +	char hid[3 + 4 + 1];	/* 3 characters + 4 hex digits + null byte */
> +	char uid[10 + 1];	/* UINT_MAX + null byte */
> +	struct acpi_device *adev;
>  	struct device *phys_dev;
>  
>  	if (node->header.length != 12)
>  		return -EINVAL;
>  
> -	sprintf(hid_uid.hid[0].id, "%c%c%c%04X",
> +	sprintf(hid, "%c%c%c%04X",
>  		'A' + ((node->acpi.hid >> 10) & 0x1f) - 1,
>  		'A' + ((node->acpi.hid >>  5) & 0x1f) - 1,
>  		'A' + ((node->acpi.hid >>  0) & 0x1f) - 1,
>  			node->acpi.hid >> 16);
> -	sprintf(hid_uid.uid, "%u", node->acpi.uid);
> +	sprintf(uid, "%u", node->acpi.uid);
>  
> -	*child = bus_find_device(&acpi_bus_type, NULL, &hid_uid,
> -				 match_acpi_dev);
> -	if (!*child)
> +	adev = acpi_dev_get_first_match_dev(hid, uid, -1);
> +	if (!adev && !node->acpi.uid)
> +		adev = acpi_dev_get_first_match_dev(hid, NULL, -1);
> +	if (!adev)
>  		return -ENODEV;
>  
> -	phys_dev = acpi_get_first_physical_node(to_acpi_device(*child));
> +	phys_dev = acpi_get_first_physical_node(adev);
>  	if (phys_dev) {
> -		get_device(phys_dev);
> -		put_device(*child);
> -		*child = phys_dev;
> +		*child = get_device(phys_dev);
> +		acpi_dev_put(adev);
> +	} else {
> +		*child = &adev->dev;
>  	}
>  
>  	return 0;
> -- 
> 2.26.2
> 

-- 
With Best Regards,
Andy Shevchenko



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

end of thread, other threads:[~2020-06-18 11:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-29 13:08 [PATCH v2] efi/dev-path-parser: Switch to acpi_dev_get_first_match_dev() Andy Shevchenko
2020-06-18 11:58 ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).