Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

gpio: keep the GPIO line names internal

This refactors the changes to the GPIO line naming mechanism to
not have so widespread effects, instead we conclude the patch series
by having created a name attribute in the GPIO descriptor, that need
not be globally unique, and it will be initialized from the old
.names array in struct gpio_chip if it exists, then used in the legacy
sysfs code like the array was used previously.

The associated changes to name lines from the device tree are
controversial and need to stand alone from this. Resulting changes:

1. Remove the export and the header for the gpio_name_to_desc() as so
far the only use is inside gpiolib.c. Staticize gpio_name_to_desc()
and move it above the only function using it.

2. Only print a warning if there are two GPIO lines with the same name.
The reason is to preserve current behaviour: before the previous
changes to the naming mechanism this would not reject probing the
driver, instead the error would occur when trying to export the line
in sysfs, so restore this behaviour, but print a friendly warning
if names collide.

Cc: Johan Hovold <johan@kernel.org>
Cc: Markus Pargmann <mpa@pengutronix.de>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

+35 -43
+35 -37
drivers/gpio/gpiolib.c
··· 90 90 EXPORT_SYMBOL_GPL(gpio_to_desc); 91 91 92 92 /** 93 - * Convert a GPIO name to its descriptor 94 - */ 95 - struct gpio_desc *gpio_name_to_desc(const char * const name) 96 - { 97 - struct gpio_chip *chip; 98 - unsigned long flags; 99 - 100 - spin_lock_irqsave(&gpio_lock, flags); 101 - 102 - list_for_each_entry(chip, &gpio_chips, list) { 103 - int i; 104 - 105 - for (i = 0; i != chip->ngpio; ++i) { 106 - struct gpio_desc *gpio = &chip->desc[i]; 107 - 108 - if (!gpio->name) 109 - continue; 110 - 111 - if (!strcmp(gpio->name, name)) { 112 - spin_unlock_irqrestore(&gpio_lock, flags); 113 - return gpio; 114 - } 115 - } 116 - } 117 - 118 - spin_unlock_irqrestore(&gpio_lock, flags); 119 - 120 - return NULL; 121 - } 122 - EXPORT_SYMBOL_GPL(gpio_name_to_desc); 123 - 124 - /** 125 93 * Get the GPIO descriptor corresponding to the given hw number for this chip. 126 94 */ 127 95 struct gpio_desc *gpiochip_get_desc(struct gpio_chip *chip, ··· 218 250 return err; 219 251 } 220 252 253 + /** 254 + * Convert a GPIO name to its descriptor 255 + */ 256 + static struct gpio_desc *gpio_name_to_desc(const char * const name) 257 + { 258 + struct gpio_chip *chip; 259 + unsigned long flags; 260 + 261 + spin_lock_irqsave(&gpio_lock, flags); 262 + 263 + list_for_each_entry(chip, &gpio_chips, list) { 264 + int i; 265 + 266 + for (i = 0; i != chip->ngpio; ++i) { 267 + struct gpio_desc *gpio = &chip->desc[i]; 268 + 269 + if (!gpio->name) 270 + continue; 271 + 272 + if (!strcmp(gpio->name, name)) { 273 + spin_unlock_irqrestore(&gpio_lock, flags); 274 + return gpio; 275 + } 276 + } 277 + } 278 + 279 + spin_unlock_irqrestore(&gpio_lock, flags); 280 + 281 + return NULL; 282 + } 283 + 221 284 /* 222 285 * Takes the names from gc->names and checks if they are all unique. If they 223 286 * are, they are assigned to their gpio descriptors. ··· 267 268 struct gpio_desc *gpio; 268 269 269 270 gpio = gpio_name_to_desc(gc->names[i]); 270 - if (gpio) { 271 - dev_err(gc->dev, "Detected name collision for GPIO name '%s'\n", 272 - gc->names[i]); 273 - return -EEXIST; 274 - } 271 + if (gpio) 272 + dev_warn(gc->dev, "Detected name collision for " 273 + "GPIO name '%s'\n", 274 + gc->names[i]); 275 275 } 276 276 277 277 /* Then add all names to the GPIO descriptors */
-6
include/linux/gpio/consumer.h
··· 130 130 /* Convert between the old gpio_ and new gpiod_ interfaces */ 131 131 struct gpio_desc *gpio_to_desc(unsigned gpio); 132 132 int desc_to_gpio(const struct gpio_desc *desc); 133 - struct gpio_desc *gpio_name_to_desc(const char *name); 134 133 135 134 /* Child properties interface */ 136 135 struct fwnode_handle; ··· 397 398 } 398 399 399 400 static inline struct gpio_desc *gpio_to_desc(unsigned gpio) 400 - { 401 - return ERR_PTR(-EINVAL); 402 - } 403 - 404 - static inline struct gpio_desc *gpio_name_to_desc(const char *name) 405 401 { 406 402 return ERR_PTR(-EINVAL); 407 403 }