Skip to contentSkip to conversation

gpio / ACPI: Two minor cleanups related to ACPI_HANDLE()

PATCH In review Rafael J. Wysocki 5 participants 11 messages Mar 10, 2015 – Mar 18, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover gpio / ACPI: Two minor cleanups related to ACPI_HANDLE()

Hi,

As per the subject, avoid evaluating ACPI_HANDLE() if we can as that one is rather costly.

Kind regards,
Rafael

#1 lore raw

PATCH 1/2 gpio / ACPI: Avoid unnecessary checks in __gpiod_get_index()

From: Rafael J. Wysocki <[email protected]>

If dev is NULL in __gpiod_get_index() and both ACPI and OF are enabled, it will be checked twice before the code decides to give up with DT/ACPI lookup, so avoid that.

Also use the observation that ACPI_COMPANION() is much more efficient than ACPI_HANDLE(), because the latter uses the former and carries out a check and a pointer dereference on top of it, so replace the ACPI_HANDLE() check with an ACPI_COMPANION() one which does not require the additional IS_ENABLED(CONFIG_ACPI) check too.

---
 drivers/gpio/gpiolib.c |   16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/gpio/gpiolib.c +9 -7
Index: linux-pm/drivers/gpio/gpiolib.c
===================================================================
@@ -1865,13 +1865,15 @@ struct gpio_desc *__must_check __gpiod_g
 
 	dev_dbg(dev, "GPIO lookup for consumer %s\n", con_id);
 
-	/* Using device tree? */
-	if (IS_ENABLED(CONFIG_OF) && dev && dev->of_node) {
-		dev_dbg(dev, "using device tree for GPIO lookup\n");
-		desc = of_find_gpio(dev, con_id, idx, &lookupflags);
-	} else if (IS_ENABLED(CONFIG_ACPI) && dev && ACPI_HANDLE(dev)) {
-		dev_dbg(dev, "using ACPI for GPIO lookup\n");
-		desc = acpi_find_gpio(dev, con_id, idx, &lookupflags);
+	if (dev) {
+		/* Using device tree? */
+		if (IS_ENABLED(CONFIG_OF) && dev->of_node) {
+			dev_dbg(dev, "using device tree for GPIO lookup\n");
+			desc = of_find_gpio(dev, con_id, idx, &lookupflags);
+		} else if (ACPI_COMPANION(dev)) {
+			dev_dbg(dev, "using ACPI for GPIO lookup\n");
+			desc = acpi_find_gpio(dev, con_id, idx, &lookupflags);
+		}
 	}
 
 	/*
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] gpio / ACPI: Avoid unnecessary checks in __gpiod_get_index()

Quoted 6 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

If dev is NULL in __gpiod_get_index() and both ACPI and OF are enabled, it will be checked twice before the code decides to give up with DT/ACPI lookup, so avoid that.

Quoted 7 lines

Also use the observation that ACPI_COMPANION() is much more efficient than ACPI_HANDLE(), because the latter uses the former and carries out a check and a pointer dereference on top of it, so replace the ACPI_HANDLE() check with an ACPI_COMPANION() one which does not require the additional IS_ENABLED(CONFIG_ACPI) check too.

Quite straight forward to me, for both two patches,

Thanks
Hanjun

Quoted 39 lines
---
 drivers/gpio/gpiolib.c |   16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

Index: linux-pm/drivers/gpio/gpiolib.c
===================================================================

drivers/gpio/gpiolib.c +9 -8
@@ -1865,13 +1865,15 @@ struct gpio_desc *__must_check __gpiod_g
 
 	dev_dbg(dev, "GPIO lookup for consumer %s\n", con_id);
 
-	/* Using device tree? */
-	if (IS_ENABLED(CONFIG_OF) && dev && dev->of_node) {
-		dev_dbg(dev, "using device tree for GPIO lookup\n");
-		desc = of_find_gpio(dev, con_id, idx, &lookupflags);
-	} else if (IS_ENABLED(CONFIG_ACPI) && dev && ACPI_HANDLE(dev)) {
-		dev_dbg(dev, "using ACPI for GPIO lookup\n");
-		desc = acpi_find_gpio(dev, con_id, idx, &lookupflags);
+	if (dev) {
+		/* Using device tree? */
+		if (IS_ENABLED(CONFIG_OF) && dev->of_node) {
+			dev_dbg(dev, "using device tree for GPIO lookup\n");
+			desc = of_find_gpio(dev, con_id, idx, &lookupflags);
+		} else if (ACPI_COMPANION(dev)) {
+			dev_dbg(dev, "using ACPI for GPIO lookup\n");
+			desc = acpi_find_gpio(dev, con_id, idx, &lookupflags);
+		}
 	}
 
 	/*
 
--

To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

.

Acked-by on v1 1/2
#3 lore raw

Re: [PATCH 1/2] gpio / ACPI: Avoid unnecessary checks in __gpiod_get_index()

In reply to Rafael J. Wysocki
Quoted 6 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

If dev is NULL in __gpiod_get_index() and both ACPI and OF are enabled, it will be checked twice before the code decides to give up with DT/ACPI lookup, so avoid that.

Quoted 7 lines

Also use the observation that ACPI_COMPANION() is much more efficient than ACPI_HANDLE(), because the latter uses the former and carries out a check and a pointer dereference on top of it, so replace the ACPI_HANDLE() check with an ACPI_COMPANION() one which does not require the additional IS_ENABLED(CONFIG_ACPI) check too.

#4 lore raw

Re: [PATCH 1/2] gpio / ACPI: Avoid unnecessary checks in __gpiod_get_index()

In reply to Rafael J. Wysocki
Quoted 6 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

If dev is NULL in __gpiod_get_index() and both ACPI and OF are enabled, it will be checked twice before the code decides to give up with DT/ACPI lookup, so avoid that.

Quoted 7 lines

Also use the observation that ACPI_COMPANION() is much more efficient than ACPI_HANDLE(), because the latter uses the former and carries out a check and a pointer dereference on top of it, so replace the ACPI_HANDLE() check with an ACPI_COMPANION() one which does not require the additional IS_ENABLED(CONFIG_ACPI) check too.

Patch applied with review and ACK tags.

Yours,
Linus Walleij

#5 lore raw

PATCH 2/2 gpio / ACPI: Use local variable instead of ACPI_HANDLE()

In reply to Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

In acpi_gpiochip_request_interrupts() the handle local variable already contains the value that we want to pass to acpi_walk_resources(), so it is better to use that variable instead of evaluating ACPI_HANDLE() once more for the same device.

---
 drivers/gpio/gpiolib-acpi.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpiolib-acpi.c +1 -1
Index: linux-pm/drivers/gpio/gpiolib-acpi.c
===================================================================
@@ -300,7 +300,7 @@ void acpi_gpiochip_request_interrupts(st
 		return;
 
 	INIT_LIST_HEAD(&acpi_gpio->events);
-	acpi_walk_resources(ACPI_HANDLE(chip->dev), "_AEI",
+	acpi_walk_resources(handle, "_AEI",
 			    acpi_gpiochip_request_interrupt, acpi_gpio);
 }
 
Acked-by on v1 2/2
#6 lore raw

Re: [PATCH 2/2] gpio / ACPI: Use local variable instead of ACPI_HANDLE()

Quoted 9 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

In acpi_gpiochip_request_interrupts() the handle local variable already contains the value that we want to pass to acpi_walk_resources(), so it is better to use that variable instead of evaluating ACPI_HANDLE() once more for the same device.

#7 lore raw

Re: [PATCH 2/2] gpio / ACPI: Use local variable instead of ACPI_HANDLE()

In reply to Rafael J. Wysocki
Quoted 9 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

In acpi_gpiochip_request_interrupts() the handle local variable already contains the value that we want to pass to acpi_walk_resources(), so it is better to use that variable instead of evaluating ACPI_HANDLE() once more for the same device.

Patch applied with Mika's ACK.

Yours,
Linus Walleij

#8 lore raw
In reply to Rafael J. Wysocki
Quoted 4 lines · Rafael J. Wysocki

Hi,

As per the subject, avoid evaluating ACPI_HANDLE() if we can as that one is rather costly.

Linus, Alexandre, any objections to this series?

If not, would there be any problem if I took these to my tree? I'll probably have material on top of them.

Rafael

#9 lore raw
Quoted 10 lines · Rafael J. Wysocki
Quoted 4 lines · Rafael J. Wysocki

Hi,

As per the subject, avoid evaluating ACPI_HANDLE() if we can as that one is rather costly.

Linus, Alexandre, any objections to this series?

If not, would there be any problem if I took these to my tree? I'll probably have material on top of them.

Sorry for the delay. Looks like Linus just took the patches in his tree, I hope that's ok?

#10 lore raw
Quoted 7 lines · Alexandre Courbot
Quoted 6 lines · Rafael J. Wysocki
Quoted 4 lines · Rafael J. Wysocki

Hi,

As per the subject, avoid evaluating ACPI_HANDLE() if we can as that one is rather costly.

Quoted 7 lines
Quoted 4 lines

Linus, Alexandre, any objections to this series?

If not, would there be any problem if I took these to my tree? I'll probably have material on top of them.

Sorry for the delay. Looks like Linus just took the patches in his tree, I hope that's ok?

Yes, that's fine, thanks!

Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.