Skip to contentSkip to conversation

gpio: gpiolib: set gpiochip_remove retval to void

PATCH In review abdoulaye berthe 3 participants 4 messages May 23, 2014 – May 29, 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
Quoted 4 lines · abdoulaye berthe

This avoids handling gpiochip remove error in device remove handler.

In general this is the right thing to do.

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

Quoted 13 lines
        for (id = 0; id < chip->ngpio; id++) {
drivers/gpio/gpiolib.c +2 -10
-               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");

panic("gpio: removing gpiochip with gpios still requested\"); is more helpful.

But I want a patch that also removes *ALL* users of the return value from this function in the *same* patch to avoid bisectability issues.

$ git grep gpiochip_remove

Then fix all of them or use coccinelle.

Yours,
Linus Walleij

#2 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..022543f 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("gpio: removing gpiochip with gpios 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
#3 lore raw

Hi abdoulaye,

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

Quoted 3 lines · On Fri, 30 May 2014 00:32:02 +0200 abdoulaye berthe <[email protected]> wrote:
drivers/gpio/gpiolib.c +2 -0
+		if (test_bit(FLAG_REQUESTED, &chip->desc[id].flags))
+			panic("gpio: removing gpiochip with gpios still requested\n");

Someone else already commented that panic is probably overkill ... is there no way to log this and continue?

Signature · 2 lines
Cheers,
Stephen Rothwell                    [email protected]