Skip to contentSkip to conversation

clk: Fix phase init check

PATCH Applied Maxime Ripard 2 participants 3 messages Feb 25, 2020 – Feb 28, 2020 Common clk

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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, and ends up returning that to the caller on success, breaking the API that implies that the driver should return 0 on success.

Fixes 2760878662a2 ("clk: Bail out when calculating phase fails during clk registration")
---
 drivers/clk/clk.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/clk/clk.c +4 -2
index ebfc1e2103cb..f122e9911b57 100644
@@ -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;
Signature · 1 line
2.24.1
maintainer
#1 lore raw

Quoting Maxime Ripard (2020-02-25 05:42:48)

Quoted 8 lines

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, and ends up returning that to the caller on success, breaking the API that implies that the driver should return 0 on success.

I had to read this a few times to understand. I'll reword it to indicate that __clk_core_init() should return 0 on success and not the phase which is typically a positive value.

Quoted 3 lines
Fixes 2760878662a2 ("clk: Bail out when calculating phase fails during clk registration")

Thanks. I think we need a

tag added as well.

Quoted 28 lines
---
 drivers/clk/clk.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/clk/clk.c +4 -2
index ebfc1e2103cb..f122e9911b57 100644
@@ -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;
maintainer Applied
#2 lore raw
In reply to Maxime Ripard

Quoting Maxime Ripard (2020-02-25 05:42:48)

Quoted 4 lines

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.

Quoted 8 lines

However, it doesn't check whether the returned value is positive which will happen if the driver returns a non-zero phase, and ends up returning that to the caller on success, breaking the API that implies that the driver should return 0 on success.

Fixes 2760878662a2 ("clk: Bail out when calculating phase fails during clk registration")

---

Applied to clk-next