linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gpio: of: Optimize quirk checks
@ 2019-03-29  8:42 Geert Uytterhoeven
  2019-03-29 10:02 ` Mukesh Ojha
  2019-04-08 11:04 ` Linus Walleij
  0 siblings, 2 replies; 3+ messages in thread
From: Geert Uytterhoeven @ 2019-03-29  8:42 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski
  Cc: linux-gpio, linux-kernel, Geert Uytterhoeven

Simple string comparisons are cheaper than DT lookups, as the latter
involve taking a spinlock and traversing properties.
Hence optimize quirk checks by postponing DT lookups after string
comparisons.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
 drivers/gpio/gpiolib-of.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index 6a3ec575a404ed9f..3a6bb53d89dfed32 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -86,9 +86,9 @@ static void of_gpio_flags_quirks(struct device_node *np,
 	if (IS_ENABLED(CONFIG_REGULATOR) &&
 	    (of_device_is_compatible(np, "regulator-fixed") ||
 	     of_device_is_compatible(np, "reg-fixed-voltage") ||
-	     (of_device_is_compatible(np, "regulator-gpio") &&
-	      !(strcmp(propname, "enable-gpio") &&
-	        strcmp(propname, "enable-gpios"))))) {
+	     (!(strcmp(propname, "enable-gpio") &&
+		strcmp(propname, "enable-gpios")) &&
+	      of_device_is_compatible(np, "regulator-gpio")))) {
 		/*
 		 * The regulator GPIO handles are specified such that the
 		 * presence or absence of "enable-active-high" solely controls
@@ -119,9 +119,8 @@ static void of_gpio_flags_quirks(struct device_node *np,
 	 * property named "cs-gpios" we need to inspect the child node
 	 * to determine if the flags should have inverted semantics.
 	 */
-	if (IS_ENABLED(CONFIG_SPI_MASTER) &&
-	    of_property_read_bool(np, "cs-gpios") &&
-	    !strcmp(propname, "cs-gpios")) {
+	if (IS_ENABLED(CONFIG_SPI_MASTER) && !strcmp(propname, "cs-gpios") &&
+	    of_property_read_bool(np, "cs-gpios")) {
 		struct device_node *child;
 		u32 cs;
 		int ret;
-- 
2.17.1

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

* Re: [PATCH] gpio: of: Optimize quirk checks
  2019-03-29  8:42 [PATCH] gpio: of: Optimize quirk checks Geert Uytterhoeven
@ 2019-03-29 10:02 ` Mukesh Ojha
  2019-04-08 11:04 ` Linus Walleij
  1 sibling, 0 replies; 3+ messages in thread
From: Mukesh Ojha @ 2019-03-29 10:02 UTC (permalink / raw)
  To: Geert Uytterhoeven, Linus Walleij, Bartosz Golaszewski
  Cc: linux-gpio, linux-kernel


On 3/29/2019 2:12 PM, Geert Uytterhoeven wrote:
> Simple string comparisons are cheaper than DT lookups, as the latter
> involve taking a spinlock and traversing properties.
> Hence optimize quirk checks by postponing DT lookups after string
> comparisons.
>
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>


Looks good to me.

Reviewed-by: Mukesh Ojha <mojha@codeaurora.org>

Cheers,
-Mukesh

> ---
>   drivers/gpio/gpiolib-of.c | 11 +++++------
>   1 file changed, 5 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
> index 6a3ec575a404ed9f..3a6bb53d89dfed32 100644
> --- a/drivers/gpio/gpiolib-of.c
> +++ b/drivers/gpio/gpiolib-of.c
> @@ -86,9 +86,9 @@ static void of_gpio_flags_quirks(struct device_node *np,
>   	if (IS_ENABLED(CONFIG_REGULATOR) &&
>   	    (of_device_is_compatible(np, "regulator-fixed") ||
>   	     of_device_is_compatible(np, "reg-fixed-voltage") ||
> -	     (of_device_is_compatible(np, "regulator-gpio") &&
> -	      !(strcmp(propname, "enable-gpio") &&
> -	        strcmp(propname, "enable-gpios"))))) {
> +	     (!(strcmp(propname, "enable-gpio") &&
> +		strcmp(propname, "enable-gpios")) &&
> +	      of_device_is_compatible(np, "regulator-gpio")))) {
>   		/*
>   		 * The regulator GPIO handles are specified such that the
>   		 * presence or absence of "enable-active-high" solely controls
> @@ -119,9 +119,8 @@ static void of_gpio_flags_quirks(struct device_node *np,
>   	 * property named "cs-gpios" we need to inspect the child node
>   	 * to determine if the flags should have inverted semantics.
>   	 */
> -	if (IS_ENABLED(CONFIG_SPI_MASTER) &&
> -	    of_property_read_bool(np, "cs-gpios") &&
> -	    !strcmp(propname, "cs-gpios")) {
> +	if (IS_ENABLED(CONFIG_SPI_MASTER) && !strcmp(propname, "cs-gpios") &&
> +	    of_property_read_bool(np, "cs-gpios")) {
>   		struct device_node *child;
>   		u32 cs;
>   		int ret;

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

* Re: [PATCH] gpio: of: Optimize quirk checks
  2019-03-29  8:42 [PATCH] gpio: of: Optimize quirk checks Geert Uytterhoeven
  2019-03-29 10:02 ` Mukesh Ojha
@ 2019-04-08 11:04 ` Linus Walleij
  1 sibling, 0 replies; 3+ messages in thread
From: Linus Walleij @ 2019-04-08 11:04 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Bartosz Golaszewski, open list:GPIO SUBSYSTEM,
	linux-kernel@vger.kernel.org

On Fri, Mar 29, 2019 at 9:42 AM Geert Uytterhoeven
<geert+renesas@glider.be> wrote:

> Simple string comparisons are cheaper than DT lookups, as the latter
> involve taking a spinlock and traversing properties.
> Hence optimize quirk checks by postponing DT lookups after string
> comparisons.
>
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>

Thanks Geert! I merged v5.1-rc3 into my devel branch and
applied this on top.

Yours,
Linus Walleij

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

end of thread, other threads:[~2019-04-08 11:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-03-29  8:42 [PATCH] gpio: of: Optimize quirk checks Geert Uytterhoeven
2019-03-29 10:02 ` Mukesh Ojha
2019-04-08 11:04 ` Linus Walleij

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).