From 5ed41cc4baaf4127661d2a8f8f2ee6e3085e0fa9 Mon Sep 17 00:00:00 2001 From: Bamvor Jian Zhang Date: Mon, 16 Nov 2015 13:02:47 +0800 Subject: [PATCH] gpiolib: do not allow to insert an empty gpiochip We need to check if number of gpio is positive if there is no such check in devicetree or acpi or whatever called before gpiochip_add. I suppose that devicetree and acpi do not allow insert gpiochip with zero number but I do not know if it is enough to ignore this check in gpiochip_add. Signed-off-by: Bamvor Jian Zhang Signed-off-by: Linus Walleij --- drivers/gpio/gpiolib.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index eed70c36e8ac..89e01538e40e 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -325,6 +325,11 @@ int gpiochip_add(struct gpio_chip *chip) if (!descs) return -ENOMEM; + if (chip->ngpio == 0) { + chip_err(chip, "tried to insert a GPIO chip with zero lines\n"); + return -EINVAL; + } + spin_lock_irqsave(&gpio_lock, flags); if (base < 0) { -- 2.20.1