Message ID | 1447490336-10209-3-git-send-email-bamvor.zhangjian@linaro.org |
---|---|
State | New |
Headers | show |
On Sat, Nov 14, 2015 at 9:38 AM, Bamvor Jian Zhang <bamvor.zhangjian@linaro.org> wrote: > 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> > + if (chip->ngpio == 0) > + return -EINVAL; Print a warning with chip_err(chip, "tried to insert a GPIO chip with zero lines\n"); Yours, Linus Walleij -- To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index cc135d9..868ff15 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -327,6 +327,9 @@ int gpiochip_add(struct gpio_chip *chip) if (!descs) return -ENOMEM; + if (chip->ngpio == 0) + return -EINVAL; + spin_lock_irqsave(&gpio_lock, flags); if (base < 0) {
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> --- drivers/gpio/gpiolib.c | 3 +++ 1 file changed, 3 insertions(+) -- 2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html