Skip to contentSkip to conversation

gpiolib: acpi: Add ACPI device NULL check to acpi_can_fallback_to_crs()

PATCH In review Laura Nao 3 participants 4 messages May 9, 2024 – May 13, 2024

Subsystems (2)
lore
Share & tools
lore

Laura Nao

author
#0 lore raw

PATCH 1/1 gpiolib: acpi: Add ACPI device NULL check to acpi_can_fallback_to_crs()

Check ACPI device for NULL inside acpi_can_fallback_to_crs(), so callers won't need to.

Fixes 49c02f6e901c ("gpiolib: acpi: Move acpi_can_fallback_to_crs() out of __acpi_find_gpio()")
---
 drivers/gpio/gpiolib-acpi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpiolib-acpi.c +1 -1
index 553a5f94c00a..688aff6e51bc 100644
@@ -939,7 +939,7 @@ static bool acpi_can_fallback_to_crs(struct acpi_device *adev,
 				     const char *con_id)
 {
 	/* Never allow fallback if the device has properties */
-	if (acpi_dev_has_props(adev) || adev->driver_gpios)
+	if (!adev || acpi_dev_has_props(adev) || adev->driver_gpios)
 		return false;
 
 	return con_id == NULL;
Signature · 1 line
2.30.2
Reviewed-by on v1 1/1
#1 lore raw

Il 09/05/24 12:46, Laura Nao ha scritto:

Quoted 8 lines

Check ACPI device for NULL inside acpi_can_fallback_to_crs(), so callers won't need to.

Fixes 49c02f6e901c ("gpiolib: acpi: Move acpi_can_fallback_to_crs() out of __acpi_find_gpio()")
Reviewed-by on v1 1/1
#2 lore raw
In reply to Laura Nao
Quoted 2 lines · Laura Nao

Check ACPI device for NULL inside acpi_can_fallback_to_crs(), so callers won't need to.

Thank you for the patch, one change seems good to have along this.

...

Review

Quoted 3 lines
(quoted diff) +1 -1
 	/* Never allow fallback if the device has properties */
-	if (acpi_dev_has_props(adev) || adev->driver_gpios)
+	if (!adev || acpi_dev_has_props(adev) || adev->driver_gpios)

Right, since it was adev || _crs() combined.

Quoted 1 line

return false;

Now we may remove that check from __acpi_find_gpio():

drivers/gpio/gpiolib-acpi.c +3 -3
@@ -988,10 +988,10 @@ __acpi_find_gpio(struct fwnode_handle *fwnode, const char *con_id, unsigned int
 	}
 
 	/* Then from plain _CRS GPIOs */
-	if (!adev || !can_fallback)
-		return ERR_PTR(-ENOENT);
+	if (can_fallback)
+		return acpi_get_gpiod_by_index(adev, NULL, idx, info);
 
-	return acpi_get_gpiod_by_index(adev, NULL, idx, info);
+	return ERR_PTR(-ENOENT);
 }
 
 struct gpio_desc *acpi_find_gpio(struct fwnode_handle *fwnode,

As a side effect it will make the comment better to understand.

With above suggestion applied, feel free to add mine

You might need to rephrase the commit message to say that

"We also move the check in additional to the moving the function call outside of __acpi_find_gpio()."

or something similar, up to you.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author
#3 lore raw

Re: [PATCH] gpiolib: acpi: Add ACPI device NULL check to

Hi Andy,

Quoted 27 lines · Andy Shevchenko

Now we may remove that check from __acpi_find_gpio():

drivers/gpio/gpiolib-acpi.c +0 -0
@@ -988,10 +988,10 @@ __acpi_find_gpio(struct fwnode_handle *fwnode,

const char *con_id, unsigned int
}

/* Then from plain _CRS GPIOs */

drivers/gpio/gpiolib-acpi.c +3 -3
-	if (!adev || !can_fallback)
-		return ERR_PTR(-ENOENT);
+	if (can_fallback)
+		return acpi_get_gpiod_by_index(adev, NULL, idx, info);
 
-	return acpi_get_gpiod_by_index(adev, NULL, idx, info);
+	return ERR_PTR(-ENOENT);
  }
 
  struct gpio_desc *acpi_find_gpio(struct fwnode_handle *fwnode,

As a side effect it will make the comment better to understand.

With above suggestion applied, feel free to add mine

Quoted 8 lines

You might need to rephrase the commit message to say that

"We also move the check in additional to the moving the function call
outside of __acpi_find_gpio()."

or something similar, up to you.

Thanks for the feedback, I sent another patch with the suggestions above applied:
https://lore.kernel.org/all/[email protected]/T/#u

Best regards,

Laura Nao