public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] gpio: provide for_each_gpio()
@ 2024-02-15  8:33 Bartosz Golaszewski
  2024-02-15  8:33 ` [PATCH 2/2] gpio: sim: use for_each_gpio() Bartosz Golaszewski
  2024-02-21 21:51 ` [PATCH 1/2] gpio: provide for_each_gpio() Linus Walleij
  0 siblings, 2 replies; 6+ messages in thread
From: Bartosz Golaszewski @ 2024-02-15  8:33 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski
  Cc: linux-gpio, linux-kernel, Bartosz Golaszewski

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>
---
 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 9d0023f83a57..5f915b653548 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_gpio - 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_gpio(_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


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

* [PATCH 2/2] gpio: sim: use for_each_gpio()
  2024-02-15  8:33 [PATCH 1/2] gpio: provide for_each_gpio() Bartosz Golaszewski
@ 2024-02-15  8:33 ` Bartosz Golaszewski
  2024-02-21 21:52   ` Linus Walleij
  2024-02-21 21:51 ` [PATCH 1/2] gpio: provide for_each_gpio() Linus Walleij
  1 sibling, 1 reply; 6+ messages in thread
From: Bartosz Golaszewski @ 2024-02-15  8:33 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski
  Cc: linux-gpio, linux-kernel, Bartosz Golaszewski

From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

Display debugfs information about all simulated GPIOs, not only the
requested ones.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
 drivers/gpio/gpio-sim.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpio/gpio-sim.c b/drivers/gpio/gpio-sim.c
index c4106e37e6db..1ebd6961ffba 100644
--- a/drivers/gpio/gpio-sim.c
+++ b/drivers/gpio/gpio-sim.c
@@ -234,10 +234,10 @@ static void gpio_sim_dbg_show(struct seq_file *seq, struct gpio_chip *gc)
 
 	guard(mutex)(&chip->lock);
 
-	for_each_requested_gpio(gc, i, label)
+	for_each_gpio(gc, i, label)
 		seq_printf(seq, " gpio-%-3d (%s) %s,%s\n",
 			   gc->base + i,
-			   label,
+			   label ?: "<unused>",
 			   test_bit(i, chip->direction_map) ? "input" :
 				test_bit(i, chip->value_map) ? "output-high" :
 							       "output-low",
-- 
2.40.1


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

* Re: [PATCH 1/2] gpio: provide for_each_gpio()
  2024-02-15  8:33 [PATCH 1/2] gpio: provide for_each_gpio() Bartosz Golaszewski
  2024-02-15  8:33 ` [PATCH 2/2] gpio: sim: use for_each_gpio() Bartosz Golaszewski
@ 2024-02-21 21:51 ` Linus Walleij
  2024-02-22  8:48   ` Bartosz Golaszewski
  1 sibling, 1 reply; 6+ messages in thread
From: Linus Walleij @ 2024-02-21 21:51 UTC (permalink / raw)
  To: Bartosz Golaszewski; +Cc: linux-gpio, linux-kernel, Bartosz Golaszewski

Hi Bartosz,

On Thu, Feb 15, 2024 at 9:33 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>
(...)

> +/**
> + * for_each_gpio - Iterates over all GPIOs for given chip.

Does this really intuitively fit with other functions named for_each_XXX()?

> + * @_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_gpio(_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

I would call it for_each_line_label() or something. I try to avoid using
"gpio" in function names as well because of ambiguity, I could also go
with for_each_hwgpio_label() I suppose.

With some more reasonable name:
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

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

* Re: [PATCH 2/2] gpio: sim: use for_each_gpio()
  2024-02-15  8:33 ` [PATCH 2/2] gpio: sim: use for_each_gpio() Bartosz Golaszewski
@ 2024-02-21 21:52   ` Linus Walleij
  0 siblings, 0 replies; 6+ messages in thread
From: Linus Walleij @ 2024-02-21 21:52 UTC (permalink / raw)
  To: Bartosz Golaszewski; +Cc: linux-gpio, linux-kernel, Bartosz Golaszewski

On Thu, Feb 15, 2024 at 9:33 AM Bartosz Golaszewski <brgl@bgdev.pl> wrote:

> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
>
> Display debugfs information about all simulated GPIOs, not only the
> requested ones.
>
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

With the naming of that function fixed in 1/2:
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

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

* Re: [PATCH 1/2] gpio: provide for_each_gpio()
  2024-02-21 21:51 ` [PATCH 1/2] gpio: provide for_each_gpio() Linus Walleij
@ 2024-02-22  8:48   ` Bartosz Golaszewski
  2024-02-22  9:18     ` Linus Walleij
  0 siblings, 1 reply; 6+ messages in thread
From: Bartosz Golaszewski @ 2024-02-22  8:48 UTC (permalink / raw)
  To: Linus Walleij; +Cc: linux-gpio, linux-kernel, Bartosz Golaszewski

On Wed, Feb 21, 2024 at 10:51 PM Linus Walleij <linus.walleij@linaro.org> wrote:
>
> Hi Bartosz,
>
> On Thu, Feb 15, 2024 at 9:33 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>
> (...)
>
> > +/**
> > + * for_each_gpio - Iterates over all GPIOs for given chip.
>
> Does this really intuitively fit with other functions named for_each_XXX()?
>
> > + * @_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_gpio(_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
>
> I would call it for_each_line_label() or something. I try to avoid using
> "gpio" in function names as well because of ambiguity, I could also go
> with for_each_hwgpio_label() I suppose.

The problem is: this doesn't iterate over labels. It really goes
through all offsets and if there's no consumer then the label is NULL
(I should have said that in the kerneldoc).

>
> With some more reasonable name:

Does for_each_hwgpio() make more sense?

Bart

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

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

* Re: [PATCH 1/2] gpio: provide for_each_gpio()
  2024-02-22  8:48   ` Bartosz Golaszewski
@ 2024-02-22  9:18     ` Linus Walleij
  0 siblings, 0 replies; 6+ messages in thread
From: Linus Walleij @ 2024-02-22  9:18 UTC (permalink / raw)
  To: Bartosz Golaszewski; +Cc: linux-gpio, linux-kernel, Bartosz Golaszewski

On Thu, Feb 22, 2024 at 9:48 AM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
> On Wed, Feb 21, 2024 at 10:51 PM Linus Walleij <linus.walleij@linaro.org> wrote:
> >
> > Hi Bartosz,
> >
> > On Thu, Feb 15, 2024 at 9:33 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>
> > (...)
> >
> > > +/**
> > > + * for_each_gpio - Iterates over all GPIOs for given chip.
> >
> > Does this really intuitively fit with other functions named for_each_XXX()?
> >
> > > + * @_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_gpio(_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
> >
> > I would call it for_each_line_label() or something. I try to avoid using
> > "gpio" in function names as well because of ambiguity, I could also go
> > with for_each_hwgpio_label() I suppose.
>
> The problem is: this doesn't iterate over labels. It really goes
> through all offsets and if there's no consumer then the label is NULL
> (I should have said that in the kerneldoc).
>
> >
> > With some more reasonable name:
>
> Does for_each_hwgpio() make more sense?

It's better it reflects the usage, but isn't the usage to conditionally
extract the label (or NULL) for each hwgpio?

What I'm after is if there is a risk that someone think this is a generic
iterator for hwgpios which would be confusing.

At the same time
for_each_hwgpio_attempt_extract_label() is a bit long I guess.

I don't wanna bikeshed too much so go with for_each_hwgpio() if
you don't immediately see anything better.

Yours,
Linus Walleij

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

end of thread, other threads:[~2024-02-22  9:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-15  8:33 [PATCH 1/2] gpio: provide for_each_gpio() Bartosz Golaszewski
2024-02-15  8:33 ` [PATCH 2/2] gpio: sim: use for_each_gpio() Bartosz Golaszewski
2024-02-21 21:52   ` Linus Walleij
2024-02-21 21:51 ` [PATCH 1/2] gpio: provide for_each_gpio() Linus Walleij
2024-02-22  8:48   ` Bartosz Golaszewski
2024-02-22  9:18     ` Linus Walleij

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox