Skip to content

Commit

Permalink
gpiolib: Extract mask allocation into subroutine
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Stephen Boyd authored and Linus Walleij committed Mar 27, 2018
1 parent b9c725e commit e4371f6
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions drivers/gpio/gpiolib.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,20 @@ 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)
return NULL;

/* Assume by default all GPIOs are valid */
bitmap_fill(p, chip->ngpio);

return p;
}

/*
* GPIO line handle management
*/
Expand Down Expand Up @@ -1506,14 +1520,10 @@ static int gpiochip_irqchip_init_valid_mask(struct gpio_chip *gpiochip)
if (!gpiochip->irq.need_valid_mask)
return 0;

gpiochip->irq.valid_mask = kcalloc(BITS_TO_LONGS(gpiochip->ngpio),
sizeof(long), GFP_KERNEL);
gpiochip->irq.valid_mask = gpiochip_allocate_mask(gpiochip);
if (!gpiochip->irq.valid_mask)
return -ENOMEM;

/* Assume by default all GPIOs are valid */
bitmap_fill(gpiochip->irq.valid_mask, gpiochip->ngpio);

return 0;
}

Expand Down

0 comments on commit e4371f6

Please sign in to comment.