All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] gpiolib: Disallow identical line names in the same chip
@ 2021-01-05  8:27 Linus Walleij
  2021-01-05 17:29 ` Andy Shevchenko
  0 siblings, 1 reply; 21+ messages in thread
From: Linus Walleij @ 2021-01-05  8:27 UTC (permalink / raw)
  To: linux-gpio
  Cc: Bartosz Golaszewski, Linus Walleij, Geert Uytterhoeven, Johan Hovold

We need to make this namespace hierarchical: at least do not
allow two lines on the same chip to have the same name, this
is just too much flexibility. If we name a line on a chip,
name it uniquely on that chip.

This does not affect device tree and other gpiochips that
get named from device properties: the uniqueness
per-chip however affect all hotplugged devices such as
GPIO expanders on USB.

Cc: Geert Uytterhoeven <geert+renesas@glider.be>
Cc: Johan Hovold <johan@kernel.org>
Link: https://lore.kernel.org/r/20201212003447.238474-1-linus.walleij@linaro.org
[Dropped warning for globally unique]
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
ChangeLog v1->v2:
- Do NOT enforce unique line names on device tree instances.
  Devicetrees know what they are doing and will make sure
  not to create conflicting naming.
---
 drivers/gpio/gpiolib.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index b02cc2abd3b6..8c0c8c5306d2 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -330,11 +330,9 @@ static struct gpio_desc *gpio_name_to_desc(const char * const name)
 
 /*
  * 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.
  *
- * Note that:
- *   1. Non-unique names are still accepted,
- *   2. Name collisions within the same GPIO chip are not reported.
+ * - Fail if a name is already used for a GPIO line on the same chip.
+ * - Allow names to not be globally unique but warn about it.
  */
 static int gpiochip_set_desc_names(struct gpio_chip *gc)
 {
@@ -343,13 +341,14 @@ static int gpiochip_set_desc_names(struct gpio_chip *gc)
 
 	/* First check all names if they are unique */
 	for (i = 0; i != gc->ngpio; ++i) {
-		struct gpio_desc *gpio;
+		struct gpio_desc *gpiod;
 
-		gpio = gpio_name_to_desc(gc->names[i]);
-		if (gpio)
-			dev_warn(&gdev->dev,
-				 "Detected name collision for GPIO name '%s'\n",
-				 gc->names[i]);
+		gpiod = gpio_name_to_desc(gc->names[i]);
+		if (gpiod && (gpiod->gdev == gdev)) {
+			dev_err(&gdev->dev,
+				"GPIO name collision on the same chip, this is not allowed, fix all lines on the chip to have unique names\n");
+			return -EEXIST;
+		}
 	}
 
 	/* Then add all names to the GPIO descriptors */
-- 
2.29.2


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

end of thread, other threads:[~2021-01-15 17:32 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-05  8:27 [PATCH v2] gpiolib: Disallow identical line names in the same chip Linus Walleij
2021-01-05 17:29 ` Andy Shevchenko
2021-01-05 23:23   ` Linus Walleij
2021-01-06 10:09     ` Bartosz Golaszewski
2021-01-06 13:34       ` Andy Shevchenko
2021-01-06 14:25         ` Bartosz Golaszewski
2021-01-06 16:14           ` Andy Shevchenko
2021-01-07 10:03         ` R: " Flavio Suligoi
2021-01-07 10:12           ` Andy Shevchenko
2021-01-07 13:12             ` R: " Flavio Suligoi
2021-01-08 10:40         ` Flavio Suligoi
2021-01-08 15:03           ` Andy Shevchenko
2021-01-07 10:45       ` Linus Walleij
2021-01-07 13:49         ` R: " Flavio Suligoi
2021-01-07 13:55           ` Geert Uytterhoeven
2021-01-08 14:39             ` R: " Flavio Suligoi
2021-01-08 14:41               ` Geert Uytterhoeven
2021-01-08 14:43                 ` R: " Flavio Suligoi
2021-01-08 15:05               ` Andy Shevchenko
2021-01-15 14:30                 ` Bartosz Golaszewski
     [not found]                   ` <CAHp75Vd017YY8HU-Ai7jnQEJ4PEgiU4VXn-jhLBKwERmsG_5MA@mail.gmail.com>
2021-01-15 17:31                     ` Geert Uytterhoeven

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.