[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20260109-fix_error_setting_clk_rate_range-v1-1-bae0b40e870f@amlogic.com>
Date: Fri, 09 Jan 2026 11:24:22 +0800
From: Chuan Liu via B4 Relay <devnull+chuan.liu.amlogic.com@...nel.org>
To: Michael Turquette <mturquette@...libre.com>,
Stephen Boyd <sboyd@...nel.org>
Cc: linux-clk@...r.kernel.org, linux-kernel@...r.kernel.org,
Chuan Liu <chuan.liu@...ogic.com>
Subject: [PATCH] clk: Ensure correct consumer's rate boundaries
From: Chuan Liu <chuan.liu@...ogic.com>
If we were to have two users of the same clock, doing something like:
clk_set_rate_range(user1, 1000, 2000);
clk_set_rate_range(user2, 3000, 4000);
Even when user2's call returns -EINVAL, the min_rate and max_rate of
user2 are still incorrectly updated. This causes subsequent calls by
user1 to fail when setting the clock rate, as clk_core_get_boundaries()
returns corrupted boundaries (min_rate = 3000, max_rate = 2000).
To prevent this, clk_core_check_boundaries() now rollback to the old
boundaries when the check fails.
Signed-off-by: Chuan Liu <chuan.liu@...ogic.com>
---
drivers/clk/clk.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 85d2f2481acf..0dfb16bf3f31 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -2710,13 +2710,17 @@ static int clk_set_rate_range_nolock(struct clk *clk,
*/
rate = clamp(rate, min, max);
ret = clk_core_set_rate_nolock(clk->core, rate);
+
+out:
if (ret) {
- /* rollback the changes */
+ /*
+ * Rollback the consumer’s old boundaries if check_boundaries or
+ * set_rate fails.
+ */
clk->min_rate = old_min;
clk->max_rate = old_max;
}
-out:
if (clk->exclusive_count)
clk_core_rate_protect(clk->core);
---
base-commit: 7f98ab9da046865d57c102fd3ca9669a29845f67
change-id: 20260107-fix_error_setting_clk_rate_range-d928da67af90
Best regards,
--
Chuan Liu <chuan.liu@...ogic.com>
Powered by blists - more mailing lists