]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
gpiolib: read descriptor flags once in gpiolib_dbg_show()
authorBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Sat, 15 Feb 2025 10:08:47 +0000 (11:08 +0100)
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Mon, 24 Feb 2025 09:06:38 +0000 (10:06 +0100)
For consistency with most other code that can access requested
descriptors: read the flags once atomically and then test individual
bits from the helper variable. This avoids any potential discrepancies
should flags change during the debug print.

Link: https://lore.kernel.org/r/20250215100847.30136-1-brgl@bgdev.pl
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
drivers/gpio/gpiolib.c

index 9103384f4a5e7341e0fc963a5fcc648405a04055..e8678a6c82ea350c86ddaf14733cfd0e2d9bbcee 100644 (file)
@@ -5111,6 +5111,7 @@ static void gpiolib_dbg_show(struct seq_file *s, struct gpio_device *gdev)
        unsigned int gpio = gdev->base;
        struct gpio_desc *desc;
        struct gpio_chip *gc;
+       unsigned long flags;
        int value;
 
        guard(srcu)(&gdev->srcu);
@@ -5123,12 +5124,13 @@ static void gpiolib_dbg_show(struct seq_file *s, struct gpio_device *gdev)
 
        for_each_gpio_desc(gc, desc) {
                guard(srcu)(&desc->gdev->desc_srcu);
-               is_irq = test_bit(FLAG_USED_AS_IRQ, &desc->flags);
-               if (is_irq || test_bit(FLAG_REQUESTED, &desc->flags)) {
+               flags = READ_ONCE(desc->flags);
+               is_irq = test_bit(FLAG_USED_AS_IRQ, &flags);
+               if (is_irq || test_bit(FLAG_REQUESTED, &flags)) {
                        gpiod_get_direction(desc);
-                       is_out = test_bit(FLAG_IS_OUT, &desc->flags);
+                       is_out = test_bit(FLAG_IS_OUT, &flags);
                        value = gpio_chip_get_value(gc, desc);
-                       active_low = test_bit(FLAG_ACTIVE_LOW, &desc->flags);
+                       active_low = test_bit(FLAG_ACTIVE_LOW, &flags);
                        seq_printf(s, " gpio-%-3u (%-20.20s|%-20.20s) %s %s %s%s\n",
                                   gpio, desc->name ?: "", gpiod_get_label(desc),
                                   is_out ? "out" : "in ",