clk: Fix phase init check
authorMaxime Ripard <maxime@cerno.tech>
Tue, 25 Feb 2020 13:42:48 +0000 (14:42 +0100)
committerStephen Boyd <sboyd@kernel.org>
Fri, 28 Feb 2020 18:57:03 +0000 (10:57 -0800)
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>
drivers/clk/clk.c

index ed17978..4d6fd7d 100644 (file)
@@ -3344,6 +3344,7 @@ static int __clk_core_init(struct clk_core *core)
        int ret;
        struct clk_core *parent;
        unsigned long rate;
+       int phase;
 
        if (!core)
                return -EINVAL;
@@ -3457,8 +3458,9 @@ static int __clk_core_init(struct clk_core *core)
         * Since a phase is by definition relative to its parent, just
         * query the current clock phase, or just assume it's in phase.
         */
-       ret = clk_core_get_phase(core);
-       if (ret < 0) {
+       phase = clk_core_get_phase(core);
+       if (phase < 0) {
+               ret = phase;
                pr_warn("%s: Failed to get phase for clk '%s'\n", __func__,
                        core->name);
                goto out;