Skip to content

Commit

Permalink
gpiolib: fix find_chip_by_name()
Browse files Browse the repository at this point in the history
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 <acourbot@nvidia.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
  • Loading branch information
Alexandre Courbot authored and Linus Walleij committed Nov 25, 2013
1 parent fd8e198 commit 79697ef
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions drivers/gpio/gpiolib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1308,6 +1308,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

/**
Expand Down Expand Up @@ -2260,23 +2272,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)
Expand Down

0 comments on commit 79697ef

Please sign in to comment.