[PATCH] gpiolib: Disallow identical line names in the same chip

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

I don't know what happens if we just apply this, I *hope* there
are not a lot of systems out there breaking this simple and
intuitive rule.

As a side effect, this makes the device tree naming code
scream a bit if names are not globally unique.

I think there are not super-many device trees out there naming
their lines so let's fix this before the problem becomes
widespread.

Cc: Geert Uytterhoeven <geert+renesas@xxxxxxxxx>
Cc: Johan Hovold <johan@xxxxxxxxxx>
Signed-off-by: Linus Walleij <linus.walleij@xxxxxxxxxx>
---
This may be just the first step in tightening this up.
Googling gives at hand that the colission warning doesn't
happen much so we might go as far as to say the name can
be required to be globally unique, but that creates a flat
namespace so I don't know if that is desireable.
---
 drivers/gpio/gpiolib.c | 34 ++++++++++++++++++++++++++--------
 1 file changed, 26 insertions(+), 8 deletions(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 5ce0c14c637b..be4b3e9032b2 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,19 @@ 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)
+		gpiod = gpio_name_to_desc(gc->names[i]);
+		if (gpiod) {
 			dev_warn(&gdev->dev,
 				 "Detected name collision for GPIO name '%s'\n",
 				 gc->names[i]);
+			if (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 -EINVAL;
+			}
+		}
 	}
 
 	/* Then add all names to the GPIO descriptors */
@@ -402,8 +406,22 @@ static int devprop_gpiochip_set_names(struct gpio_chip *chip)
 		return ret;
 	}
 
-	for (i = 0; i < count; i++)
+	for (i = 0; i < count; i++) {
+		struct gpio_desc *gpiod;
+
+		gpiod = gpio_name_to_desc(names[i]);
+		if (gpiod) {
+			dev_warn(&gdev->dev,
+                                 "Detected name collision for GPIO name '%s'\n",
+                                 names[i]);
+			if (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 -EINVAL;
+			}
+		}
 		gdev->descs[i].name = names[i];
+	}
 
 	kfree(names);
 
-- 
2.28.0




[Index of Archives]     [Linux SPI]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux