Skip to content

Commit 2447883

Browse files
miquelraynalbebarino
authored andcommitted
clk: core: clarify the check for runtime PM
Currently, the core->dev entry is populated only if runtime PM is enabled. Doing so prevents accessing the device structure in any case. Keep the same logic but instead of using the presence of core->dev as the only condition, also check the status of pm_runtime_enabled(). Then, we can set the core->dev pointer at any time as long as a device structure is available. This change will help supporting device links in the clock subsystem. Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Cc: Jerome Brunet <jbrunet@baylibre.com> Cc: Russell King <linux@armlinux.org.uk> Cc: Michael Turquette <mturquette@baylibre.com> Cc: Jeffrey Hugo <jhugo@codeaurora.org> Cc: Chen-Yu Tsai <wens@csie.org> [sboyd@kernel.org: Change to a boolean flag] Signed-off-by: Stephen Boyd <sboyd@kernel.org>
1 parent 1df4046 commit 2447883

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

drivers/clk/clk.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ struct clk_core {
5757
struct clk_core *new_child;
5858
unsigned long flags;
5959
bool orphan;
60+
bool rpm_enabled;
6061
unsigned int enable_count;
6162
unsigned int prepare_count;
6263
unsigned int protect_count;
@@ -92,9 +93,9 @@ struct clk {
9293
/*** runtime pm ***/
9394
static int clk_pm_runtime_get(struct clk_core *core)
9495
{
95-
int ret = 0;
96+
int ret;
9697

97-
if (!core->dev)
98+
if (!core->rpm_enabled)
9899
return 0;
99100

100101
ret = pm_runtime_get_sync(core->dev);
@@ -103,7 +104,7 @@ static int clk_pm_runtime_get(struct clk_core *core)
103104

104105
static void clk_pm_runtime_put(struct clk_core *core)
105106
{
106-
if (!core->dev)
107+
if (!core->rpm_enabled)
107108
return;
108109

109110
pm_runtime_put_sync(core->dev);
@@ -223,7 +224,7 @@ static bool clk_core_is_enabled(struct clk_core *core)
223224
* taking enable spinlock, but the below check is needed if one tries
224225
* to call it from other places.
225226
*/
226-
if (core->dev) {
227+
if (core->rpm_enabled) {
227228
pm_runtime_get_noresume(core->dev);
228229
if (!pm_runtime_active(core->dev)) {
229230
ret = false;
@@ -233,7 +234,7 @@ static bool clk_core_is_enabled(struct clk_core *core)
233234

234235
ret = core->ops->is_enabled(core->hw);
235236
done:
236-
if (core->dev)
237+
if (core->rpm_enabled)
237238
pm_runtime_put(core->dev);
238239

239240
return ret;
@@ -3341,7 +3342,8 @@ struct clk *clk_register(struct device *dev, struct clk_hw *hw)
33413342
core->ops = hw->init->ops;
33423343

33433344
if (dev && pm_runtime_enabled(dev))
3344-
core->dev = dev;
3345+
core->rpm_enabled = true;
3346+
core->dev = dev;
33453347
if (dev && dev->driver)
33463348
core->owner = dev->driver->owner;
33473349
core->hw = hw;

0 commit comments

Comments
 (0)