]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/commitdiff
gpiolib: do not allow to insert an empty gpiochip
authorBamvor Jian Zhang <bamvor.zhangjian@linaro.org>
Mon, 16 Nov 2015 05:02:47 +0000 (13:02 +0800)
committerLinus Walleij <linus.walleij@linaro.org>
Thu, 19 Nov 2015 08:24:40 +0000 (09:24 +0100)
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>
drivers/gpio/gpiolib.c

index eed70c36e8ac6eb266eefe85a1b72d1a0e02ca4c..89e01538e40ee845176460539551f2992b05eece 100644 (file)
@@ -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) {