gpiolib: fix find_chip_by_name()
PATCH 1/1 gpiolib: fix find_chip_by_name()
find_chip_by_name() was incorrectly implemented by using gpio_lookup_list instead of gpiod_chips to iterate through all the registered GPIO controllers. This patch reimplements it by using gpiochip_find() with a custom search function, which simplifies the code on top of fixing the mistake.
Signed-off-by Alexandre Courbot <[email protected]>
--- drivers/gpio/gpiolib.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-)
drivers/gpio/gpiolib.c +12 -17
@@ -1307,6 +1307,18 @@ struct gpio_chip *gpiochip_find(void *data, }EXPORT_SYMBOL_GPL (gpiochip_find); +static int gpiochip_match_name (struct gpio_chip *chip,void *data) +{ +const char *name = data; + +return !strcmp (chip->label, name); +} + +static struct gpio_chip *find_chip_by_name (const char *name) +{ +return gpiochip_find ((void *)name, gpiochip_match_name); +} +#ifdef CONFIG_PINCTRL /**
@@ -2212,23 +2224,6 @@ void gpiod_add_table(struct gpiod_lookup *table, size_t size)mutex_unlock (&gpio_lookup_lock); } -/* -* Caller must have a acquired gpio_lookup_lock -*/ -static struct gpio_chip *find_chip_by_name (const char *name) -{ -struct gpio_chip *chip =NULL ; - -list_for_each_entry (chip, &gpio_lookup_list, list) { -if (chip->label ==NULL ) -continue ; -if (!strcmp (chip->label, name)) -break ; - } - -return chip; -} -#ifdef CONFIG_OF static struct gpio_desc *of_find_gpio (struct device *dev,const char *con_id,unsigned int idx,unsigned long *flags)
Signature · 1 line
1.8.4.2
Quoted 7 lines · Alexandre Courbot
find_chip_by_name()was incorrectly implemented by usinggpio_lookup_listinstead ofgpiod_chipsto iterate through all the registered GPIO controllers. This patch reimplements it by usinggpiochip_find()with a custom search function, which simplifies the code on top of fixing the mistake.Signed-off-by Alexandre Courbot <[email protected]>
Patch applied for fixes.
Yours,
Linus Walleij