Skip to content

Commit a649136

Browse files
lumagbebarino
authored andcommitted
PM: runtime: add devm_pm_clk_create helper
A typical code pattern for pm_clk_create() call is to call it in the _probe function and to call pm_clk_destroy() 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_clk_create() removes the need for calling pm_clk_destroy() both in the probe()'s error path and in the remove() function. Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org> Link: https://lore.kernel.org/r/20210731195034.979084-3-dmitry.baryshkov@linaro.org Acked-by: Rafael J. Wysocki <rafael@kernel.org> Signed-off-by: Stephen Boyd <sboyd@kernel.org>
1 parent b3636a3 commit a649136

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

drivers/base/power/clock_ops.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,23 @@ void pm_clk_destroy(struct device *dev)
519519
}
520520
EXPORT_SYMBOL_GPL(pm_clk_destroy);
521521

522+
static void pm_clk_destroy_action(void *data)
523+
{
524+
pm_clk_destroy(data);
525+
}
526+
527+
int devm_pm_clk_create(struct device *dev)
528+
{
529+
int ret;
530+
531+
ret = pm_clk_create(dev);
532+
if (ret)
533+
return ret;
534+
535+
return devm_add_action_or_reset(dev, pm_clk_destroy_action, dev);
536+
}
537+
EXPORT_SYMBOL_GPL(devm_pm_clk_create);
538+
522539
/**
523540
* pm_clk_suspend - Disable clocks in a device's PM clock list.
524541
* @dev: Device to disable the clocks for.

include/linux/pm_clock.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ extern void pm_clk_remove(struct device *dev, const char *con_id);
4747
extern void pm_clk_remove_clk(struct device *dev, struct clk *clk);
4848
extern int pm_clk_suspend(struct device *dev);
4949
extern int pm_clk_resume(struct device *dev);
50+
extern int devm_pm_clk_create(struct device *dev);
5051
#else
5152
static inline bool pm_clk_no_clocks(struct device *dev)
5253
{
@@ -83,6 +84,10 @@ static inline void pm_clk_remove(struct device *dev, const char *con_id)
8384
static inline void pm_clk_remove_clk(struct device *dev, struct clk *clk)
8485
{
8586
}
87+
static inline int devm_pm_clk_create(struct device *dev)
88+
{
89+
return -EINVAL;
90+
}
8691
#endif
8792

8893
#ifdef CONFIG_HAVE_CLK

0 commit comments

Comments
 (0)