diff mbox series

[v1,8/8] efi/dev-path-parser: Refactor _UID handling to use acpi_dev_uid_to_integer()

Message ID 20220907164606.65742-9-andriy.shevchenko@linux.intel.com
State New
Headers show
Series ACPI: unify _UID handling as integer | expand

Commit Message

Andy Shevchenko Sept. 7, 2022, 4:46 p.m. UTC
ACPI utils provide acpi_dev_uid_to_integer() helper to extract _UID as
an integer. Use it instead of custom approach.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/firmware/efi/dev-path-parser.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

Comments

Ard Biesheuvel Sept. 8, 2022, 8:20 a.m. UTC | #1
On Wed, 7 Sept 2022 at 18:57, Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> ACPI utils provide acpi_dev_uid_to_integer() helper to extract _UID as
> an integer. Use it instead of custom approach.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/firmware/efi/dev-path-parser.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/firmware/efi/dev-path-parser.c b/drivers/firmware/efi/dev-path-parser.c
> index eb9c65f97841..113b3ca1bd76 100644
> --- a/drivers/firmware/efi/dev-path-parser.c
> +++ b/drivers/firmware/efi/dev-path-parser.c
> @@ -15,9 +15,11 @@
>  static long __init parse_acpi_path(const struct efi_dev_path *node,
>                                    struct device *parent, struct device **child)
>  {
> -       char hid[ACPI_ID_LEN], uid[11]; /* UINT_MAX + null byte */
>         struct acpi_device *adev;
>         struct device *phys_dev;
> +       char hid[ACPI_ID_LEN];
> +       long ret;
> +       u64 uid;
>
>         if (node->header.length != 12)
>                 return -EINVAL;
> @@ -27,12 +29,12 @@ static long __init parse_acpi_path(const struct efi_dev_path *node,
>                 'A' + ((node->acpi.hid >>  5) & 0x1f) - 1,
>                 'A' + ((node->acpi.hid >>  0) & 0x1f) - 1,
>                         node->acpi.hid >> 16);
> -       sprintf(uid, "%u", node->acpi.uid);
>
>         for_each_acpi_dev_match(adev, hid, NULL, -1) {
> -               if (adev->pnp.unique_id && !strcmp(adev->pnp.unique_id, uid))
> +               ret = acpi_dev_uid_to_integer(adev, &uid);
> +               if (ret == -ENODATA && node->acpi.uid == 0)
>                         break;
> -               if (!adev->pnp.unique_id && node->acpi.uid == 0)
> +               if (ret == 0 && node->acpi.uid == uid)

Is it necessary to reorder the conditions here? I.e., why not

> +               ret = acpi_dev_uid_to_integer(adev, &uid);
> +               if (ret == 0 && node->acpi.uid == uid)
>                         break;
> +               if (ret == -ENODATA && node->acpi.uid == 0)
>                         break;

?

With that fixed,

Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
Hans de Goede Sept. 8, 2022, 9:29 a.m. UTC | #2
Hi,

On 9/7/22 18:46, Andy Shevchenko wrote:
> ACPI utils provide acpi_dev_uid_to_integer() helper to extract _UID as
> an integer. Use it instead of custom approach.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/firmware/efi/dev-path-parser.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/firmware/efi/dev-path-parser.c b/drivers/firmware/efi/dev-path-parser.c
> index eb9c65f97841..113b3ca1bd76 100644
> --- a/drivers/firmware/efi/dev-path-parser.c
> +++ b/drivers/firmware/efi/dev-path-parser.c
> @@ -15,9 +15,11 @@
>  static long __init parse_acpi_path(const struct efi_dev_path *node,
>  				   struct device *parent, struct device **child)
>  {
> -	char hid[ACPI_ID_LEN], uid[11]; /* UINT_MAX + null byte */
>  	struct acpi_device *adev;
>  	struct device *phys_dev;
> +	char hid[ACPI_ID_LEN];
> +	long ret;

"long ret" should be "int ret" here since that is what acpi_dev_uid_to_integer()
returns.

Regards,

Hans


> +	u64 uid;
>  
>  	if (node->header.length != 12)
>  		return -EINVAL;
> @@ -27,12 +29,12 @@ static long __init parse_acpi_path(const struct efi_dev_path *node,
>  		'A' + ((node->acpi.hid >>  5) & 0x1f) - 1,
>  		'A' + ((node->acpi.hid >>  0) & 0x1f) - 1,
>  			node->acpi.hid >> 16);
> -	sprintf(uid, "%u", node->acpi.uid);
>  
>  	for_each_acpi_dev_match(adev, hid, NULL, -1) {
> -		if (adev->pnp.unique_id && !strcmp(adev->pnp.unique_id, uid))
> +		ret = acpi_dev_uid_to_integer(adev, &uid);
> +		if (ret == -ENODATA && node->acpi.uid == 0)
>  			break;
> -		if (!adev->pnp.unique_id && node->acpi.uid == 0)
> +		if (ret == 0 && node->acpi.uid == uid)
>  			break;
>  	}
>  	if (!adev)
Andy Shevchenko Sept. 8, 2022, 10:04 a.m. UTC | #3
On Thu, Sep 08, 2022 at 11:29:22AM +0200, Hans de Goede wrote:
> On 9/7/22 18:46, Andy Shevchenko wrote:

...

> > +	long ret;
> 
> "long ret" should be "int ret" here since that is what acpi_dev_uid_to_integer()
> returns.

I put it long since the efi_get_device_by_path() uses long ret (for the sake of
consistency with the existing code), but I have no objections to move it to
int.
Andy Shevchenko Sept. 8, 2022, 10:06 a.m. UTC | #4
On Thu, Sep 08, 2022 at 10:20:47AM +0200, Ard Biesheuvel wrote:
> On Wed, 7 Sept 2022 at 18:57, Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:

...

> >         for_each_acpi_dev_match(adev, hid, NULL, -1) {
> > -               if (adev->pnp.unique_id && !strcmp(adev->pnp.unique_id, uid))
> > +               ret = acpi_dev_uid_to_integer(adev, &uid);
> > +               if (ret == -ENODATA && node->acpi.uid == 0)
> >                         break;
> > -               if (!adev->pnp.unique_id && node->acpi.uid == 0)
> > +               if (ret == 0 && node->acpi.uid == uid)
> 
> Is it necessary to reorder the conditions here? I.e., why not

Code-wise there should be not much difference which does not affect the flow,
I think I moved it to be closer to the pattern "let's handle errors first",
but in this case I'm fine with your proposal.

> > +               ret = acpi_dev_uid_to_integer(adev, &uid);
> > +               if (ret == 0 && node->acpi.uid == uid)
> >                         break;
> > +               if (ret == -ENODATA && node->acpi.uid == 0)
> >                         break;
> 
> ?
> 
> With that fixed,
> 
> Reviewed-by: Ard Biesheuvel <ardb@kernel.org>

Thanks!
diff mbox series

Patch

diff --git a/drivers/firmware/efi/dev-path-parser.c b/drivers/firmware/efi/dev-path-parser.c
index eb9c65f97841..113b3ca1bd76 100644
--- a/drivers/firmware/efi/dev-path-parser.c
+++ b/drivers/firmware/efi/dev-path-parser.c
@@ -15,9 +15,11 @@ 
 static long __init parse_acpi_path(const struct efi_dev_path *node,
 				   struct device *parent, struct device **child)
 {
-	char hid[ACPI_ID_LEN], uid[11]; /* UINT_MAX + null byte */
 	struct acpi_device *adev;
 	struct device *phys_dev;
+	char hid[ACPI_ID_LEN];
+	long ret;
+	u64 uid;
 
 	if (node->header.length != 12)
 		return -EINVAL;
@@ -27,12 +29,12 @@  static long __init parse_acpi_path(const struct efi_dev_path *node,
 		'A' + ((node->acpi.hid >>  5) & 0x1f) - 1,
 		'A' + ((node->acpi.hid >>  0) & 0x1f) - 1,
 			node->acpi.hid >> 16);
-	sprintf(uid, "%u", node->acpi.uid);
 
 	for_each_acpi_dev_match(adev, hid, NULL, -1) {
-		if (adev->pnp.unique_id && !strcmp(adev->pnp.unique_id, uid))
+		ret = acpi_dev_uid_to_integer(adev, &uid);
+		if (ret == -ENODATA && node->acpi.uid == 0)
 			break;
-		if (!adev->pnp.unique_id && node->acpi.uid == 0)
+		if (ret == 0 && node->acpi.uid == uid)
 			break;
 	}
 	if (!adev)