]> git.baikalelectronics.ru Git - kernel.git/commitdiff
gpiolib: Optimize gpiochip_remove() when check for requested line
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Tue, 25 Feb 2020 11:47:25 +0000 (13:47 +0200)
committerLinus Walleij <linus.walleij@linaro.org>
Fri, 28 Feb 2020 22:58:56 +0000 (23:58 +0100)
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.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20200225114725.839-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
drivers/gpio/gpiolib.c

index 9ad86477af9c4f7cde939912ac9763a493d3856a..2253ab49534914cbe39b210b1ea00198f8c393f0 100644 (file)
@@ -1797,10 +1797,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);
@@ -1820,13 +1818,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");