[PATCH 4/4] gpio: grgpio: remove remove()

From: Bartosz Golaszewski
Date: Tue Oct 15 2024 - 09:23:28 EST


From: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxx>

Use devres to automatically manage resources and remove the remove()
callback.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxx>
---
drivers/gpio/gpio-grgpio.c | 29 +++++++++++++----------------
1 file changed, 13 insertions(+), 16 deletions(-)

diff --git a/drivers/gpio/gpio-grgpio.c b/drivers/gpio/gpio-grgpio.c
index e11d7c4ad04d..7ffe59d845f0 100644
--- a/drivers/gpio/gpio-grgpio.c
+++ b/drivers/gpio/gpio-grgpio.c
@@ -318,6 +318,13 @@ static void grgpio_irq_unmap(struct irq_domain *d, unsigned int irq)
raw_spin_unlock_irqrestore(&priv->gc.bgpio_lock, flags);
}

+static void grgpio_irq_domain_remove(void *data)
+{
+ struct irq_domain *domain = data;
+
+ irq_domain_remove(domain);
+}
+
static const struct irq_domain_ops grgpio_irq_domain_ops = {
.map = grgpio_irq_map,
.unmap = grgpio_irq_unmap,
@@ -394,6 +401,11 @@ static int grgpio_probe(struct platform_device *ofdev)
return -EINVAL;
}

+ err = devm_add_action_or_reset(dev, grgpio_irq_domain_remove,
+ priv->domain);
+ if (err)
+ return err;
+
for (i = 0; i < gc->ngpio; i++) {
struct grgpio_lirq *lirq;
int ret;
@@ -416,13 +428,9 @@ static int grgpio_probe(struct platform_device *ofdev)
}
}

- platform_set_drvdata(ofdev, priv);
-
- err = gpiochip_add_data(gc, priv);
+ err = devm_gpiochip_add_data(dev, gc, priv);
if (err) {
dev_err(dev, "Could not add gpiochip\n");
- if (priv->domain)
- irq_domain_remove(priv->domain);
return err;
}

@@ -432,16 +440,6 @@ static int grgpio_probe(struct platform_device *ofdev)
return 0;
}

-static void grgpio_remove(struct platform_device *ofdev)
-{
- struct grgpio_priv *priv = platform_get_drvdata(ofdev);
-
- gpiochip_remove(&priv->gc);
-
- if (priv->domain)
- irq_domain_remove(priv->domain);
-}
-
static const struct of_device_id grgpio_match[] = {
{.name = "GAISLER_GPIO"},
{.name = "01_01a"},
@@ -456,7 +454,6 @@ static struct platform_driver grgpio_driver = {
.of_match_table = grgpio_match,
},
.probe = grgpio_probe,
- .remove_new = grgpio_remove,
};
module_platform_driver(grgpio_driver);

--
2.43.0