gpio: Remove VLA from stmpe driver
The new challenge is to remove VLAs from the kernel (see https://lkml.org/lkml/2018/3/7/621) The number of GPIOs on the supported chips is fairly small so stack allocate to a known upper bound and spit out a warning if any new chips have more gpios. Signed-off-by: Laura Abbott <labbott@redhat.com> Reviewed-by: Phil Reid <preid@electromag.com.au> Reviewed-by: Kees Cook <keescook@chromium.org> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
This commit is contained in:
parent
014e420d8a
commit
97fe7bef56
|
@ -363,13 +363,15 @@ static struct irq_chip stmpe_gpio_irq_chip = {
|
||||||
.irq_set_type = stmpe_gpio_irq_set_type,
|
.irq_set_type = stmpe_gpio_irq_set_type,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define MAX_GPIOS 24
|
||||||
|
|
||||||
static irqreturn_t stmpe_gpio_irq(int irq, void *dev)
|
static irqreturn_t stmpe_gpio_irq(int irq, void *dev)
|
||||||
{
|
{
|
||||||
struct stmpe_gpio *stmpe_gpio = dev;
|
struct stmpe_gpio *stmpe_gpio = dev;
|
||||||
struct stmpe *stmpe = stmpe_gpio->stmpe;
|
struct stmpe *stmpe = stmpe_gpio->stmpe;
|
||||||
u8 statmsbreg;
|
u8 statmsbreg;
|
||||||
int num_banks = DIV_ROUND_UP(stmpe->num_gpios, 8);
|
int num_banks = DIV_ROUND_UP(stmpe->num_gpios, 8);
|
||||||
u8 status[num_banks];
|
u8 status[DIV_ROUND_UP(MAX_GPIOS, 8)];
|
||||||
int ret;
|
int ret;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
@ -434,6 +436,11 @@ static int stmpe_gpio_probe(struct platform_device *pdev)
|
||||||
struct stmpe_gpio *stmpe_gpio;
|
struct stmpe_gpio *stmpe_gpio;
|
||||||
int ret, irq;
|
int ret, irq;
|
||||||
|
|
||||||
|
if (stmpe->num_gpios > MAX_GPIOS) {
|
||||||
|
dev_err(&pdev->dev, "Need to increase maximum GPIO number\n");
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
stmpe_gpio = kzalloc(sizeof(*stmpe_gpio), GFP_KERNEL);
|
stmpe_gpio = kzalloc(sizeof(*stmpe_gpio), GFP_KERNEL);
|
||||||
if (!stmpe_gpio)
|
if (!stmpe_gpio)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
Loading…
Reference in New Issue