Skip to contentSkip to conversation

gpiolib: don't compare an unsigned for >= 0

PATCH In review Dirk Behme 3 participants 5 messages Aug 18, 2015 – Oct 2, 2015 GPIO

lore
Share & tools
lore

Dirk Behme

author
#0 lore raw

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
index bf4bd1d..9841b05 100644
@@ -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
author
#1 lore raw
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_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 +0 -2
index bf4bd1d..9841b05 100644
@@ -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

#2 lore raw
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_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 +0 -2
index bf4bd1d..9841b05 100644
@@ -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.

author
#3 lore raw
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_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 +0 -2
index bf4bd1d..9841b05 100644
@@ -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

#4 lore raw
In reply to Dirk Behme
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_VALID is only used at this single place, simplify the code by dropping the macro completely and dropping the invert, too.

No functional change.

Patch applied with Alexandre's ACK.

Yours,
Linus Walleij