base/platform: assert that dev_pm_domain callbacks are called unconditionally
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Fri, 7 Aug 2015 05:19:22 +0000 (07:19 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 4 Oct 2015 18:42:22 +0000 (19:42 +0100)
When a platform driver doesn't provide a .remove callback the function
platform_drv_remove isn't called and so the call to dev_pm_domain_attach
called at probe time isn't paired by dev_pm_domain_detach at remove
time.

To fix this (and similar issues if different callbacks are missing) hook
up the driver callbacks unconditionally and make them aware that the
platform callbacks might be missing.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/base/platform.c

index f80aaaf9f6108c0204c17d9eb770f984f3a303c2..07cec9ba5e70c55b99c950b38950ec572f4bbd0e 100644 (file)
@@ -513,7 +513,7 @@ static int platform_drv_probe(struct device *_dev)
                return ret;
 
        ret = dev_pm_domain_attach(_dev, true);
-       if (ret != -EPROBE_DEFER) {
+       if (ret != -EPROBE_DEFER && drv->probe) {
                ret = drv->probe(dev);
                if (ret)
                        dev_pm_domain_detach(_dev, true);
@@ -536,9 +536,10 @@ static int platform_drv_remove(struct device *_dev)
 {
        struct platform_driver *drv = to_platform_driver(_dev->driver);
        struct platform_device *dev = to_platform_device(_dev);
-       int ret;
+       int ret = 0;
 
-       ret = drv->remove(dev);
+       if (drv->remove)
+               ret = drv->remove(dev);
        dev_pm_domain_detach(_dev, true);
 
        return ret;
@@ -549,7 +550,8 @@ static void platform_drv_shutdown(struct device *_dev)
        struct platform_driver *drv = to_platform_driver(_dev->driver);
        struct platform_device *dev = to_platform_device(_dev);
 
-       drv->shutdown(dev);
+       if (drv->shutdown)
+               drv->shutdown(dev);
        dev_pm_domain_detach(_dev, true);
 }
 
@@ -563,12 +565,9 @@ int __platform_driver_register(struct platform_driver *drv,
 {
        drv->driver.owner = owner;
        drv->driver.bus = &platform_bus_type;
-       if (drv->probe)
-               drv->driver.probe = platform_drv_probe;
-       if (drv->remove)
-               drv->driver.remove = platform_drv_remove;
-       if (drv->shutdown)
-               drv->driver.shutdown = platform_drv_shutdown;
+       drv->driver.probe = platform_drv_probe;
+       drv->driver.remove = platform_drv_remove;
+       drv->driver.shutdown = platform_drv_shutdown;
 
        return driver_register(&drv->driver);
 }
This page took 0.026067 seconds and 5 git commands to generate.