gpiolib: don't compare an unsigned for >= 0
PATCH 1/1 gpiolib: don't compare an unsigned for >= 0
The parameter offset is an unsigned, so it makes no sense to compare it for >= 0. Fix the compiler warning regarding this by removing this comparison.
As the macro GPIO_OFFSET_VALID is only used at this single place, simplify the code by dropping the macro completely and dropping the invert, too.
No functional change.
--- drivers/gpio/gpiolib.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/gpio/gpiolib.c +1 -3
@@ -47,8 +47,6 @@*/ DEFINE_SPINLOCK (gpio_lock); -#define GPIO_OFFSET_VALID (chip, offset) (offset >= 0 && offset < chip->ngpio) -static DEFINE_MUTEX (gpio_lookup_lock);static LIST_HEAD (gpio_lookup_list);LIST_HEAD (gpio_chips);
@@ -914,7 +912,7 @@ const char *gpiochip_is_requested(struct gpio_chip *chip, unsigned offset) {struct gpio_desc *desc; -if (!GPIO_OFFSET_VALID (chip, offset)) +if (offset >= chip->ngpio)return NULL ; desc = &chip->desc[offset];
Signature · 1 line
2.5.0
Quoted 28 lines · Dirk Behme
The parameter offset is an unsigned, so it makes no sense to compare it for >= 0. Fix the compiler warning regarding this by removing this comparison.
As the macro
GPIO_OFFSET_VALIDis only used at this single place, simplify the code by dropping the macro completely and dropping the invert, too.No functional change.
Signed-off-by Dirk Behme <[email protected]>--- drivers/gpio/gpiolib.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)drivers/gpio/gpiolib.c +0
-2@@ -47,8 +47,6 @@*/ DEFINE_SPINLOCK (gpio_lock); -#define GPIO_OFFSET_VALID (chip, offset) (offset >= 0 && offset < chip->ngpio) -static DEFINE_MUTEX (gpio_lookup_lock);static LIST_HEAD (gpio_lookup_list);LIST_HEAD (gpio_chips);
drivers/gpio/gpiolib.c const char *gpiochip_is_requested(struct gpio_chip *chip, unsigned offset) · line 918
Quoted 8 lines
drivers/gpio/gpiolib.c +1
-1@@ -914,7 +912,7 @@ const char *gpiochip_is_requested(struct gpio_chip *chip, unsigned offset) {struct gpio_desc *desc; -if (!GPIO_OFFSET_VALID (chip, offset)) +if (offset >= chip->ngpio)return NULL ; desc = &chip->desc[offset];
What do you think about this? Could this be applied?
Best regards
Dirk
Alexandre Courbot
Acked-byQuoted 39 lines · Dirk Behme
Quoted 38 lines · Dirk Behme
The parameter offset is an unsigned, so it makes no sense to compare it for >= 0. Fix the compiler warning regarding this by removing this comparison.
As the macro
GPIO_OFFSET_VALIDis only used at this single place, simplify the code by dropping the macro completely and dropping the invert, too.No functional change.
Signed-off-by Dirk Behme <[email protected]>--- drivers/gpio/gpiolib.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)drivers/gpio/gpiolib.c +0
-2@@ -47,8 +47,6 @@*/ DEFINE_SPINLOCK (gpio_lock); -#define GPIO_OFFSET_VALID (chip, offset) (offset >= 0 && offset < chip->ngpio) -static DEFINE_MUTEX (gpio_lookup_lock);static LIST_HEAD (gpio_lookup_list);LIST_HEAD(gpio_chips);drivers/gpio/gpiolib.c +1
-1@@ -914,7 +912,7 @@ const char *gpiochip_is_requested(struct gpio_chip *chip, unsigned offset) {struct gpio_desc *desc; -if (!GPIO_OFFSET_VALID (chip, offset)) +if (offset >= chip->ngpio)return NULL ;
Quoted 5 lines
Quoted 1 line
desc = &chip->desc[offset];What do you think about this? Could this be applied?
Looks good to me.
Quoted 46 lines · Alexandre Courbot
Quoted 39 lines · Dirk Behme
Quoted 38 lines · Dirk Behme
The parameter offset is an unsigned, so it makes no sense to compare it for >= 0. Fix the compiler warning regarding this by removing this comparison.
As the macro
GPIO_OFFSET_VALIDis only used at this single place, simplify the code by dropping the macro completely and dropping the invert, too.No functional change.
Signed-off-by Dirk Behme <[email protected]>--- drivers/gpio/gpiolib.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)drivers/gpio/gpiolib.c +0
-2@@ -47,8 +47,6 @@*/ DEFINE_SPINLOCK (gpio_lock); -#define GPIO_OFFSET_VALID (chip, offset) (offset >= 0 && offset < chip->ngpio) -static DEFINE_MUTEX (gpio_lookup_lock);static LIST_HEAD (gpio_lookup_list);LIST_HEAD(gpio_chips);drivers/gpio/gpiolib.c +1
-1@@ -914,7 +912,7 @@ const char *gpiochip_is_requested(struct gpio_chip *chip, unsigned offset) {struct gpio_desc *desc; -if (!GPIO_OFFSET_VALID (chip, offset)) +if (offset >= chip->ngpio)return NULL ;Quoted 5 lines
Quoted 1 line
desc = &chip->desc[offset];What do you think about this? Could this be applied?
Quoted 3 lines
Looks good to me.
Ping, could this be applied, then?
Best regards
Dirk
Quoted 10 lines · Dirk Behme
The parameter offset is an unsigned, so it makes no sense to compare it for >= 0. Fix the compiler warning regarding this by removing this comparison.
As the macro
GPIO_OFFSET_VALIDis only used at this single place, simplify the code by dropping the macro completely and dropping the invert, too.No functional change.
Signed-off-by Dirk Behme <[email protected]>
Patch applied with Alexandre's ACK.
Yours,
Linus Walleij