Thread (9 messages) flat view 9 messages, 3 authors, 2021-08-31

Re: [PATCH v3 1/3] PM: runtime: add devm_pm_runtime_enable helper

From: "Rafael J. Wysocki" <rafael@kernel.org>
Date: 2021-08-06 13:28:06
Also in: linux-arm-msm, linux-clk, lkml

On Wed, Aug 4, 2021 at 11:03 PM Dmitry Baryshkov
[off-list ref] wrote:
On Wed, 4 Aug 2021 at 21:07, Rafael J. Wysocki [off-list ref] wrote:
quoted
On Sat, Jul 31, 2021 at 9:50 PM Dmitry Baryshkov
[off-list ref] wrote:
quoted
A typical code pattern for pm_runtime_enable() call is to call it in the
_probe function and to call pm_runtime_disable() both from _probe error
path and from _remove function. For some drivers the whole remove
function would consist of the call to pm_remove_disable().

Add helper function to replace this bolierplate piece of code. Calling
devm_pm_runtime_enable() removes the need for calling
pm_runtime_disable() both in the probe()'s error path and in the
remove() function.

Signed-off-by: Dmitry Baryshkov <redacted>
---
 drivers/base/power/runtime.c | 17 +++++++++++++++++
 include/linux/pm_runtime.h   |  4 ++++
 2 files changed, 21 insertions(+)
diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
index 8a66eaf731e4..ec94049442b9 100644
--- a/drivers/base/power/runtime.c
+++ b/drivers/base/power/runtime.c
@@ -1447,6 +1447,23 @@ void pm_runtime_enable(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(pm_runtime_enable);

+static void pm_runtime_disable_action(void *data)
+{
+       pm_runtime_disable(data);
+}
+
+/**
+ * devm_pm_runtime_enable - devres-enabled version of pm_runtime_enable.
+ * @dev: Device to handle.
+ */
+int devm_pm_runtime_enable(struct device *dev)
+{
+       pm_runtime_enable(dev);
+
+       return devm_add_action_or_reset(dev, pm_runtime_disable_action, dev);
When exactly is pm_runtime_disable_action() going to run by this rule?
 When the device goes away or when the driver is unbound from it?
When the driver is unbound (either because probe() returns an error or
because __device_release_driver() is being called).
This corresponds to a typical call to pm_runtime_disable() from the
probe()'s error path or in the remove() callback.
OK, so

Acked-by: Rafael J. Wysocki <rafael@kernel.org>

for the PM-runtime framework changes in this series (patches [1-2/3])
and please feel free to route them in through whatever tree is most
suitable (or let me know if you want me to pick them up).
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help