@@ -113,7 +113,7 @@ struct clk {
/*** runtime pm ***/
static int clk_pm_runtime_get(struct clk_core *core)
{
- if (!core->rpm_enabled)
+ if (!core || !core->rpm_enabled)
return 0;
return pm_runtime_resume_and_get(core->dev);
@@ -135,7 +135,7 @@ static int clk_pm_runtime_get_if_active(struct clk_core *core)
static void clk_pm_runtime_put(struct clk_core *core)
{
- if (!core->rpm_enabled)
+ if (!core || !core->rpm_enabled)
return;
pm_runtime_put_sync(core->dev);
@@ -1081,7 +1081,6 @@ static void clk_core_unprepare(struct clk_core *core)
trace_clk_unprepare_complete(core);
clk_core_unprepare(core->parent);
- clk_pm_runtime_put(core);
}
static void clk_core_unprepare_lock(struct clk_core *core)
@@ -1089,6 +1088,8 @@ static void clk_core_unprepare_lock(struct clk_core *core)
clk_prepare_lock();
clk_core_unprepare(core);
clk_prepare_unlock();
+
+ clk_pm_runtime_put(core);
}
/**
@@ -1121,13 +1122,9 @@ static int clk_core_prepare(struct clk_core *core)
return 0;
if (core->prepare_count == 0) {
- ret = clk_pm_runtime_get(core);
- if (ret)
- return ret;
-
ret = clk_core_prepare(core->parent);
if (ret)
- goto runtime_put;
+ return ret;
trace_clk_prepare(core);
@@ -1155,8 +1152,7 @@ static int clk_core_prepare(struct clk_core *core)
return 0;
unprepare:
clk_core_unprepare(core->parent);
-runtime_put:
- clk_pm_runtime_put(core);
+
return ret;
}
@@ -1164,10 +1160,17 @@ static int clk_core_prepare_lock(struct clk_core *core)
{
int ret;
+ ret = clk_pm_runtime_get(core);
+ if (ret)
+ return ret;
+
clk_prepare_lock();
ret = clk_core_prepare(core);
clk_prepare_unlock();
+ if (ret)
+ clk_pm_runtime_put(core);
+
return ret;
}
In order to fix the ABBA locking situation between clock and power domains, let's disimburse these two locks by preventing any runtime PM call to happen with the clk prepare_lock mutex acquired. The prepare routine shall preferably call the runtime PM functions before acquiring the prepare lock. In practice the prepare helper requires the current clock and all its parents to be runtime resumed. There is no need to perform individual calls as we get inner and inner in recursive calls (ie. following the "clock parents") because, as of today, runtime PM works by already resuming automatically all the suppliers which in this case already include the clock parents. Hence, doing a single runtime PM call at the beginning of the function is enough. One side effect though is that we now need to check for the validity of core clk pointers in the runtime PM clk helpers. Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> --- drivers/clk/clk.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-)