Skip to content

Commit b4060db

Browse files
diandersrafaeljw
authored andcommitted
PM: runtime: Have devm_pm_runtime_enable() handle pm_runtime_dont_use_autosuspend()
The PM Runtime docs say: Drivers in ->remove() callback should undo the runtime PM changes done in ->probe(). Usually this means calling pm_runtime_disable(), pm_runtime_dont_use_autosuspend() etc. From grepping code, it's clear that many people aren't aware of the need to call pm_runtime_dont_use_autosuspend(). When brainstorming solutions, one idea that came up was to leverage the new-ish devm_pm_runtime_enable() function. The idea here is that: * When the devm action is called we know that the driver is being removed. It's the perfect time to undo the use_autosuspend. * The code of pm_runtime_dont_use_autosuspend() already handles the case of being called when autosuspend wasn't enabled. Suggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Douglas Anderson <dianders@chromium.org> Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 7e57714 commit b4060db

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

drivers/base/power/runtime.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,11 +1476,16 @@ EXPORT_SYMBOL_GPL(pm_runtime_enable);
14761476

14771477
static void pm_runtime_disable_action(void *data)
14781478
{
1479+
pm_runtime_dont_use_autosuspend(data);
14791480
pm_runtime_disable(data);
14801481
}
14811482

14821483
/**
14831484
* devm_pm_runtime_enable - devres-enabled version of pm_runtime_enable.
1485+
*
1486+
* NOTE: this will also handle calling pm_runtime_dont_use_autosuspend() for
1487+
* you at driver exit time if needed.
1488+
*
14841489
* @dev: Device to handle.
14851490
*/
14861491
int devm_pm_runtime_enable(struct device *dev)

include/linux/pm_runtime.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,10 @@ static inline void pm_runtime_disable(struct device *dev)
567567
* Allow the runtime PM autosuspend mechanism to be used for @dev whenever
568568
* requested (or "autosuspend" will be handled as direct runtime-suspend for
569569
* it).
570+
*
571+
* NOTE: It's important to undo this with pm_runtime_dont_use_autosuspend()
572+
* at driver exit time unless your driver initially enabled pm_runtime
573+
* with devm_pm_runtime_enable() (which handles it for you).
570574
*/
571575
static inline void pm_runtime_use_autosuspend(struct device *dev)
572576
{

0 commit comments

Comments
 (0)