]> Git Repo - linux.git/commitdiff
gpio: em: remove the gpiochip before removing the irq domain
authorBartosz Golaszewski <[email protected]>
Thu, 11 Jul 2019 08:29:35 +0000 (10:29 +0200)
committerBartosz Golaszewski <[email protected]>
Mon, 15 Jul 2019 09:52:42 +0000 (11:52 +0200)
In commit 8764c4ca5049 ("gpio: em: use the managed version of
gpiochip_add_data()") we implicitly altered the ordering of resource
freeing: since gpiochip_remove() calls gpiochip_irqchip_remove()
internally, we now can potentially use the irq_domain after it was
destroyed in the remove() callback (as devm resources are freed after
remove() has returned).

Use devm_add_action_or_reset() to keep the ordering right and entirely
kill the remove() callback in the driver.

Reported-by: Geert Uytterhoeven <[email protected]>
Fixes: 8764c4ca5049 ("gpio: em: use the managed version of gpiochip_add_data()")
Cc: [email protected]
Signed-off-by: Bartosz Golaszewski <[email protected]>
Reviewed-by: Geert Uytterhoeven <[email protected]>
drivers/gpio/gpio-em.c

index b6af705a4e5f4810f1a8fc74c51ad0b74b440b78..a87951293aaac50f72dc9ea2cbb86e2851a79847 100644 (file)
@@ -259,6 +259,13 @@ static const struct irq_domain_ops em_gio_irq_domain_ops = {
        .xlate  = irq_domain_xlate_twocell,
 };
 
+static void em_gio_irq_domain_remove(void *data)
+{
+       struct irq_domain *domain = data;
+
+       irq_domain_remove(domain);
+}
+
 static int em_gio_probe(struct platform_device *pdev)
 {
        struct em_gio_priv *p;
@@ -333,39 +340,30 @@ static int em_gio_probe(struct platform_device *pdev)
                return -ENXIO;
        }
 
+       ret = devm_add_action_or_reset(&pdev->dev, em_gio_irq_domain_remove,
+                                      p->irq_domain);
+       if (ret)
+               return ret;
+
        if (devm_request_irq(&pdev->dev, irq[0]->start,
                             em_gio_irq_handler, 0, name, p)) {
                dev_err(&pdev->dev, "failed to request low IRQ\n");
-               ret = -ENOENT;
-               goto err1;
+               return -ENOENT;
        }
 
        if (devm_request_irq(&pdev->dev, irq[1]->start,
                             em_gio_irq_handler, 0, name, p)) {
                dev_err(&pdev->dev, "failed to request high IRQ\n");
-               ret = -ENOENT;
-               goto err1;
+               return -ENOENT;
        }
 
        ret = devm_gpiochip_add_data(&pdev->dev, gpio_chip, p);
        if (ret) {
                dev_err(&pdev->dev, "failed to add GPIO controller\n");
-               goto err1;
+               return ret;
        }
 
        return 0;
-
-err1:
-       irq_domain_remove(p->irq_domain);
-       return ret;
-}
-
-static int em_gio_remove(struct platform_device *pdev)
-{
-       struct em_gio_priv *p = platform_get_drvdata(pdev);
-
-       irq_domain_remove(p->irq_domain);
-       return 0;
 }
 
 static const struct of_device_id em_gio_dt_ids[] = {
@@ -376,7 +374,6 @@ MODULE_DEVICE_TABLE(of, em_gio_dt_ids);
 
 static struct platform_driver em_gio_device_driver = {
        .probe          = em_gio_probe,
-       .remove         = em_gio_remove,
        .driver         = {
                .name   = "em_gio",
                .of_match_table = em_gio_dt_ids,
This page took 0.055628 seconds and 4 git commands to generate.