Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 86256d1f authored by Geert Uytterhoeven's avatar Geert Uytterhoeven Committed by Linus Walleij
Browse files

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: default avatarGeert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: default avatarAlexandre Courbot <acourbot@nvidia.com>
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent a231b88c
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -227,8 +227,8 @@ int gpiochip_add(struct gpio_chip *chip)
	unsigned	id;
	unsigned	id;
	int		base = chip->base;
	int		base = chip->base;


	if ((!gpio_is_valid(base) || !gpio_is_valid(base + chip->ngpio - 1))
	if (base >= 0 &&
			&& base >= 0) {
	    (!gpio_is_valid(base) || !gpio_is_valid(base + chip->ngpio - 1))) {
		status = -EINVAL;
		status = -EINVAL;
		goto fail;
		goto fail;
	}
	}