Skip to content

Commit b8b2c7d

Browse files
Uwe Kleine-Königgregkh
authored andcommitted
base/platform: assert that dev_pm_domain callbacks are called unconditionally
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>
1 parent 65da348 commit b8b2c7d

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

drivers/base/platform.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ static int platform_drv_probe(struct device *_dev)
513513
return ret;
514514

515515
ret = dev_pm_domain_attach(_dev, true);
516-
if (ret != -EPROBE_DEFER) {
516+
if (ret != -EPROBE_DEFER && drv->probe) {
517517
ret = drv->probe(dev);
518518
if (ret)
519519
dev_pm_domain_detach(_dev, true);
@@ -536,9 +536,10 @@ static int platform_drv_remove(struct device *_dev)
536536
{
537537
struct platform_driver *drv = to_platform_driver(_dev->driver);
538538
struct platform_device *dev = to_platform_device(_dev);
539-
int ret;
539+
int ret = 0;
540540

541-
ret = drv->remove(dev);
541+
if (drv->remove)
542+
ret = drv->remove(dev);
542543
dev_pm_domain_detach(_dev, true);
543544

544545
return ret;
@@ -549,7 +550,8 @@ static void platform_drv_shutdown(struct device *_dev)
549550
struct platform_driver *drv = to_platform_driver(_dev->driver);
550551
struct platform_device *dev = to_platform_device(_dev);
551552

552-
drv->shutdown(dev);
553+
if (drv->shutdown)
554+
drv->shutdown(dev);
553555
dev_pm_domain_detach(_dev, true);
554556
}
555557

@@ -563,12 +565,9 @@ int __platform_driver_register(struct platform_driver *drv,
563565
{
564566
drv->driver.owner = owner;
565567
drv->driver.bus = &platform_bus_type;
566-
if (drv->probe)
567-
drv->driver.probe = platform_drv_probe;
568-
if (drv->remove)
569-
drv->driver.remove = platform_drv_remove;
570-
if (drv->shutdown)
571-
drv->driver.shutdown = platform_drv_shutdown;
568+
drv->driver.probe = platform_drv_probe;
569+
drv->driver.remove = platform_drv_remove;
570+
drv->driver.shutdown = platform_drv_shutdown;
572571

573572
return driver_register(&drv->driver);
574573
}

0 commit comments

Comments
 (0)