1
0
Fork 0

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 <geert+renesas@glider.be>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
hifive-unleashed-5.1
Geert Uytterhoeven 2014-11-17 15:31:59 +01:00 committed by Linus Walleij
parent a231b88cfc
commit 86256d1fce
1 changed files with 2 additions and 2 deletions

View File

@ -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;
}