···121121 struct xra1403 *xra = gpiochip_get_data(chip);122122 int value[XRA_LAST];123123 int i;124124+ const char *label;124125 unsigned int gcr;125126 unsigned int gsr;126127···137136138137 gcr = value[XRA_GCR + 1] << 8 | value[XRA_GCR];139138 gsr = value[XRA_GSR + 1] << 8 | value[XRA_GSR];140140- for (i = 0; i < chip->ngpio; i++) {141141- const char *label = gpiochip_is_requested(chip, i);142142-143143- if (!label)144144- continue;145145-139139+ for_each_requested_gpio(chip, i, label) {146140 seq_printf(s, " gpio-%-3d (%-12s) %s %s\n",147141 chip->base + i, label,148142 (gcr & BIT(i)) ? "in" : "out",
+2-5
drivers/pinctrl/pinctrl-at91.c
···14861486 int i;14871487 struct at91_gpio_chip *at91_gpio = gpiochip_get_data(chip);14881488 void __iomem *pio = at91_gpio->regbase;14891489+ const char *gpio_label;1489149014901490- for (i = 0; i < chip->ngpio; i++) {14911491+ for_each_requested_gpio(chip, i, gpio_label) {14911492 unsigned mask = pin_to_mask(i);14921492- const char *gpio_label;1493149314941494- gpio_label = gpiochip_is_requested(chip, i);14951495- if (!gpio_label)14961496- continue;14971494 mode = at91_gpio->ops->get_periph(pio, mask);14981495 seq_printf(s, "[%s] GPIO%s%d: ",14991496 gpio_label, chip->label, i);
+16
include/linux/gpio/driver.h
···474474extern const char *gpiochip_is_requested(struct gpio_chip *gc,475475 unsigned int offset);476476477477+/**478478+ * for_each_requested_gpio_in_range - iterates over requested GPIOs in a given range479479+ * @chip: the chip to query480480+ * @i: loop variable481481+ * @base: first GPIO in the range482482+ * @size: amount of GPIOs to check starting from @base483483+ * @label: label of current GPIO484484+ */485485+#define for_each_requested_gpio_in_range(chip, i, base, size, label) \486486+ for (i = 0; i < size; i++) \487487+ if ((label = gpiochip_is_requested(chip, base + i)) == NULL) {} else488488+489489+/* Iterates over all requested GPIO of the given @chip */490490+#define for_each_requested_gpio(chip, i, label) \491491+ for_each_requested_gpio_in_range(chip, i, 0, chip->ngpio, label)492492+477493/* add/remove chips */478494extern int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,479495 struct lock_class_key *lock_key,