Skip to contentSkip to conversation

gpiolib: Optimize gpiochip_remove() when check for requested line

PATCH In review Andy Shevchenko 2 participants 2 messages Feb 25, 2020 – Feb 28, 2020 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpiolib: Optimize gpiochip_remove() when check for requested line

Here are the following optimizations have been done:
- break the loop after first found requested line
- due to above, drop redundant boolean variable
- replace open coded variant of gpiochip_is_requested()
- due to above, drop redundant pointer to struct gpio_desc
- use 'unsigned int' instead of 'unsigned' for loop counter

Note, pointer to struct gpio_chip followed by pointer to struct gpio_device is still valid, back link is not.

---
 drivers/gpio/gpiolib.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/gpio/gpiolib.c +4 -7
index 26fe775e4bab..c98902a13f6f 100644
@@ -1819,10 +1819,8 @@ EXPORT_SYMBOL_GPL(gpiochip_get_data);
 void gpiochip_remove(struct gpio_chip *chip)
 {
 	struct gpio_device *gdev = chip->gpiodev;
-	struct gpio_desc *desc;
 	unsigned long	flags;
-	unsigned	i;
-	bool		requested = false;
+	unsigned int	i;
 
 	/* FIXME: should the legacy sysfs handling be moved to gpio_device? */
 	gpiochip_sysfs_unregister(gdev);
@@ -1842,13 +1840,12 @@ void gpiochip_remove(struct gpio_chip *chip)
 
 	spin_lock_irqsave(&gpio_lock, flags);
 	for (i = 0; i < gdev->ngpio; i++) {
-		desc = &gdev->descs[i];
-		if (test_bit(FLAG_REQUESTED, &desc->flags))
-			requested = true;
+		if (gpiochip_is_requested(chip, i))
+			break;
 	}
 	spin_unlock_irqrestore(&gpio_lock, flags);
 
-	if (requested)
+	if (i == gdev->ngpio)
 		dev_crit(&gdev->dev,
 			 "REMOVING GPIOCHIP WITH GPIOS STILL REQUESTED\n");
 
Signature · 1 line
2.25.0
#1 lore raw
Quoted 11 lines · Andy Shevchenko

Here are the following optimizations have been done:
- break the loop after first found requested line
- due to above, drop redundant boolean variable
- replace open coded variant of gpiochip_is_requested()
- due to above, drop redundant pointer to struct gpio_desc
- use 'unsigned int' instead of 'unsigned' for loop counter

Note, pointer to struct gpio_chip followed by pointer to struct gpio_device is still valid, back link is not.

Looks neat!
Patch applied.

Yours,
Linus Walleij