Skip to content

Commit f995080

Browse files
claudiubeznearafaeljw
authored andcommitted
PM: domains: Detach on device_unbind_cleanup()
The dev_pm_domain_attach() function is typically used in bus code alongside dev_pm_domain_detach(), often following patterns like: static int bus_probe(struct device *_dev) { struct bus_driver *drv = to_bus_driver(dev->driver); struct bus_device *dev = to_bus_device(_dev); int ret; // ... ret = dev_pm_domain_attach(_dev, true); if (ret) return ret; if (drv->probe) ret = drv->probe(dev); // ... } static void bus_remove(struct device *_dev) { struct bus_driver *drv = to_bus_driver(dev->driver); struct bus_device *dev = to_bus_device(_dev); if (drv->remove) drv->remove(dev); dev_pm_domain_detach(_dev); } When the driver's probe function uses devres-managed resources that depend on the power domain state, those resources are released later during device_unbind_cleanup(). Releasing devres-managed resources that depend on the power domain state after detaching the device from its PM domain can cause failures. For example, if the driver uses devm_pm_runtime_enable() in its probe function, and the device's clocks are managed by the PM domain, then during removal the runtime PM is disabled in device_unbind_cleanup() after the clocks have been removed from the PM domain. It may happen that the devm_pm_runtime_enable() action causes the device to be runtime- resumed. If the driver specific runtime PM APIs access registers directly, this will lead to accessing device registers without clocks being enabled. Similar issues may occur with other devres actions that access device registers. Add detach_power_off member to struct dev_pm_info, to be used later in device_unbind_cleanup() as the power_off argument for dev_pm_domain_detach(). This is a preparatory step toward removing dev_pm_domain_detach() calls from bus remove functions. Since the current PM domain detach functions (genpd_dev_pm_detach() and acpi_dev_pm_detach()) already set dev->pm_domain = NULL, there should be no issues with bus drivers that still call dev_pm_domain_detach() in their remove functions. Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com> Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org> Link: https://patch.msgid.link/20250703112708.1621607-3-claudiu.beznea.uj@bp.renesas.com Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent d42c7c6 commit f995080

3 files changed

Lines changed: 6 additions & 0 deletions

File tree

drivers/base/dd.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <linux/kthread.h>
2626
#include <linux/wait.h>
2727
#include <linux/async.h>
28+
#include <linux/pm_domain.h>
2829
#include <linux/pm_runtime.h>
2930
#include <linux/pinctrl/devinfo.h>
3031
#include <linux/slab.h>
@@ -552,6 +553,7 @@ static void device_unbind_cleanup(struct device *dev)
552553
dev->dma_range_map = NULL;
553554
device_set_driver(dev, NULL);
554555
dev_set_drvdata(dev, NULL);
556+
dev_pm_domain_detach(dev, dev->power.detach_power_off);
555557
if (dev->pm_domain && dev->pm_domain->dismiss)
556558
dev->pm_domain->dismiss(dev);
557559
pm_runtime_reinit(dev);

drivers/base/power/common.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ int dev_pm_domain_attach(struct device *dev, u32 flags)
111111
if (!ret)
112112
ret = genpd_dev_pm_attach(dev);
113113

114+
if (dev->pm_domain)
115+
dev->power.detach_power_off = !!(flags & PD_FLAG_DETACH_POWER_OFF);
116+
114117
return ret < 0 ? ret : 0;
115118
}
116119
EXPORT_SYMBOL_GPL(dev_pm_domain_attach);

include/linux/pm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,7 @@ struct dev_pm_info {
721721
struct pm_subsys_data *subsys_data; /* Owned by the subsystem. */
722722
void (*set_latency_tolerance)(struct device *, s32);
723723
struct dev_pm_qos *qos;
724+
bool detach_power_off:1; /* Owned by the driver core */
724725
};
725726

726727
extern int dev_pm_get_subsys_data(struct device *dev);

0 commit comments

Comments
 (0)