From: Geert Uytterhoeven Date: Mon, 17 Nov 2014 14:31:59 +0000 (+0100) Subject: gpio: Check if base is positive before calling gpio_is_valid() X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=86256d1fceff058d5afea6dfcc8a2eac18a71e95;p=GitHub%2FLineageOS%2FG12%2Fandroid_kernel_amlogic_linux-4.9.git gpio: Check if base is positive before calling gpio_is_valid() It doesn't make much sense to make some (possible expensive) calls to gpio_is_valid() first, and to ignore the result if the base number is negative. Check for a positive base number first. Signed-off-by: Geert Uytterhoeven Reviewed-by: Alexandre Courbot Signed-off-by: Linus Walleij --- diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index eb739a51e774..12d981a5be66 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -227,8 +227,8 @@ int gpiochip_add(struct gpio_chip *chip) unsigned id; int base = chip->base; - if ((!gpio_is_valid(base) || !gpio_is_valid(base + chip->ngpio - 1)) - && base >= 0) { + if (base >= 0 && + (!gpio_is_valid(base) || !gpio_is_valid(base + chip->ngpio - 1))) { status = -EINVAL; goto fail; }