Skip to contentSkip to conversation

gpiolib: Add for_each_gpio_suffix() helper

PATCH In review Stefan Roese 6 participants 20 messages Aug 8, 2019 – Aug 14, 2019

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

PATCH 1/2 gpiolib: Add for_each_gpio_suffix() helper

Add a helper macro to enable the interation over all supported GPIO suffixes (currently "gpios" & "gpio"). This will be used by the serial mctrl code to check, if a GPIO property exists before requesting it.

Cc Andy Shevchenko <[email protected]>
Cc Geert Uytterhoeven <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
---
 drivers/gpio/gpiolib.h | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/gpio/gpiolib.h +6 -0
index 7c52c2442173..a3add73f99d6 100644
@@ -92,6 +92,12 @@ struct acpi_gpio_info {
 /* gpio suffixes used for ACPI and device tree lookup */
 static __maybe_unused const char * const gpio_suffixes[] = { "gpios", "gpio" };
 
+#define for_each_gpio_suffix(idx, suffix)				\
+	for (idx = 0;							\
+	     idx < ARRAY_SIZE(gpio_suffixes) &&				\
+		     (suffix = gpio_suffixes[idx]) != NULL;		\
+	     idx++)
+
 #ifdef CONFIG_OF_GPIO
 struct gpio_desc *of_find_gpio(struct device *dev,
 			       const char *con_id,
Signature · 1 line
2.22.0
#1 lore raw

PATCH 2/2 serial: mctrl_gpio: Support all GPIO suffixes (gpios vs gpio)

This patch fixes a backward compatibility issue, when boards use the old style GPIO suffix "-gpio" instead of the new "-gpios". This potential problem has been introduced by commit d99482673f95 ("serial:
mctrl_gpio: Check if GPIO property exisits before requesting it").

This patch now fixes this issue by iterating over all supported GPIO suffixes by using the newly introduced for_each_gpio_suffix() helper.

Also, the string buffer is now allocated on the stack to avoid the problem of allocation in a loop and its potential failure.

Cc Andy Shevchenko <[email protected]>
Cc Geert Uytterhoeven <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
---
 drivers/tty/serial/serial_mctrl_gpio.c | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)
drivers/tty/serial/serial_mctrl_gpio.c +17 -9
index 2b400189be91..d444fdaa280a 100644
@@ -15,6 +15,7 @@
 #include <linux/property.h>
 
 #include "serial_mctrl_gpio.h"
+#include "../../gpio/gpiolib.h"
 
 struct mctrl_gpios {
 	struct uart_port *port;
@@ -117,17 +118,24 @@ struct mctrl_gpios *mctrl_gpio_init_noauto(struct device *dev, unsigned int idx)
 
 	for (i = 0; i < UART_GPIO_MAX; i++) {
 		enum gpiod_flags flags;
-		char *gpio_str;
+		const char *suffix;
+		char gpio_str[32];	/* 32 is max size of property name */
 		bool present;
+		int k;
+
+		/*
+		 * Check if GPIO property exists and continue if not. Iterate
+		 * over all supported GPIO suffixes (foo-gpios vs. foo-gpio).
+		 */
+		for_each_gpio_suffix(k, suffix) {
+			snprintf(gpio_str, sizeof(gpio_str), "%s-%s",
+				 mctrl_gpios_desc[i].name, suffix);
+
+			present = device_property_present(dev, gpio_str);
+			if (present)
+				break;
+		}
 
-		/* Check if GPIO property exists and continue if not */
-		gpio_str = kasprintf(GFP_KERNEL, "%s-gpios",
-				     mctrl_gpios_desc[i].name);
-		if (!gpio_str)
-			continue;
-
-		present = device_property_present(dev, gpio_str);
-		kfree(gpio_str);
 		if (!present)
 			continue;
 
Signature · 1 line
2.22.0
#2 lore raw

Re: [PATCH 2/2] serial: mctrl_gpio: Support all GPIO suffixes (gpios vs gpio)

Quoted 11 lines · Stefan Roese

This patch fixes a backward compatibility issue, when boards use the old style GPIO suffix "-gpio" instead of the new "-gpios". This potential problem has been introduced by commit d99482673f95 ("serial:
mctrl_gpio: Check if GPIO property exisits before requesting it").

This patch now fixes this issue by iterating over all supported GPIO suffixes by using the newly introduced for_each_gpio_suffix() helper.

Also, the string buffer is now allocated on the stack to avoid the problem of allocation in a loop and its potential failure.

drivers/tty/serial/serial_mctrl_gpio.c struct mctrl_gpios *mctrl_gpio_init_noauto(struct device *dev, unsigned int idx) · line 122

Quoted 5 lines
drivers/tty/serial/serial_mctrl_gpio.c +2 -1
 	for (i = 0; i < UART_GPIO_MAX; i++) {
 		enum gpiod_flags flags;
-		char *gpio_str;
+		const char *suffix;
+		char gpio_str[32];	/* 32 is max size of property name */

Hmm... don't we have some define for the maximum length of property?

Or maybe we can still continue using kasprintf() approach?

Quoted 14 lines
drivers/tty/serial/serial_mctrl_gpio.c +13 -0
 		bool present;
+		int k;
+
+		/*
+		 * Check if GPIO property exists and continue if not. Iterate
+		 * over all supported GPIO suffixes (foo-gpios vs. foo-gpio).
+		 */
+		for_each_gpio_suffix(k, suffix) {
+			snprintf(gpio_str, sizeof(gpio_str), "%s-%s",
+				 mctrl_gpios_desc[i].name, suffix);
+
+			present = device_property_present(dev, gpio_str);
+			if (present)
+				break;

drivers/tty/serial/serial_mctrl_gpio.c struct mctrl_gpios *mctrl_gpio_init_noauto(struct device *dev, unsigned int idx)

Quoted 10 lines
drivers/tty/serial/serial_mctrl_gpio.c +1 -7
+		}
 
-		/* Check if GPIO property exists and continue if not */
-		gpio_str = kasprintf(GFP_KERNEL, "%s-gpios",
-				     mctrl_gpios_desc[i].name);
-		if (!gpio_str)
-			continue;
-
 
-		present = device_property_present(dev, gpio_str);

Because there is no more explicit assignment of present outside of the loop, the compiler may warn about uninitialized variable in use...

drivers/tty/serial/serial_mctrl_gpio.c struct mctrl_gpios *mctrl_gpio_init_noauto(struct device *dev, unsigned int idx)

Quoted 3 lines
drivers/tty/serial/serial_mctrl_gpio.c +0 -1
-		kfree(gpio_str);
 
 		if (!present)

...here.

Quoted 1 line

continue;

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

Re: [PATCH 2/2] serial: mctrl_gpio: Support all GPIO suffixes (gpios vs gpio)

Hi Andy,

Quoted 12 lines · Andy Shevchenko
Quoted 10 lines · Stefan Roese

This patch fixes a backward compatibility issue, when boards use the old style GPIO suffix "-gpio" instead of the new "-gpios". This potential problem has been introduced by commit d99482673f95 ("serial:
mctrl_gpio: Check if GPIO property exisits before requesting it").

This patch now fixes this issue by iterating over all supported GPIO suffixes by using the newly introduced for_each_gpio_suffix() helper.

Also, the string buffer is now allocated on the stack to avoid the problem of allocation in a loop and its potential failure.

Quoted 7 lines

drivers/tty/serial/serial_mctrl_gpio.c struct mctrl_gpios *mctrl_gpio_init_noauto(struct device *dev, unsigned int idx) · line 122

Quoted 5 lines
  	for (i = 0; i < UART_GPIO_MAX; i++) {
  		enum gpiod_flags flags;
drivers/tty/serial/serial_mctrl_gpio.c +2 -1
-		char *gpio_str;
+		const char *suffix;
+		char gpio_str[32];	/* 32 is max size of property name */

Hmm... don't we have some define for the maximum length of property?

I've come up with this assumption from this code (identical comment):

https://elixir.bootlin.com/linux/latest/source/drivers/gpio/gpiolib-of.c#L293

(and other places in drivers/gpio/*)

Quoted 1 line

Or maybe we can still continue using kasprintf() approach?

Frankly, I was feeling a bit uncomfortable with this memory allocation in a loop. And Pavel also commented on this:

https://www.mail-archive.com/[email protected]/msg2066286.html

So I would really prefer to move this buffer to the stack instead.

Quoted 28 lines
Quoted 14 lines

bool present;

drivers/tty/serial/serial_mctrl_gpio.c +13 -0
+		int k;
+
+		/*
+		 * Check if GPIO property exists and continue if not. Iterate
+		 * over all supported GPIO suffixes (foo-gpios vs. foo-gpio).
+		 */
+		for_each_gpio_suffix(k, suffix) {
+			snprintf(gpio_str, sizeof(gpio_str), "%s-%s",
+				 mctrl_gpios_desc[i].name, suffix);
+
+			present = device_property_present(dev, gpio_str);
+			if (present)
+				break;

drivers/tty/serial/serial_mctrl_gpio.c struct mctrl_gpios *mctrl_gpio_init_noauto(struct device *dev, unsigned int idx)

Quoted 10 lines
drivers/tty/serial/serial_mctrl_gpio.c +1 -7
+		}
 
-		/* Check if GPIO property exists and continue if not */
-		gpio_str = kasprintf(GFP_KERNEL, "%s-gpios",
-				     mctrl_gpios_desc[i].name);
-		if (!gpio_str)
-			continue;
-
 
-		present = device_property_present(dev, gpio_str);

Because there is no more explicit assignment of present outside of the loop, the compiler may warn about uninitialized variable in use...

Quoted 5 lines

drivers/tty/serial/serial_mctrl_gpio.c struct mctrl_gpios *mctrl_gpio_init_noauto(struct device *dev, unsigned int idx)

Quoted 3 lines
drivers/tty/serial/serial_mctrl_gpio.c +0 -1
-		kfree(gpio_str);
 
  		if (!present)

...here.

My compiler does not warn (MIPS GCC 8.1) but I see your point. I'll add an initialization in the next version.

Thanks,
Stefan

#4 lore raw

Re: [PATCH 2/2] serial: mctrl_gpio: Support all GPIO suffixes (gpios vs gpio)

Quoted 21 lines · Stefan Roese
Quoted 12 lines · Andy Shevchenko
Quoted 10 lines · Stefan Roese

This patch fixes a backward compatibility issue, when boards use the old style GPIO suffix "-gpio" instead of the new "-gpios". This potential problem has been introduced by commit d99482673f95 ("serial:
mctrl_gpio: Check if GPIO property exisits before requesting it").

This patch now fixes this issue by iterating over all supported GPIO suffixes by using the newly introduced for_each_gpio_suffix() helper.

Also, the string buffer is now allocated on the stack to avoid the problem of allocation in a loop and its potential failure.

Quoted 7 lines

drivers/tty/serial/serial_mctrl_gpio.c struct mctrl_gpios *mctrl_gpio_init_noauto(struct device *dev, unsigned int idx) · line 122

Quoted 5 lines
  	for (i = 0; i < UART_GPIO_MAX; i++) {
  		enum gpiod_flags flags;
drivers/tty/serial/serial_mctrl_gpio.c +2 -1
-		char *gpio_str;
+		const char *suffix;
+		char gpio_str[32];	/* 32 is max size of property name */

Hmm... don't we have some define for the maximum length of property?

Quoted 5 lines

I've come up with this assumption from this code (identical comment):

https://elixir.bootlin.com/linux/latest/source/drivers/gpio/gpiolib-of.c#L293

(and other places in drivers/gpio/*)

I tried hard to find an evidence of this in Linux kernel, I assume that comes from DT compiler or something, but fail. Linux kernel OF properties handling is written in the assumption of arbitrary length of the property name.

It might be that my hard was not hard at all and I missed something.

Quoted 6 lines
Quoted 1 line

Or maybe we can still continue using kasprintf() approach?

Frankly, I was feeling a bit uncomfortable with this memory allocation in a loop. And Pavel also commented on this:

https://www.mail-archive.com/[email protected]/msg2066286.html

If memory allocator fails, it's a big issue, and what will happen next probably much less important.

Quoted 1 line

So I would really prefer to move this buffer to the stack instead.

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

Re: [PATCH 2/2] serial: mctrl_gpio: Support all GPIO suffixes (gpios vs gpio)

Quoted 36 lines · Andy Shevchenko
Quoted 21 lines · Stefan Roese
Quoted 12 lines · Andy Shevchenko
Quoted 10 lines · Stefan Roese

This patch fixes a backward compatibility issue, when boards use the old style GPIO suffix "-gpio" instead of the new "-gpios". This potential problem has been introduced by commit d99482673f95 ("serial:
mctrl_gpio: Check if GPIO property exisits before requesting it").

This patch now fixes this issue by iterating over all supported GPIO suffixes by using the newly introduced for_each_gpio_suffix() helper.

Also, the string buffer is now allocated on the stack to avoid the problem of allocation in a loop and its potential failure.

Quoted 7 lines

drivers/tty/serial/serial_mctrl_gpio.c struct mctrl_gpios *mctrl_gpio_init_noauto(struct device *dev, unsigned int idx) · line 122

Quoted 5 lines
  	for (i = 0; i < UART_GPIO_MAX; i++) {
  		enum gpiod_flags flags;
drivers/tty/serial/serial_mctrl_gpio.c +2 -1
-		char *gpio_str;
+		const char *suffix;
+		char gpio_str[32];	/* 32 is max size of property name */

Hmm... don't we have some define for the maximum length of property?

Quoted 5 lines

I've come up with this assumption from this code (identical comment):

https://elixir.bootlin.com/linux/latest/source/drivers/gpio/gpiolib-of.c#L293

(and other places in drivers/gpio/*)

I tried hard to find an evidence of this in Linux kernel, I assume that comes from DT compiler or something, but fail. Linux kernel OF properties handling is written in the assumption of arbitrary length of the property name.

It might be that my hard was not hard at all and I missed something.

Quoted 2 lines
Quoted 1 line

Or maybe we can still continue using kasprintf() approach?

Quoted 7 lines
Quoted 4 lines

Frankly, I was feeling a bit uncomfortable with this memory allocation in a loop. And Pavel also commented on this:

https://www.mail-archive.com/[email protected]/msg2066286.html

If memory allocator fails, it's a big issue, and what will happen next probably much less important.

Not... really. With "too big" allocations, it will fail.

Anyway, my point is that allocating in a loop for this is slow and ugly. If we don't have a maximum property length, we should probably invent some. I mean, we can agree that 64KB property name is not okay, right?

Pavel

Signature · 2 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
#6 lore raw

Re: [PATCH 2/2] serial: mctrl_gpio: Support all GPIO suffixes (gpios vs gpio)

Quoted 16 lines · Pavel Machek
Quoted 15 lines · Andy Shevchenko
Quoted 2 lines · Stefan Roese
Quoted 1 line · Andy Shevchenko

On Thu, Aug 08, 2019 at 03:25:43PM +0200, Stefan Roese wrote:

I tried hard to find an evidence of this in Linux kernel, I assume that comes from DT compiler or something, but fail. Linux kernel OF properties handling is written in the assumption of arbitrary length of the property name.

It might be that my hard was not hard at all and I missed something.

Quoted 5 lines
Quoted 1 line

Or maybe we can still continue using kasprintf() approach?

Frankly, I was feeling a bit uncomfortable with this memory allocation in a loop. And Pavel also commented on this:

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

https://www.mail-archive.com/[email protected]/msg2066286.html

If memory allocator fails, it's a big issue, and what will happen next probably much less important.

Not... really. With "too big" allocations, it will fail.

Yeah, or with relatively small if memory is too much fragmented. But we are talking about really small allocations here in most cases, right?

Quoted 4 lines

Anyway, my point is that allocating in a loop for this is slow and ugly. If we don't have a maximum property length, we should probably invent some. I mean, we can agree that 64KB property name is not okay, right?

My point that is should be declared on the level of property API. Restricting it on the level of one, 'client' to that API, framework is not a solution.

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

Re: [PATCH 2/2] serial: mctrl_gpio: Support all GPIO suffixes (gpios vs gpio)

In reply to Stefan Roese

Hi Stefan,

Quoted 5 lines · Stefan Roese

This patch fixes a backward compatibility issue, when boards use the old style GPIO suffix "-gpio" instead of the new "-gpios". This potential problem has been introduced by commit d99482673f95 ("serial:
mctrl_gpio: Check if GPIO property exisits before requesting it").

Quoted 7 lines

This patch now fixes this issue by iterating over all supported GPIO suffixes by using the newly introduced for_each_gpio_suffix() helper.

Also, the string buffer is now allocated on the stack to avoid the problem of allocation in a loop and its potential failure.

Do we really need to spread this *-gpio" legacy support all over the kernel?

Seeing the only in-kernel users of legacy "rts-gpio" are

    arch/arm/boot/dts/am335x-nano.dts:      rts-gpio = <&gpio0 13
GPIO_ACTIVE_HIGH>;
    arch/arm/boot/dts/am335x-nano.dts:      rts-gpio = <&gpio2 15
GPIO_ACTIVE_HIGH>;
    arch/arm/boot/dts/am335x-pdu001.dts:    rts-gpio = <&gpio1 9

GPIO_ACTIVE_HIGH>;

and this is handled by omap-serial.c, predating mctrl_gpio, I'd like to reconsider.

Documentation/devicetree/bindings/serial/serial.txt always described the "*-gpios"
variants, so there should be no users of the legacy "*-gpio" variants.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#8 lore raw

Re: [PATCH 2/2] serial: mctrl_gpio: Support all GPIO suffixes (gpios vs gpio)

Hi Geert,

Quoted 25 lines · Geert Uytterhoeven

Hi Stefan,

Quoted 5 lines · Stefan Roese

This patch fixes a backward compatibility issue, when boards use the old style GPIO suffix "-gpio" instead of the new "-gpios". This potential problem has been introduced by commit d99482673f95 ("serial:
mctrl_gpio: Check if GPIO property exisits before requesting it").

Quoted 7 lines

This patch now fixes this issue by iterating over all supported GPIO suffixes by using the newly introduced for_each_gpio_suffix() helper.

Also, the string buffer is now allocated on the stack to avoid the problem of allocation in a loop and its potential failure.

Do we really need to spread this *-gpio" legacy support all over the kernel?

Seeing the only in-kernel users of legacy "rts-gpio" are

     arch/arm/boot/dts/am335x-nano.dts:      rts-gpio = <&gpio0 13
GPIO_ACTIVE_HIGH>;
     arch/arm/boot/dts/am335x-nano.dts:      rts-gpio = <&gpio2 15
GPIO_ACTIVE_HIGH>;
     arch/arm/boot/dts/am335x-pdu001.dts:    rts-gpio = <&gpio1 9
Quoted 8 lines

GPIO_ACTIVE_HIGH>;

and this is handled by omap-serial.c, predating mctrl_gpio, I'd like to reconsider.

Documentation/devicetree/bindings/serial/serial.txt always described the "*-gpios"
variants, so there should be no users of the legacy "*-gpio" variants.

Hmmm, you were the one to comment about supporting (not breaking) the "-gpio" variant:

https://lkml.org/lkml/2019/6/24/248

That was my main motivation to work on this patch.

If we all agree, that only the documented "-gpios" variant needs to be supported, then we can drop this patch.

Thanks,
Stefan

#9 lore raw

Re: [PATCH 2/2] serial: mctrl_gpio: Support all GPIO suffixes (gpios vs gpio)

Hi Stefan,

Quoted 33 lines · Stefan Roese
Quoted 23 lines · Geert Uytterhoeven
Quoted 5 lines · Stefan Roese

This patch fixes a backward compatibility issue, when boards use the old style GPIO suffix "-gpio" instead of the new "-gpios". This potential problem has been introduced by commit d99482673f95 ("serial:
mctrl_gpio: Check if GPIO property exisits before requesting it").

Quoted 7 lines

This patch now fixes this issue by iterating over all supported GPIO suffixes by using the newly introduced for_each_gpio_suffix() helper.

Also, the string buffer is now allocated on the stack to avoid the problem of allocation in a loop and its potential failure.

Do we really need to spread this *-gpio" legacy support all over the kernel?

Seeing the only in-kernel users of legacy "rts-gpio" are

     arch/arm/boot/dts/am335x-nano.dts:      rts-gpio = <&gpio0 13
GPIO_ACTIVE_HIGH>;
     arch/arm/boot/dts/am335x-nano.dts:      rts-gpio = <&gpio2 15
GPIO_ACTIVE_HIGH>;
     arch/arm/boot/dts/am335x-pdu001.dts:    rts-gpio = <&gpio1 9
Quoted 8 lines

GPIO_ACTIVE_HIGH>;

and this is handled by omap-serial.c, predating mctrl_gpio, I'd like to reconsider.

Documentation/devicetree/bindings/serial/serial.txt always described the "*-gpios"
variants, so there should be no users of the legacy "*-gpio" variants.

Quoted 6 lines

Hmmm, you were the one to comment about supporting (not breaking) the "-gpio" variant:

https://lkml.org/lkml/2019/6/24/248

That was my main motivation to work on this patch.

I know. That's why I wrote "reconsider". Before, I assumed there were actual users of the legacy properties, which turned out to be wrong.

IMHO no driver should be aware there can be multiple possible suffixes.

Sorry for the trouble.

Quoted 2 lines

If we all agree, that only the documented "-gpios" variant needs to be supported, then we can drop this patch.

BTW, I'm still wondering if d99482673f950817 ("serial: mctrl_gpio: Check if GPIO property exisits before requesting it") is the right fix. This is a place where we rely explicitly on named GPIOs being present, so IMHO the ACPI code should not return a random GPIO instead.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#10 lore raw

Re: [PATCH 2/2] serial: mctrl_gpio: Support all GPIO suffixes (gpios vs gpio)

Quoted 10 lines · Geert Uytterhoeven
Quoted 4 lines · Stefan Roese

On 12.08.19 13:17, Geert Uytterhoeven wrote:

If we all agree, that only the documented "-gpios" variant needs to be supported, then we can drop this patch.

BTW, I'm still wondering if d99482673f950817 ("serial: mctrl_gpio: Check if GPIO property exisits before requesting it") is the right fix. This is a place where we rely explicitly on named GPIOs being present, so IMHO the ACPI code should not return a random GPIO instead.

ACPI is not taking it to consideration for now. That is, there is no support of mctrl gpio for ACPI.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#11 lore raw
In reply to Stefan Roese
Quoted 3 lines · Stefan Roese

Add a helper macro to enable the interation over all supported GPIO suffixes (currently "gpios" & "gpio"). This will be used by the serial mctrl code to check, if a GPIO property exists before requesting it.

Thanks! My comments below.

drivers/gpio/gpiolib.h struct acpi_gpio_info { · line 99

Quoted 5 lines
drivers/gpio/gpiolib.h +5 -0
+#define for_each_gpio_suffix(idx, suffix)				\
+	for (idx = 0;							\
+	     idx < ARRAY_SIZE(gpio_suffixes) &&				\
+		     (suffix = gpio_suffixes[idx]) != NULL;		\
+	     idx++)

I think we can use comma here, like

	for (idx = 0; idx < ARRAY_SIZE(...), suffix = ...; idx++;)

however, this needs to be checked, b/c I think the last operation makes a return code, and probably we have to assign suffix first.

(and perhaps switch to one letter for idx makes it fit one line)

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

Hi Andy,

Quoted 15 lines · Andy Shevchenko
Quoted 3 lines · Stefan Roese

Add a helper macro to enable the interation over all supported GPIO suffixes (currently "gpios" & "gpio"). This will be used by the serial mctrl code to check, if a GPIO property exists before requesting it.

Thanks! My comments below.

drivers/gpio/gpiolib.h struct acpi_gpio_info { · line 99

Quoted 5 lines
drivers/gpio/gpiolib.h +5 -0
+#define for_each_gpio_suffix(idx, suffix)				\
+	for (idx = 0;							\
+	     idx < ARRAY_SIZE(gpio_suffixes) &&				\
+		     (suffix = gpio_suffixes[idx]) != NULL;		\
+	     idx++)

I think we can use comma here, like

Quoted 4 lines
	for (idx = 0; idx < ARRAY_SIZE(...), suffix = ...; idx++;)

however, this needs to be checked, b/c I think the last operation makes a return code, and probably we have to assign suffix first.

Yes, this seems to be the case (assign suffix first). But in this case, the assignment is done *before* checking if the index is still valid (in the array). In this case "suffix = gpio_suffices[2]". Or am I missing something?

Quoted 1 line

(and perhaps switch to one letter for idx makes it fit one line)

Yes.

Thanks,
Stefan

#13 lore raw
In reply to Stefan Roese
Quoted 11 lines · Stefan Roese

Add a helper macro to enable the interation over all supported GPIO suffixes (currently "gpios" & "gpio"). This will be used by the serial mctrl code to check, if a GPIO property exists before requesting it.

Cc Andy Shevchenko <[email protected]>
Cc Geert Uytterhoeven <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>

I really like this patch, it makes things so much more readable.

Do you want me to apply both patches to the GPIO tree when we agreed on the final version? I need some ACK from some serial maintainer.

Yours,
Linus Walleij

#14 lore raw
Quoted 14 lines · Linus Walleij
Quoted 11 lines · Stefan Roese

Add a helper macro to enable the interation over all supported GPIO suffixes (currently "gpios" & "gpio"). This will be used by the serial mctrl code to check, if a GPIO property exists before requesting it.

Cc Andy Shevchenko <[email protected]>
Cc Geert Uytterhoeven <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Quoted 5 lines

I really like this patch, it makes things so much more readable.

Do you want me to apply both patches to the GPIO tree when we agreed on the final version? I need some ACK from some serial maintainer.

When you all can agree on the final version, I'll be glad to give my ack for you to take these :)

thanks,

greg k-h

#15 lore raw
In reply to Linus Walleij

Hi Linus,

Quoted 13 lines · Linus Walleij
Quoted 11 lines · Stefan Roese

Add a helper macro to enable the interation over all supported GPIO suffixes (currently "gpios" & "gpio"). This will be used by the serial mctrl code to check, if a GPIO property exists before requesting it.

Cc Andy Shevchenko <[email protected]>
Cc Geert Uytterhoeven <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Quoted 1 line

I really like this patch, it makes things so much more readable.

Do we really need to spread this *-gpio" legacy support all over the kernel?

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#16 lore raw
Quoted 14 lines · Geert Uytterhoeven
Quoted 13 lines · Linus Walleij
Quoted 11 lines · Stefan Roese

Add a helper macro to enable the interation over all supported GPIO suffixes (currently "gpios" & "gpio"). This will be used by the serial mctrl code to check, if a GPIO property exists before requesting it.

Cc Andy Shevchenko <[email protected]>
Cc Geert Uytterhoeven <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Quoted 3 lines
Quoted 1 line

I really like this patch, it makes things so much more readable.

Do we really need to spread this *-gpio" legacy support all over the kernel?

Not really :/

Isn't it possible to use something like gpiod_count(dev, "foo") to check for any GPIOs instead?

Yours,
Linus Walleij

#17 lore raw
Quoted 15 lines · Linus Walleij
Quoted 14 lines · Geert Uytterhoeven
Quoted 13 lines · Linus Walleij
Quoted 11 lines · Stefan Roese

Add a helper macro to enable the interation over all supported GPIO suffixes (currently "gpios" & "gpio"). This will be used by the serial mctrl code to check, if a GPIO property exists before requesting it.

Cc Andy Shevchenko <[email protected]>
Cc Geert Uytterhoeven <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Quoted 8 lines
Quoted 3 lines
Quoted 1 line

I really like this patch, it makes things so much more readable.

Do we really need to spread this *-gpio" legacy support all over the kernel?

Not really :/

Isn't it possible to use something like gpiod_count(dev, "foo") to check for any GPIOs instead?

Good idea. I can rework my patch to use gpiod_count() to check if the GPIO exists before requesting it. This way, we're not spreading the legacy "-gpio" support any more.

But I'm unsure, if I should change the string malloc (kasprintf) to the fixed length string on the stack as I've done in this patch version.

Thanks,
Stefan

#18 lore raw

Hi Stefan,

Quoted 25 lines · Stefan Roese
Quoted 15 lines · Linus Walleij
Quoted 14 lines · Geert Uytterhoeven
Quoted 13 lines · Linus Walleij
Quoted 11 lines · Stefan Roese

Add a helper macro to enable the interation over all supported GPIO suffixes (currently "gpios" & "gpio"). This will be used by the serial mctrl code to check, if a GPIO property exists before requesting it.

Cc Andy Shevchenko <[email protected]>
Cc Geert Uytterhoeven <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Quoted 8 lines
Quoted 3 lines
Quoted 1 line

I really like this patch, it makes things so much more readable.

Do we really need to spread this *-gpio" legacy support all over the kernel?

Not really :/

Isn't it possible to use something like gpiod_count(dev, "foo") to check for any GPIOs instead?

Quoted 6 lines

Good idea. I can rework my patch to use gpiod_count() to check if the GPIO exists before requesting it. This way, we're not spreading the legacy "-gpio" support any more.

But I'm unsure, if I should change the string malloc (kasprintf) to the fixed length string on the stack as I've done in this patch version.

Would that work for the mctrl-gpio case?
The issue is that there exist GPIOs (found by index), but they don't match the passed con_id.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#19 lore raw
In reply to Stefan Roese
Quoted 25 lines · Stefan Roese
Quoted 15 lines · Linus Walleij
Quoted 14 lines · Geert Uytterhoeven
Quoted 13 lines · Linus Walleij
Quoted 11 lines · Stefan Roese

Add a helper macro to enable the interation over all supported GPIO suffixes (currently "gpios" & "gpio"). This will be used by the serial mctrl code to check, if a GPIO property exists before requesting it.

Cc Andy Shevchenko <[email protected]>
Cc Geert Uytterhoeven <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Quoted 8 lines
Quoted 3 lines
Quoted 1 line

I really like this patch, it makes things so much more readable.

Do we really need to spread this *-gpio" legacy support all over the kernel?

Not really :/

Isn't it possible to use something like gpiod_count(dev, "foo") to check for any GPIOs instead?

Quoted 6 lines

Good idea. I can rework my patch to use gpiod_count() to check if the GPIO exists before requesting it. This way, we're not spreading the legacy "-gpio" support any more.

But I'm unsure, if I should change the string malloc (kasprintf) to the fixed length string on the stack as I've done in this patch version.

You don't need suffix for gpiod_count(). Will you need that at all?

Signature · 2 lines
With Best Regards,
Andy Shevchenko