Skip to contentSkip to conversation

gpio: gpiolib: set gpiochip_remove retval to void

PATCH In review abdoulaye berthe 2 participants 5 messages May 23, 2014 – May 25, 2014 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpio: gpiolib: set gpiochip_remove retval to void

This avoids handling gpiochip remove error in device remove handler.

---
 drivers/gpio/gpiolib.c      | 24 +++++++-----------------
 include/linux/gpio/driver.h |  2 +-
 2 files changed, 8 insertions(+), 18 deletions(-)
drivers/gpio/gpiolib.c +7 -17
index f48817d..4878980 100644
@@ -1263,10 +1263,9 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip);
  *
  * A gpio_chip with any GPIOs still requested may not be removed.
  */
-int gpiochip_remove(struct gpio_chip *chip)
+void gpiochip_remove(struct gpio_chip *chip)
 {
 	unsigned long	flags;
-	int		status = 0;
 	unsigned	id;
 
 	acpi_gpiochip_remove(chip);
@@ -1278,24 +1277,15 @@ int gpiochip_remove(struct gpio_chip *chip)
 	of_gpiochip_remove(chip);
 
 	for (id = 0; id < chip->ngpio; id++) {
-		if (test_bit(FLAG_REQUESTED, &chip->desc[id].flags)) {
-			status = -EBUSY;
-			break;
-		}
-	}
-	if (status == 0) {
-		for (id = 0; id < chip->ngpio; id++)
-			chip->desc[id].chip = NULL;
-
-		list_del(&chip->list);
+		if (test_bit(FLAG_REQUESTED, &chip->desc[id].flags))
+			panic("gpiolib.c: gpiochip is still requested\n");
 	}
+	for (id = 0; id < chip->ngpio; id++)
+		chip->desc[id].chip = NULL;
 
+	list_del(&chip->list);
 	spin_unlock_irqrestore(&gpio_lock, flags);
-
-	if (status == 0)
-		gpiochip_unexport(chip);
-
-	return status;
+	gpiochip_unexport(chip);
 }
 EXPORT_SYMBOL_GPL(gpiochip_remove);
 
include/linux/gpio/driver.h +1 -1
index 1827b43..72ed256 100644
@@ -138,7 +138,7 @@ extern const char *gpiochip_is_requested(struct gpio_chip *chip,
 
 /* add/remove chips */
 extern int gpiochip_add(struct gpio_chip *chip);
-extern int __must_check gpiochip_remove(struct gpio_chip *chip);
+void gpiochip_remove(struct gpio_chip *chip);
 extern struct gpio_chip *gpiochip_find(void *data,
 			      int (*match)(struct gpio_chip *chip, void *data));
 
Signature · 1 line
1.8.3.2
#1 lore raw

If this step is ok I will continue by updating the codes that use it.

Quoted 72 lines · abdoulaye berthe

This avoids handling gpiochip remove error in device remove handler.

---
 drivers/gpio/gpiolib.c      | 24 +++++++-----------------
 include/linux/gpio/driver.h |  2 +-
 2 files changed, 8 insertions(+), 18 deletions(-)
drivers/gpio/gpiolib.c +7 -17
index f48817d..4878980 100644
@@ -1263,10 +1263,9 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip);
  *
  * A gpio_chip with any GPIOs still requested may not be removed.
  */
-int gpiochip_remove(struct gpio_chip *chip)
+void gpiochip_remove(struct gpio_chip *chip)
 {
        unsigned long   flags;
-       int             status = 0;
        unsigned        id;
 
        acpi_gpiochip_remove(chip);
@@ -1278,24 +1277,15 @@ int gpiochip_remove(struct gpio_chip *chip)
        of_gpiochip_remove(chip);
 
        for (id = 0; id < chip->ngpio; id++) {
-               if (test_bit(FLAG_REQUESTED, &chip->desc[id].flags)) {
-                       status = -EBUSY;
-                       break;
-               }
-       }
-       if (status == 0) {
-               for (id = 0; id < chip->ngpio; id++)
-                       chip->desc[id].chip = NULL;
-
-               list_del(&chip->list);
+               if (test_bit(FLAG_REQUESTED, &chip->desc[id].flags))
+                       panic("gpiolib.c: gpiochip is still requested\n");
        }
+       for (id = 0; id < chip->ngpio; id++)
+               chip->desc[id].chip = NULL;
 
+       list_del(&chip->list);
        spin_unlock_irqrestore(&gpio_lock, flags);
-
-       if (status == 0)
-               gpiochip_unexport(chip);
-
-       return status;
+       gpiochip_unexport(chip);
 }
 EXPORT_SYMBOL_GPL(gpiochip_remove);
 
include/linux/gpio/driver.h +1 -2
index 1827b43..72ed256 100644
@@ -138,7 +138,7 @@ extern const char *gpiochip_is_requested(struct gpio_chip *chip,
 
 /* add/remove chips */
 extern int gpiochip_add(struct gpio_chip *chip);
-extern int __must_check gpiochip_remove(struct gpio_chip *chip);
+void gpiochip_remove(struct gpio_chip *chip);
 extern struct gpio_chip *gpiochip_find(void *data,
                              int (*match)(struct gpio_chip *chip, void *data));
 
--

1.8.3.2

#2 lore raw
In reply to abdoulaye berthe
Quoted 2 lines · abdoulaye berthe

This avoids handling gpiochip remove error in device remove handler.

Be aware that at the moment many callers of gpiochip_remove() read its return value. So applying your patch as-is would break compilation.

This patch should therefore be the last of a series that first modifies all callers of gpiochip_remove() to ignore its return value, then neutralizes the function itself.

I am not sure whether the world would really be a better place after this though. Callers that don't need the return value of gpiochip_remove() can simply ignore it...

Quoted 29 lines
---
 drivers/gpio/gpiolib.c      | 24 +++++++-----------------
 include/linux/gpio/driver.h |  2 +-
 2 files changed, 8 insertions(+), 18 deletions(-)
drivers/gpio/gpiolib.c +1 -4
index f48817d..4878980 100644
@@ -1263,10 +1263,9 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip);
  *
  * A gpio_chip with any GPIOs still requested may not be removed.
  */
-int gpiochip_remove(struct gpio_chip *chip)
+void gpiochip_remove(struct gpio_chip *chip)
 {
        unsigned long   flags;
-       int             status = 0;
        unsigned        id;
 
        acpi_gpiochip_remove(chip);
@@ -1278,24 +1277,15 @@ int gpiochip_remove(struct gpio_chip *chip)
        of_gpiochip_remove(chip);
 
        for (id = 0; id < chip->ngpio; id++) {
-               if (test_bit(FLAG_REQUESTED, &chip->desc[id].flags)) {
-                       status = -EBUSY;

drivers/gpio/gpiolib.c int gpiochip_remove(struct gpio_chip *chip) · line 1281

Quoted 10 lines
drivers/gpio/gpiolib.c +2 -8
-                       break;
-               }
-       }
-       if (status == 0) {
-               for (id = 0; id < chip->ngpio; id++)
-                       chip->desc[id].chip = NULL;
-
-               list_del(&chip->list);
+               if (test_bit(FLAG_REQUESTED, &chip->desc[id].flags))
+                       panic("gpiolib.c: gpiochip is still requested\n");

panic() sounds a little harsh here. Maybe a dev_err() would be enough?

Quoted 20 lines
drivers/gpio/gpiolib.c +4 -5
        }
+       for (id = 0; id < chip->ngpio; id++)
+               chip->desc[id].chip = NULL;
 
+       list_del(&chip->list);
        spin_unlock_irqrestore(&gpio_lock, flags);
-
-       if (status == 0)
-               gpiochip_unexport(chip);
-
-       return status;
+       gpiochip_unexport(chip);
 }
 EXPORT_SYMBOL_GPL(gpiochip_remove);
 
include/linux/gpio/driver.h +0 -0
index 1827b43..72ed256 100644

include/linux/gpio/driver.h extern const char *gpiochip_is_requested(struct gpio_chip *chip, · line 141

Quoted 5 lines
include/linux/gpio/driver.h +1 -1
@@ -138,7 +138,7 @@ extern const char *gpiochip_is_requested(struct gpio_chip *chip,
 
 /* add/remove chips */
 extern int gpiochip_add(struct gpio_chip *chip);
-extern int __must_check gpiochip_remove(struct gpio_chip *chip);
+void gpiochip_remove(struct gpio_chip *chip);

"extern" should be preserved here for style consistency.

#3 lore raw

Well, ignoring the return value as it is done in gpio-bt8xx makes the compiler complain and display a warning message. The problem with false warning is that it might distract you. I think that the patch will makes things consistent once completed
Thanks a lot for the review.

Quoted 84 lines · Alexandre Courbot
Quoted 2 lines · abdoulaye berthe

This avoids handling gpiochip remove error in device remove handler.

Be aware that at the moment many callers of gpiochip_remove() read its return value. So applying your patch as-is would break compilation.

This patch should therefore be the last of a series that first modifies all callers of gpiochip_remove() to ignore its return value, then neutralizes the function itself.

I am not sure whether the world would really be a better place after this though. Callers that don't need the return value of gpiochip_remove() can simply ignore it...

Quoted 29 lines
---
 drivers/gpio/gpiolib.c      | 24 +++++++-----------------
 include/linux/gpio/driver.h |  2 +-
 2 files changed, 8 insertions(+), 18 deletions(-)
drivers/gpio/gpiolib.c +1 -4
index f48817d..4878980 100644
@@ -1263,10 +1263,9 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip);
  *
  * A gpio_chip with any GPIOs still requested may not be removed.
  */
-int gpiochip_remove(struct gpio_chip *chip)
+void gpiochip_remove(struct gpio_chip *chip)
 {
        unsigned long   flags;
-       int             status = 0;
        unsigned        id;
 
        acpi_gpiochip_remove(chip);
@@ -1278,24 +1277,15 @@ int gpiochip_remove(struct gpio_chip *chip)
        of_gpiochip_remove(chip);
 
        for (id = 0; id < chip->ngpio; id++) {
-               if (test_bit(FLAG_REQUESTED, &chip->desc[id].flags)) {
-                       status = -EBUSY;

drivers/gpio/gpiolib.c int gpiochip_remove(struct gpio_chip *chip) · line 1281

Quoted 10 lines
drivers/gpio/gpiolib.c +2 -8
-                       break;
-               }
-       }
-       if (status == 0) {
-               for (id = 0; id < chip->ngpio; id++)
-                       chip->desc[id].chip = NULL;
-
-               list_del(&chip->list);
+               if (test_bit(FLAG_REQUESTED, &chip->desc[id].flags))
+                       panic("gpiolib.c: gpiochip is still requested\n");

panic() sounds a little harsh here. Maybe a dev_err() would be enough?

Quoted 20 lines
drivers/gpio/gpiolib.c +4 -5
        }
+       for (id = 0; id < chip->ngpio; id++)
+               chip->desc[id].chip = NULL;
 
+       list_del(&chip->list);
        spin_unlock_irqrestore(&gpio_lock, flags);
-
-       if (status == 0)
-               gpiochip_unexport(chip);
-
-       return status;
+       gpiochip_unexport(chip);
 }
 EXPORT_SYMBOL_GPL(gpiochip_remove);
 
include/linux/gpio/driver.h +0 -0
index 1827b43..72ed256 100644

include/linux/gpio/driver.h extern const char *gpiochip_is_requested(struct gpio_chip *chip, · line 141

Quoted 5 lines
include/linux/gpio/driver.h +1 -1
@@ -138,7 +138,7 @@ extern const char *gpiochip_is_requested(struct gpio_chip *chip,
 
 /* add/remove chips */
 extern int gpiochip_add(struct gpio_chip *chip);
-extern int __must_check gpiochip_remove(struct gpio_chip *chip);
+void gpiochip_remove(struct gpio_chip *chip);

"extern" should be preserved here for style consistency.

#4 lore raw
Quoted 3 lines · abdoulaye berthe

Well, ignoring the return value as it is done in gpio-bt8xx makes the compiler complain and display a warning message. The problem with false warning is that it might distract you.

Isn't the warning due to the __must_check in the function's declaration? If so just removing it might do the trick...

Quoted 2 lines

I think that the patch
will makes things consistent once completed

Yeah fundamentally speaking I am not against this patch - I just wonder if it is worth going through all the call sites and changing them. Also we cannot exclude that a few users actually make something meaningful with the return value (don't know what that would be though).

Quoted 87 lines

Thanks a lot for the review.

Quoted 84 lines · Alexandre Courbot
Quoted 2 lines · abdoulaye berthe

This avoids handling gpiochip remove error in device remove handler.

Be aware that at the moment many callers of gpiochip_remove() read its return value. So applying your patch as-is would break compilation.

This patch should therefore be the last of a series that first modifies all callers of gpiochip_remove() to ignore its return value, then neutralizes the function itself.

I am not sure whether the world would really be a better place after this though. Callers that don't need the return value of gpiochip_remove() can simply ignore it...

Quoted 29 lines
---
 drivers/gpio/gpiolib.c      | 24 +++++++-----------------
 include/linux/gpio/driver.h |  2 +-
 2 files changed, 8 insertions(+), 18 deletions(-)
drivers/gpio/gpiolib.c +1 -4
index f48817d..4878980 100644
@@ -1263,10 +1263,9 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip);
  *
  * A gpio_chip with any GPIOs still requested may not be removed.
  */
-int gpiochip_remove(struct gpio_chip *chip)
+void gpiochip_remove(struct gpio_chip *chip)
 {
        unsigned long   flags;
-       int             status = 0;
        unsigned        id;
 
        acpi_gpiochip_remove(chip);
@@ -1278,24 +1277,15 @@ int gpiochip_remove(struct gpio_chip *chip)
        of_gpiochip_remove(chip);
 
        for (id = 0; id < chip->ngpio; id++) {
-               if (test_bit(FLAG_REQUESTED, &chip->desc[id].flags)) {
-                       status = -EBUSY;

drivers/gpio/gpiolib.c int gpiochip_remove(struct gpio_chip *chip) · line 1281

Quoted 10 lines
drivers/gpio/gpiolib.c +2 -8
-                       break;
-               }
-       }
-       if (status == 0) {
-               for (id = 0; id < chip->ngpio; id++)
-                       chip->desc[id].chip = NULL;
-
-               list_del(&chip->list);
+               if (test_bit(FLAG_REQUESTED, &chip->desc[id].flags))
+                       panic("gpiolib.c: gpiochip is still requested\n");

panic() sounds a little harsh here. Maybe a dev_err() would be enough?

Quoted 20 lines
drivers/gpio/gpiolib.c +4 -5
        }
+       for (id = 0; id < chip->ngpio; id++)
+               chip->desc[id].chip = NULL;
 
+       list_del(&chip->list);
        spin_unlock_irqrestore(&gpio_lock, flags);
-
-       if (status == 0)
-               gpiochip_unexport(chip);
-
-       return status;
+       gpiochip_unexport(chip);
 }
 EXPORT_SYMBOL_GPL(gpiochip_remove);
 
include/linux/gpio/driver.h +0 -0
index 1827b43..72ed256 100644

include/linux/gpio/driver.h extern const char *gpiochip_is_requested(struct gpio_chip *chip, · line 141

Quoted 5 lines
include/linux/gpio/driver.h +1 -1
@@ -138,7 +138,7 @@ extern const char *gpiochip_is_requested(struct gpio_chip *chip,
 
 /* add/remove chips */
 extern int gpiochip_add(struct gpio_chip *chip);
-extern int __must_check gpiochip_remove(struct gpio_chip *chip);
+void gpiochip_remove(struct gpio_chip *chip);

"extern" should be preserved here for style consistency.