Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1299856 > unrolled thread

[PATCH] gpio: check first for invalid gpio

Started bySudip Mukherjee <sudipm.mukherjee@gmail.com>
First post2016-01-01 09:40 +0100
Last post2016-01-01 09:40 +0100
Articles 1 — 1 participant

Back to article view | Back to linux.kernel


Contents

  [PATCH] gpio: check first for invalid gpio Sudip Mukherjee <sudipm.mukherjee@gmail.com> - 2016-01-01 09:40 +0100

#1299856 — [PATCH] gpio: check first for invalid gpio

FromSudip Mukherjee <sudipm.mukherjee@gmail.com>
Date2016-01-01 09:40 +0100
Subject[PATCH] gpio: check first for invalid gpio
Message-ID<qM3pE-7Uv-3@gated-at.bofh.it>
Even if an invalid gpio number is sent to gpio_to_desc() we try to find
it in the list before checking if it is invalid. We can check it first
so that it will save us from traversing the list incase of invalid gpio.

Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
---
 drivers/gpio/gpiolib.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index ca66302..17a1cd5 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -70,6 +70,11 @@ struct gpio_desc *gpio_to_desc(unsigned gpio)
 	struct gpio_chip *chip;
 	unsigned long flags;
 
+	if (!gpio_is_valid(gpio)) {
+		WARN(1, "invalid GPIO %d\n", gpio);
+		return NULL;
+	}
+
 	spin_lock_irqsave(&gpio_lock, flags);
 
 	list_for_each_entry(chip, &gpio_chips, list) {
@@ -81,9 +86,6 @@ struct gpio_desc *gpio_to_desc(unsigned gpio)
 
 	spin_unlock_irqrestore(&gpio_lock, flags);
 
-	if (!gpio_is_valid(gpio))
-		WARN(1, "invalid GPIO %d\n", gpio);
-
 	return NULL;
 }
 EXPORT_SYMBOL_GPL(gpio_to_desc);
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [standalone]


Back to top | Article view | linux.kernel


csiph-web