summaryrefslogtreecommitdiff
path: root/drivers/gpio/gpiolib.c
diff options
context:
space:
mode:
authorBamvor Jian Zhang <bamvor.zhangjian@linaro.org>2015-11-16 05:02:47 (GMT)
committerLinus Walleij <linus.walleij@linaro.org>2015-11-19 08:24:40 (GMT)
commit5ed41cc4baaf4127661d2a8f8f2ee6e3085e0fa9 (patch)
treecde0d7d31e4deab80a6def316ba661ef3873a0f2 /drivers/gpio/gpiolib.c
parentef7c7553039b3d1c847b38b0f1ea208f8d5d8370 (diff)
downloadlinux-5ed41cc4baaf4127661d2a8f8f2ee6e3085e0fa9.tar.xz
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 <bamvor.zhangjian@linaro.org> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/gpio/gpiolib.c')
-rw-r--r--drivers/gpio/gpiolib.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index eed70c3..89e0153 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) {