Skip to content

Commit f21cf9c

Browse files
committed
clk: Don't cache errors from clk_ops::get_phase()
We don't check for errors from clk_ops::get_phase() before storing away the result into the clk_core::phase member. This can lead to some fairly confusing debugfs information if these ops do return an error. Let's skip the store when this op fails to fix this. While we're here, move the locking outside of clk_core_get_phase() to simplify callers from the debugfs side. Cc: Douglas Anderson <[email protected]> Cc: Heiko Stuebner <[email protected]> Cc: Jerome Brunet <[email protected]> Signed-off-by: Stephen Boyd <[email protected]> Link: https://lkml.kernel.org/r/[email protected] Acked-by: Jerome Brunet <[email protected]>
1 parent bb6d3fb commit f21cf9c

File tree

1 file changed

+32
-16
lines changed

1 file changed

+32
-16
lines changed

drivers/clk/clk.c

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2660,12 +2660,14 @@ static int clk_core_get_phase(struct clk_core *core)
26602660
{
26612661
int ret;
26622662

2663-
clk_prepare_lock();
2663+
lockdep_assert_held(&prepare_lock);
2664+
if (!core->ops->get_phase)
2665+
return 0;
2666+
26642667
/* Always try to update cached phase if possible */
2665-
if (core->ops->get_phase)
2666-
core->phase = core->ops->get_phase(core->hw);
2667-
ret = core->phase;
2668-
clk_prepare_unlock();
2668+
ret = core->ops->get_phase(core->hw);
2669+
if (ret >= 0)
2670+
core->phase = ret;
26692671

26702672
return ret;
26712673
}
@@ -2679,10 +2681,16 @@ static int clk_core_get_phase(struct clk_core *core)
26792681
*/
26802682
int clk_get_phase(struct clk *clk)
26812683
{
2684+
int ret;
2685+
26822686
if (!clk)
26832687
return 0;
26842688

2685-
return clk_core_get_phase(clk->core);
2689+
clk_prepare_lock();
2690+
ret = clk_core_get_phase(clk->core);
2691+
clk_prepare_unlock();
2692+
2693+
return ret;
26862694
}
26872695
EXPORT_SYMBOL_GPL(clk_get_phase);
26882696

@@ -2896,13 +2904,21 @@ static struct hlist_head *orphan_list[] = {
28962904
static void clk_summary_show_one(struct seq_file *s, struct clk_core *c,
28972905
int level)
28982906
{
2899-
seq_printf(s, "%*s%-*s %7d %8d %8d %11lu %10lu %5d %6d\n",
2907+
int phase;
2908+
2909+
seq_printf(s, "%*s%-*s %7d %8d %8d %11lu %10lu ",
29002910
level * 3 + 1, "",
29012911
30 - level * 3, c->name,
29022912
c->enable_count, c->prepare_count, c->protect_count,
2903-
clk_core_get_rate(c), clk_core_get_accuracy(c),
2904-
clk_core_get_phase(c),
2905-
clk_core_get_scaled_duty_cycle(c, 100000));
2913+
clk_core_get_rate(c), clk_core_get_accuracy(c));
2914+
2915+
phase = clk_core_get_phase(c);
2916+
if (phase >= 0)
2917+
seq_printf(s, "%5d", phase);
2918+
else
2919+
seq_puts(s, "-----");
2920+
2921+
seq_printf(s, " %6d\n", clk_core_get_scaled_duty_cycle(c, 100000));
29062922
}
29072923

29082924
static void clk_summary_show_subtree(struct seq_file *s, struct clk_core *c,
@@ -2939,6 +2955,7 @@ DEFINE_SHOW_ATTRIBUTE(clk_summary);
29392955

29402956
static void clk_dump_one(struct seq_file *s, struct clk_core *c, int level)
29412957
{
2958+
int phase;
29422959
unsigned long min_rate, max_rate;
29432960

29442961
clk_core_get_boundaries(c, &min_rate, &max_rate);
@@ -2952,7 +2969,9 @@ static void clk_dump_one(struct seq_file *s, struct clk_core *c, int level)
29522969
seq_printf(s, "\"min_rate\": %lu,", min_rate);
29532970
seq_printf(s, "\"max_rate\": %lu,", max_rate);
29542971
seq_printf(s, "\"accuracy\": %lu,", clk_core_get_accuracy(c));
2955-
seq_printf(s, "\"phase\": %d,", clk_core_get_phase(c));
2972+
phase = clk_core_get_phase(c);
2973+
if (phase >= 0)
2974+
seq_printf(s, "\"phase\": %d,", phase);
29562975
seq_printf(s, "\"duty_cycle\": %u",
29572976
clk_core_get_scaled_duty_cycle(c, 100000));
29582977
}
@@ -3434,14 +3453,11 @@ static int __clk_core_init(struct clk_core *core)
34343453
core->accuracy = 0;
34353454

34363455
/*
3437-
* Set clk's phase.
3456+
* Set clk's phase by clk_core_get_phase() caching the phase.
34383457
* Since a phase is by definition relative to its parent, just
34393458
* query the current clock phase, or just assume it's in phase.
34403459
*/
3441-
if (core->ops->get_phase)
3442-
core->phase = core->ops->get_phase(core->hw);
3443-
else
3444-
core->phase = 0;
3460+
clk_core_get_phase(core);
34453461

34463462
/*
34473463
* Set clk's duty cycle.

0 commit comments

Comments
 (0)