Struct gpio_device now provides a revocable provider to the underlying
struct gpio_chip.  Leverage revocable for gpiolib_sops so that it
doesn't need to handle the synchronization by accessing the SRCU
explicitly.

Signed-off-by: Tzung-Bi Shih <[email protected]>
---
 drivers/gpio/gpiolib.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 6226dc738281..cd18ff42b610 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -5376,6 +5376,7 @@ static void gpiolib_dbg_show(struct seq_file *s, struct 
gpio_chip *gc)
 struct gpiolib_seq_priv {
        bool newline;
        int idx;
+       struct revocable *chip_rev;
 };
 
 static void *gpiolib_seq_start(struct seq_file *s, loff_t *pos)
@@ -5397,8 +5398,12 @@ static void *gpiolib_seq_start(struct seq_file *s, 
loff_t *pos)
 
        list_for_each_entry_srcu(gdev, &gpio_devices, list,
                                 srcu_read_lock_held(&gpio_devices_srcu)) {
-               if (index-- == 0)
+               if (index-- == 0) {
+                       priv->chip_rev = revocable_alloc(gdev->chip_rp);
+                       if (!priv->chip_rev)
+                               return NULL;
                        return gdev;
+               }
        }
 
        return NULL;
@@ -5425,6 +5430,8 @@ static void gpiolib_seq_stop(struct seq_file *s, void *v)
        if (!priv)
                return;
 
+       if (priv->chip_rev)
+               revocable_free(priv->chip_rev);
        srcu_read_unlock(&gpio_devices_srcu, priv->idx);
        kfree(priv);
 }
@@ -5439,9 +5446,7 @@ static int gpiolib_seq_show(struct seq_file *s, void *v)
        if (priv->newline)
                seq_putc(s, '\n');
 
-       guard(srcu)(&gdev->srcu);
-
-       gc = srcu_dereference(gdev->chip, &gdev->srcu);
+       REVOCABLE_TRY_ACCESS_WITH(priv->chip_rev, gc);
        if (!gc) {
                seq_printf(s, "%s: (dangling chip)\n", dev_name(&gdev->dev));
                return 0;
-- 
2.52.0.457.g6b5491de43-goog


Reply via email to