diff mbox series

[v2,1/2] gpio: provide for_each_hwgpio()

Message ID 20240222102513.16975-1-brgl@bgdev.pl
State New
Headers show
Series [v2,1/2] gpio: provide for_each_hwgpio() | expand

Commit Message

Bartosz Golaszewski Feb. 22, 2024, 10:25 a.m. UTC
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

We only provide iterators for requested GPIOs to provider drivers. In
order to allow them to display debug information about all GPIOs, let's
provide a variant for iterating over all GPIOs.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
v1 -> v2:
- rename the iterator to for_each_hwgpio()

 include/linux/gpio/driver.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

Comments

Linus Walleij Feb. 22, 2024, 12:04 p.m. UTC | #1
On Thu, Feb 22, 2024 at 11:25 AM Bartosz Golaszewski <brgl@bgdev.pl> wrote:

> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
>
> We only provide iterators for requested GPIOs to provider drivers. In
> order to allow them to display debug information about all GPIOs, let's
> provide a variant for iterating over all GPIOs.
>
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> ---
> v1 -> v2:
> - rename the iterator to for_each_hwgpio()

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij
Bartosz Golaszewski Feb. 23, 2024, 8:58 a.m. UTC | #2
On Thu, Feb 22, 2024 at 11:25 AM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
>
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
>
> We only provide iterators for requested GPIOs to provider drivers. In
> order to allow them to display debug information about all GPIOs, let's
> provide a variant for iterating over all GPIOs.
>
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> ---
> v1 -> v2:
> - rename the iterator to for_each_hwgpio()
>
>  include/linux/gpio/driver.h | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
>
> diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h
> index 9c1fbfaebaa8..175129a92656 100644
> --- a/include/linux/gpio/driver.h
> +++ b/include/linux/gpio/driver.h
> @@ -551,6 +551,21 @@ DEFINE_CLASS(_gpiochip_for_each_data,
>              }),
>              const char **label, int *i)
>
> +/**
> + * for_each_hwgpio - Iterates over all GPIOs for given chip.
> + * @_chip: Chip to iterate over.
> + * @_i: Loop counter.
> + * @_label: Place to store the address of the label if the GPIO is requested.
> + *          Set to NULL for unused GPIOs.
> + */
> +#define for_each_hwgpio(_chip, _i, _label) \
> +       for (CLASS(_gpiochip_for_each_data, _data)(&_label, &_i); \
> +            *_data.i < _chip->ngpio; \
> +            (*_data.i)++, kfree(*(_data.label)), *_data.label = NULL) \
> +               if (IS_ERR(*_data.label = \
> +                       gpiochip_dup_line_label(_chip, *_data.i))) {} \
> +               else
> +
>  /**
>   * for_each_requested_gpio_in_range - iterates over requested GPIOs in a given range
>   * @_chip:     the chip to query
> --
> 2.40.1
>

Patch applied.

Bart
diff mbox series

Patch

diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h
index 9c1fbfaebaa8..175129a92656 100644
--- a/include/linux/gpio/driver.h
+++ b/include/linux/gpio/driver.h
@@ -551,6 +551,21 @@  DEFINE_CLASS(_gpiochip_for_each_data,
 	     }),
 	     const char **label, int *i)
 
+/**
+ * for_each_hwgpio - Iterates over all GPIOs for given chip.
+ * @_chip: Chip to iterate over.
+ * @_i: Loop counter.
+ * @_label: Place to store the address of the label if the GPIO is requested.
+ *          Set to NULL for unused GPIOs.
+ */
+#define for_each_hwgpio(_chip, _i, _label) \
+	for (CLASS(_gpiochip_for_each_data, _data)(&_label, &_i); \
+	     *_data.i < _chip->ngpio; \
+	     (*_data.i)++, kfree(*(_data.label)), *_data.label = NULL) \
+		if (IS_ERR(*_data.label = \
+			gpiochip_dup_line_label(_chip, *_data.i))) {} \
+		else
+
 /**
  * for_each_requested_gpio_in_range - iterates over requested GPIOs in a given range
  * @_chip:	the chip to query