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@xxxxxxxxx> Cc: Johan Hovold <johan@xxxxxxxxxx> Link: https://lore.kernel.org/r/20201212003447.238474-1-linus.walleij@xxxxxxxxxx [Dropped warning for globally unique] Signed-off-by: Linus Walleij <linus.walleij@xxxxxxxxxx> --- 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