[cip-dev] [PATCH v2 18/52] gpiolib: Extract mask allocation into subroutine

Fabrizio Castro fabrizio.castro at bp.renesas.com
Thu May 16 09:39:30 UTC 2019

From: Stephen Boyd <swboyd at chromium.org>

commit e4371f6e079294369ecb4cfa03aaeb60831e8b91 upstream.

We're going to use similar code to allocate and set all the bits in a
mask for valid gpios to use. Extract the code from the irqchip version
so it can be reused.

Signed-off-by: Stephen Boyd <swboyd at chromium.org>
Tested-by: Timur Tabi <timur at codeaurora.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko at linux.intel.com>
Signed-off-by: Linus Walleij <linus.walleij at linaro.org>
[fab: removed change from function gpiochip_irqchip_init_valid_mask,
reworked return from gpiochip_allocate_mask]
Signed-off-by: Fabrizio Castro <fabrizio.castro at bp.renesas.com>

* Reworked return from gpiochip_allocate_mask according to Pavel's
 drivers/gpio/gpiolib.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 827510d..adb4740 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -279,6 +279,19 @@ static int gpiochip_set_desc_names(struct gpio_chip *gc)
 	return 0;
+static unsigned long *gpiochip_allocate_mask(struct gpio_chip *chip)
+	unsigned long *p;
+	p = kcalloc(BITS_TO_LONGS(chip->ngpio), sizeof(long), GFP_KERNEL);
+	if (p)
+		/* Assume by default all GPIOs are valid */
+		bitmap_fill(p, chip->ngpio);
+	return p;
  * gpiochip_add_data() - register a gpio_chip
  * @chip: the chip to register, with chip->base initialized

More information about the cip-dev mailing list