diff options
author | Stephen Boyd <swboyd@chromium.org> | 2018-03-23 12:34:50 -0400 |
---|---|---|
committer | Linus Walleij <linus.walleij@linaro.org> | 2018-03-27 09:34:07 -0400 |
commit | e4371f6e079294369ecb4cfa03aaeb60831e8b91 (patch) | |
tree | 8ee1a67f3f0f91859b1b9a5335ec5464fc71e59e | |
parent | b9c725ed73b7cecc7c9bc4b752ab3eb975ef9330 (diff) |
gpiolib: Extract mask allocation into subroutine
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@chromium.org>
Tested-by: Timur Tabi <timur@codeaurora.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
-rw-r--r-- | drivers/gpio/gpiolib.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index d66de67ef307..cc0e1519da45 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c | |||
@@ -337,6 +337,20 @@ static int gpiochip_set_desc_names(struct gpio_chip *gc) | |||
337 | return 0; | 337 | return 0; |
338 | } | 338 | } |
339 | 339 | ||
340 | static unsigned long *gpiochip_allocate_mask(struct gpio_chip *chip) | ||
341 | { | ||
342 | unsigned long *p; | ||
343 | |||
344 | p = kcalloc(BITS_TO_LONGS(chip->ngpio), sizeof(long), GFP_KERNEL); | ||
345 | if (!p) | ||
346 | return NULL; | ||
347 | |||
348 | /* Assume by default all GPIOs are valid */ | ||
349 | bitmap_fill(p, chip->ngpio); | ||
350 | |||
351 | return p; | ||
352 | } | ||
353 | |||
340 | /* | 354 | /* |
341 | * GPIO line handle management | 355 | * GPIO line handle management |
342 | */ | 356 | */ |
@@ -1506,14 +1520,10 @@ static int gpiochip_irqchip_init_valid_mask(struct gpio_chip *gpiochip) | |||
1506 | if (!gpiochip->irq.need_valid_mask) | 1520 | if (!gpiochip->irq.need_valid_mask) |
1507 | return 0; | 1521 | return 0; |
1508 | 1522 | ||
1509 | gpiochip->irq.valid_mask = kcalloc(BITS_TO_LONGS(gpiochip->ngpio), | 1523 | gpiochip->irq.valid_mask = gpiochip_allocate_mask(gpiochip); |
1510 | sizeof(long), GFP_KERNEL); | ||
1511 | if (!gpiochip->irq.valid_mask) | 1524 | if (!gpiochip->irq.valid_mask) |
1512 | return -ENOMEM; | 1525 | return -ENOMEM; |
1513 | 1526 | ||
1514 | /* Assume by default all GPIOs are valid */ | ||
1515 | bitmap_fill(gpiochip->irq.valid_mask, gpiochip->ngpio); | ||
1516 | |||
1517 | return 0; | 1527 | return 0; |
1518 | } | 1528 | } |
1519 | 1529 | ||