Skip to content

Commit db54696

Browse files
author
Bartosz Golaszewski
committed
gpiolib: replace find_chip_by_name() with gpio_device_find_by_label()
Remove all remaining uses of find_chip_by_name() (and subsequently: gpiochip_find()) from gpiolib.c and use the new gpio_device_find_by_label() instead. Signed-off-by: Bartosz Golaszewski <[email protected]> Reviewed-by: Linus Walleij <[email protected]>
1 parent 9b41878 commit db54696

File tree

1 file changed

+11
-22
lines changed

1 file changed

+11
-22
lines changed

drivers/gpio/gpiolib.c

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,18 +1145,6 @@ struct gpio_device *gpio_device_find_by_label(const char *label)
11451145
}
11461146
EXPORT_SYMBOL_GPL(gpio_device_find_by_label);
11471147

1148-
static int gpiochip_match_name(struct gpio_chip *gc, void *data)
1149-
{
1150-
const char *name = data;
1151-
1152-
return !strcmp(gc->label, name);
1153-
}
1154-
1155-
static struct gpio_chip *find_chip_by_name(const char *name)
1156-
{
1157-
return gpiochip_find((void *)name, gpiochip_match_name);
1158-
}
1159-
11601148
/**
11611149
* gpio_device_get() - Increase the reference count of this GPIO device
11621150
* @gdev: GPIO device to increase the refcount for
@@ -3908,7 +3896,6 @@ EXPORT_SYMBOL_GPL(gpiod_remove_lookup_table);
39083896
*/
39093897
void gpiod_add_hogs(struct gpiod_hog *hogs)
39103898
{
3911-
struct gpio_chip *gc;
39123899
struct gpiod_hog *hog;
39133900

39143901
mutex_lock(&gpio_machine_hogs_mutex);
@@ -3920,9 +3907,10 @@ void gpiod_add_hogs(struct gpiod_hog *hogs)
39203907
* The chip may have been registered earlier, so check if it
39213908
* exists and, if so, try to hog the line now.
39223909
*/
3923-
gc = find_chip_by_name(hog->chip_label);
3924-
if (gc)
3925-
gpiochip_machine_hog(gc, hog);
3910+
struct gpio_device *gdev __free(gpio_device_put) =
3911+
gpio_device_find_by_label(hog->chip_label);
3912+
if (gdev)
3913+
gpiochip_machine_hog(gpio_device_get_chip(gdev), hog);
39263914
}
39273915

39283916
mutex_unlock(&gpio_machine_hogs_mutex);
@@ -3972,6 +3960,7 @@ static struct gpio_desc *gpiod_find(struct device *dev, const char *con_id,
39723960
struct gpio_desc *desc = ERR_PTR(-ENOENT);
39733961
struct gpiod_lookup_table *table;
39743962
struct gpiod_lookup *p;
3963+
struct gpio_chip *gc;
39753964

39763965
guard(mutex)(&gpio_lookup_lock);
39773966

@@ -3980,8 +3969,6 @@ static struct gpio_desc *gpiod_find(struct device *dev, const char *con_id,
39803969
return desc;
39813970

39823971
for (p = &table->table[0]; p->key; p++) {
3983-
struct gpio_chip *gc;
3984-
39853972
/* idx must always match exactly */
39863973
if (p->idx != idx)
39873974
continue;
@@ -4002,9 +3989,9 @@ static struct gpio_desc *gpiod_find(struct device *dev, const char *con_id,
40023989
return ERR_PTR(-EPROBE_DEFER);
40033990
}
40043991

4005-
gc = find_chip_by_name(p->key);
4006-
4007-
if (!gc) {
3992+
struct gpio_device *gdev __free(gpio_device_put) =
3993+
gpio_device_find_by_label(p->key);
3994+
if (!gdev) {
40083995
/*
40093996
* As the lookup table indicates a chip with
40103997
* p->key should exist, assume it may
@@ -4017,6 +4004,8 @@ static struct gpio_desc *gpiod_find(struct device *dev, const char *con_id,
40174004
return ERR_PTR(-EPROBE_DEFER);
40184005
}
40194006

4007+
gc = gpio_device_get_chip(gdev);
4008+
40204009
if (gc->ngpio <= p->chip_hwnum) {
40214010
dev_err(dev,
40224011
"requested GPIO %u (%u) is out of range [0..%u] for chip %s\n",
@@ -4025,7 +4014,7 @@ static struct gpio_desc *gpiod_find(struct device *dev, const char *con_id,
40254014
return ERR_PTR(-EINVAL);
40264015
}
40274016

4028-
desc = gpiochip_get_desc(gc, p->chip_hwnum);
4017+
desc = gpio_device_get_desc(gdev, p->chip_hwnum);
40294018
*flags = p->flags;
40304019

40314020
return desc;

0 commit comments

Comments
 (0)