diff mbox

gpio: Check if base is positive before calling gpio_is_valid()

Message ID 1416234719-16310-1-git-send-email-geert+renesas@glider.be
State Accepted
Headers show

Commit Message

Geert Uytterhoeven Nov. 17, 2014, 2:31 p.m. UTC
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>
---
 drivers/gpio/gpiolib.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Alexandre Courbot Nov. 18, 2014, 3:06 a.m. UTC | #1
On Mon, Nov 17, 2014 at 11:31 PM, Geert Uytterhoeven
<geert+renesas@glider.be> wrote:
> 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.

Sure.

Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
--
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 mbox

Patch

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 2e3d66adc6880950..bdf2020e103c7bc0 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;
 	}