Commit 80c78fbe authored by Andy Shevchenko's avatar Andy Shevchenko Committed by Bartosz Golaszewski

gpiolib: Introduce for_each_gpio_desc_with_flag() macro

In a few places we are using a loop against all GPIO descriptors
with a given flag for a given device. Replace it with a consolidated
for_each type of macro.
Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Signed-off-by: default avatarBartosz Golaszewski <brgl@bgdev.pl>
parent 0868ad38
...@@ -711,14 +711,12 @@ static int of_gpiochip_scan_gpios(struct gpio_chip *chip) ...@@ -711,14 +711,12 @@ static int of_gpiochip_scan_gpios(struct gpio_chip *chip)
static void of_gpiochip_remove_hog(struct gpio_chip *chip, static void of_gpiochip_remove_hog(struct gpio_chip *chip,
struct device_node *hog) struct device_node *hog)
{ {
struct gpio_desc *descs = chip->gpiodev->descs; struct gpio_desc *desc;
unsigned int i; unsigned int i;
for (i = 0; i < chip->ngpio; i++) { for_each_gpio_desc_with_flag(i, chip, desc, FLAG_IS_HOGGED)
if (test_bit(FLAG_IS_HOGGED, &descs[i].flags) && if (desc->hog == hog)
descs[i].hog == hog) gpiochip_free_own_desc(desc);
gpiochip_free_own_desc(&descs[i]);
}
} }
static int of_gpiochip_match_node(struct gpio_chip *chip, void *data) static int of_gpiochip_match_node(struct gpio_chip *chip, void *data)
......
...@@ -793,11 +793,8 @@ void gpiochip_sysfs_unregister(struct gpio_device *gdev) ...@@ -793,11 +793,8 @@ void gpiochip_sysfs_unregister(struct gpio_device *gdev)
mutex_unlock(&sysfs_lock); mutex_unlock(&sysfs_lock);
/* unregister gpiod class devices owned by sysfs */ /* unregister gpiod class devices owned by sysfs */
for (i = 0; i < chip->ngpio; i++) { for_each_gpio_desc_with_flag(i, chip, desc, FLAG_SYSFS)
desc = &gdev->descs[i];
if (test_and_clear_bit(FLAG_SYSFS, &desc->flags))
gpiod_free(desc); gpiod_free(desc);
}
} }
static int __init gpiolib_sysfs_init(void) static int __init gpiolib_sysfs_init(void)
......
...@@ -4102,12 +4102,11 @@ int gpiod_hog(struct gpio_desc *desc, const char *name, ...@@ -4102,12 +4102,11 @@ int gpiod_hog(struct gpio_desc *desc, const char *name,
*/ */
static void gpiochip_free_hogs(struct gpio_chip *gc) static void gpiochip_free_hogs(struct gpio_chip *gc)
{ {
struct gpio_desc *desc;
int id; int id;
for (id = 0; id < gc->ngpio; id++) { for_each_gpio_desc_with_flag(id, gc, desc, FLAG_IS_HOGGED)
if (test_bit(FLAG_IS_HOGGED, &gc->gpiodev->descs[id].flags)) gpiochip_free_own_desc(desc);
gpiochip_free_own_desc(&gc->gpiodev->descs[id]);
}
} }
/** /**
......
...@@ -82,6 +82,13 @@ struct gpio_array { ...@@ -82,6 +82,13 @@ struct gpio_array {
}; };
struct gpio_desc *gpiochip_get_desc(struct gpio_chip *gc, unsigned int hwnum); struct gpio_desc *gpiochip_get_desc(struct gpio_chip *gc, unsigned int hwnum);
#define for_each_gpio_desc_with_flag(i, gc, desc, flag) \
for (i = 0, desc = gpiochip_get_desc(gc, i); \
i < gc->ngpio; \
i++, desc = gpiochip_get_desc(gc, i)) \
if (!test_bit(flag, &desc->flags)) {} else
int gpiod_get_array_value_complex(bool raw, bool can_sleep, int gpiod_get_array_value_complex(bool raw, bool can_sleep,
unsigned int array_size, unsigned int array_size,
struct gpio_desc **desc_array, struct gpio_desc **desc_array,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment