Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

clk: Fix phase init check

Commit 2760878662a2 ("clk: Bail out when calculating phase fails during
clk registration") introduced a check on error values at the time the
clock is registered to bail out when such an error occurs. However, it
doesn't check whether the returned value is positive which will happen
if the driver returns a non-zero phase. Since a phase is usually a
non-zero positive number this ends up returning something that isn't 0
to the caller of __clk_core_init(), making most clks fail to register
if they implement a phase clk op and return anything besides 0 for the
phase.

Fix this by returning the error if phase is less than zero or just
return zero if the phase is a positive number.

Fixes: 2760878662a2 ("clk: Bail out when calculating phase fails during clk registration")
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Link: https://lkml.kernel.org/r/20200225134248.919889-1-maxime@cerno.tech
Reported-by: "kernelci.org bot" <bot@kernelci.org>
[sboyd@kernel.org: Reword commit text to provide clarity]
Signed-off-by: Stephen Boyd <sboyd@kernel.org>

authored by

Maxime Ripard and committed by
Stephen Boyd
c3944ec8 27608786

+4 -2
+4 -2
drivers/clk/clk.c
··· 3344 3344 int ret; 3345 3345 struct clk_core *parent; 3346 3346 unsigned long rate; 3347 + int phase; 3347 3348 3348 3349 if (!core) 3349 3350 return -EINVAL; ··· 3458 3457 * Since a phase is by definition relative to its parent, just 3459 3458 * query the current clock phase, or just assume it's in phase. 3460 3459 */ 3461 - ret = clk_core_get_phase(core); 3462 - if (ret < 0) { 3460 + phase = clk_core_get_phase(core); 3461 + if (phase < 0) { 3462 + ret = phase; 3463 3463 pr_warn("%s: Failed to get phase for clk '%s'\n", __func__, 3464 3464 core->name); 3465 3465 goto out;