linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gpiolib: Document that GPIO line names are not globally unique
@ 2020-05-11 10:18 Geert Uytterhoeven
  2020-05-12 10:43 ` Bartosz Golaszewski
  2020-05-16  9:37 ` Linus Walleij
  0 siblings, 2 replies; 4+ messages in thread
From: Geert Uytterhoeven @ 2020-05-11 10:18 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski
  Cc: linux-gpio, linux-kernel, Geert Uytterhoeven

gpiochip_set_desc_names() no longer rejects GPIO line name collisions.
Hence GPIO line names are not guaranteed to be globally unique.
In case of multiple GPIO lines with the same name, gpio_name_to_desc()
will return the first match found.

Update the comments for gpio_name_to_desc() and
gpiochip_set_desc_names() to match reality.

Fixes: f881bab038c9667d ("gpio: keep the GPIO line names internal")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
 drivers/gpio/gpiolib.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 99533f4cb5d332a9..98822412f565073a 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -296,6 +296,9 @@ static int gpiodev_add_to_list(struct gpio_device *gdev)
 
 /*
  * Convert a GPIO name to its descriptor
+ * Note that there is no guarantee that GPIO names are globally unique!
+ * Hence this function will return, if it exists, a reference to the first GPIO
+ * line found that matches the given name.
  */
 static struct gpio_desc *gpio_name_to_desc(const char * const name)
 {
@@ -329,10 +332,12 @@ static struct gpio_desc *gpio_name_to_desc(const char * const name)
 }
 
 /*
- * Takes the names from gc->names and checks if they are all unique. If they
- * are, they are assigned to their gpio descriptors.
+ * Take the names from gc->names and assign them to their GPIO descriptors.
+ * Warn if a name is already used for a GPIO line on a different GPIO chip.
  *
- * Warning if one of the names is already used for a different GPIO.
+ * Note that:
+ *   1. Non-unique names are still accepted,
+ *   2. Name collisions within the same GPIO chip are not reported.
  */
 static int gpiochip_set_desc_names(struct gpio_chip *gc)
 {
-- 
2.17.1


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

* Re: [PATCH] gpiolib: Document that GPIO line names are not globally unique
  2020-05-11 10:18 [PATCH] gpiolib: Document that GPIO line names are not globally unique Geert Uytterhoeven
@ 2020-05-12 10:43 ` Bartosz Golaszewski
  2020-05-16  9:41   ` Linus Walleij
  2020-05-16  9:37 ` Linus Walleij
  1 sibling, 1 reply; 4+ messages in thread
From: Bartosz Golaszewski @ 2020-05-12 10:43 UTC (permalink / raw)
  To: Geert Uytterhoeven; +Cc: Linus Walleij, linux-gpio, LKML

pon., 11 maj 2020 o 12:18 Geert Uytterhoeven <geert+renesas@glider.be>
napisał(a):
>
> gpiochip_set_desc_names() no longer rejects GPIO line name collisions.
> Hence GPIO line names are not guaranteed to be globally unique.
> In case of multiple GPIO lines with the same name, gpio_name_to_desc()
> will return the first match found.
>
> Update the comments for gpio_name_to_desc() and
> gpiochip_set_desc_names() to match reality.
>
> Fixes: f881bab038c9667d ("gpio: keep the GPIO line names internal")
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> ---
>  drivers/gpio/gpiolib.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index 99533f4cb5d332a9..98822412f565073a 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -296,6 +296,9 @@ static int gpiodev_add_to_list(struct gpio_device *gdev)
>
>  /*
>   * Convert a GPIO name to its descriptor
> + * Note that there is no guarantee that GPIO names are globally unique!
> + * Hence this function will return, if it exists, a reference to the first GPIO
> + * line found that matches the given name.
>   */
>  static struct gpio_desc *gpio_name_to_desc(const char * const name)
>  {
> @@ -329,10 +332,12 @@ static struct gpio_desc *gpio_name_to_desc(const char * const name)
>  }
>
>  /*
> - * Takes the names from gc->names and checks if they are all unique. If they
> - * are, they are assigned to their gpio descriptors.
> + * Take the names from gc->names and assign them to their GPIO descriptors.
> + * Warn if a name is already used for a GPIO line on a different GPIO chip.
>   *
> - * Warning if one of the names is already used for a different GPIO.
> + * Note that:
> + *   1. Non-unique names are still accepted,
> + *   2. Name collisions within the same GPIO chip are not reported.
>   */
>  static int gpiochip_set_desc_names(struct gpio_chip *gc)
>  {
> --
> 2.17.1
>

This makes me wonder whether I should do something about this in
libgpiod? Looks to me like gpiod_chip_find_line() and the global
gpiod_line_find() are no longer reliable and should probably return
all lines whose names match.

Bart

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

* Re: [PATCH] gpiolib: Document that GPIO line names are not globally unique
  2020-05-11 10:18 [PATCH] gpiolib: Document that GPIO line names are not globally unique Geert Uytterhoeven
  2020-05-12 10:43 ` Bartosz Golaszewski
@ 2020-05-16  9:37 ` Linus Walleij
  1 sibling, 0 replies; 4+ messages in thread
From: Linus Walleij @ 2020-05-16  9:37 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Bartosz Golaszewski, open list:GPIO SUBSYSTEM, linux-kernel

On Mon, May 11, 2020 at 12:18 PM Geert Uytterhoeven
<geert+renesas@glider.be> wrote:

> gpiochip_set_desc_names() no longer rejects GPIO line name collisions.
> Hence GPIO line names are not guaranteed to be globally unique.
> In case of multiple GPIO lines with the same name, gpio_name_to_desc()
> will return the first match found.
>
> Update the comments for gpio_name_to_desc() and
> gpiochip_set_desc_names() to match reality.
>
> Fixes: f881bab038c9667d ("gpio: keep the GPIO line names internal")
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>

Patch applied.

Yours,
Linus Walleij

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

* Re: [PATCH] gpiolib: Document that GPIO line names are not globally unique
  2020-05-12 10:43 ` Bartosz Golaszewski
@ 2020-05-16  9:41   ` Linus Walleij
  0 siblings, 0 replies; 4+ messages in thread
From: Linus Walleij @ 2020-05-16  9:41 UTC (permalink / raw)
  To: Bartosz Golaszewski; +Cc: Geert Uytterhoeven, linux-gpio, LKML

On Tue, May 12, 2020 at 12:43 PM Bartosz Golaszewski
<bgolaszewski@baylibre.com> wrote:
> pon., 11 maj 2020 o 12:18 Geert Uytterhoeven <geert+renesas@glider.be>
> napisał(a):
> >
> > gpiochip_set_desc_names() no longer rejects GPIO line name collisions.
> > Hence GPIO line names are not guaranteed to be globally unique.
> > In case of multiple GPIO lines with the same name, gpio_name_to_desc()
> > will return the first match found.
(...)
> This makes me wonder whether I should do something about this in
> libgpiod? Looks to me like gpiod_chip_find_line() and the global
> gpiod_line_find() are no longer reliable and should probably return
> all lines whose names match.

Hm. You probably know how consumers of libgpiod work better than me.

The background is historical and this happens because gpiolib had a
mechanism to name lines before I even took over maintenance, and
that did not require line names to be unique. So
when I created the character device I had to face the fact.

We also had to deal with the fact that when naming lines, the
"NULL alternative" (no name on the line at all) is always a valid
fallback.

And all lines named NULL are still valid and all have the same name
so...

Yours,
Linus Walleij

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

end of thread, other threads:[~2020-05-16  9:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-11 10:18 [PATCH] gpiolib: Document that GPIO line names are not globally unique Geert Uytterhoeven
2020-05-12 10:43 ` Bartosz Golaszewski
2020-05-16  9:41   ` Linus Walleij
2020-05-16  9:37 ` 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).