Skip to content

Commit

Permalink
gpio: Convert gpio_is_valid to return bool
Browse files Browse the repository at this point in the history
Make the code a bit more readable.

Instead of casting an int to an unsigned then comparing to
MAX_NR_GPIOS, add a >= 0 test and let the compiler optimizer
do the conversion to unsigned.

The generated code should be the same.

Signed-off-by: Joe Perches <joe@perches.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
  • Loading branch information
Joe Perches authored and Grant Likely committed May 27, 2011
1 parent 82ab0f7 commit 3474cb3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions include/asm-generic/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
* platform data and other tables.
*/

static inline int gpio_is_valid(int number)
static inline bool gpio_is_valid(int number)
{
return ((unsigned)number) < ARCH_NR_GPIOS;
return number >= 0 && number < ARCH_NR_GPIOS;
}

struct device;
Expand Down Expand Up @@ -212,7 +212,7 @@ extern void gpio_unexport(unsigned gpio);

#else /* !CONFIG_GPIOLIB */

static inline int gpio_is_valid(int number)
static inline bool gpio_is_valid(int number)
{
/* only non-negative numbers are valid */
return number >= 0;
Expand Down
4 changes: 2 additions & 2 deletions include/linux/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ struct gpio_chip;
* warning when something is wrongly called.
*/

static inline int gpio_is_valid(int number)
static inline bool gpio_is_valid(int number)
{
return 0;
return false;
}

static inline int gpio_request(unsigned gpio, const char *label)
Expand Down

0 comments on commit 3474cb3

Please sign in to comment.