* [PATCH v2 0/2] clk: fix corner case of clk_mux_determine_rate_flags()
@ 2023-04-25 7:46 Yang Xiwen via B4 Relay
2023-04-25 7:46 ` [PATCH v2 1/2] clk: use ULONG_MAX as the initial value for the iteration in clk_mux_determine_rate_flags() Yang Xiwen via B4 Relay
2023-04-25 7:46 ` [PATCH v2 2/2] clk: tests: Add missing test case for mux determine_rate Yang Xiwen via B4 Relay
0 siblings, 2 replies; 4+ messages in thread
From: Yang Xiwen via B4 Relay @ 2023-04-25 7:46 UTC (permalink / raw)
To: Michael Turquette, Stephen Boyd; +Cc: linux-clk, linux-kernel, Yang Xiwen
Signed-off-by: Yang Xiwen <forbidden405@outlook.com>
---
Changes in v2:
- Add a unit test to clk_test.c
- Link to v1: https://lore.kernel.org/r/20230421-clk-v1-1-bb503f2f2cf3@outlook.com
---
Yang Xiwen (2):
clk: use ULONG_MAX as the initial value for the iteration in clk_mux_determine_rate_flags()
clk: tests: Add missing test case for mux determine_rate
drivers/clk/clk.c | 5 ++++-
drivers/clk/clk_test.c | 9 +++++++++
2 files changed, 13 insertions(+), 1 deletion(-)
---
base-commit: 76f598ba7d8e2bfb4855b5298caedd5af0c374a8
change-id: 20230421-clk-64c6b6e21cdb
Best regards,
--
Yang Xiwen <forbidden405@outlook.com>
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH v2 1/2] clk: use ULONG_MAX as the initial value for the iteration in clk_mux_determine_rate_flags() 2023-04-25 7:46 [PATCH v2 0/2] clk: fix corner case of clk_mux_determine_rate_flags() Yang Xiwen via B4 Relay @ 2023-04-25 7:46 ` Yang Xiwen via B4 Relay 2023-04-25 7:46 ` [PATCH v2 2/2] clk: tests: Add missing test case for mux determine_rate Yang Xiwen via B4 Relay 1 sibling, 0 replies; 4+ messages in thread From: Yang Xiwen via B4 Relay @ 2023-04-25 7:46 UTC (permalink / raw) To: Michael Turquette, Stephen Boyd; +Cc: linux-clk, linux-kernel, Yang Xiwen From: Yang Xiwen <forbidden405@outlook.com> Currently, clk_mux_determine_rate_flags() use 0 as the initial value for selecting the best matching parent. However, this will choose a non-existant rate(0) if the requested rate is closer to 0 than the minimum rate the parents have. Fix that by initializing the initial value to ULONG_MAX and treat it as a magic number. Signed-off-by: Yang Xiwen <forbidden405@outlook.com> --- drivers/clk/clk.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index ae07685c7588b..ab8a2acfac8f3 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -541,6 +541,9 @@ EXPORT_SYMBOL_GPL(__clk_is_enabled); static bool mux_is_better_rate(unsigned long rate, unsigned long now, unsigned long best, unsigned long flags) { + if (best == ULONG_MAX) + return true; + if (flags & CLK_MUX_ROUND_CLOSEST) return abs(now - rate) < abs(best - rate); @@ -600,7 +603,7 @@ int clk_mux_determine_rate_flags(struct clk_hw *hw, { struct clk_core *core = hw->core, *parent, *best_parent = NULL; int i, num_parents, ret; - unsigned long best = 0; + unsigned long best = ULONG_MAX; /* if NO_REPARENT flag set, pass through to current parent */ if (core->flags & CLK_SET_RATE_NO_REPARENT) { -- 2.39.2 ^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 2/2] clk: tests: Add missing test case for mux determine_rate 2023-04-25 7:46 [PATCH v2 0/2] clk: fix corner case of clk_mux_determine_rate_flags() Yang Xiwen via B4 Relay 2023-04-25 7:46 ` [PATCH v2 1/2] clk: use ULONG_MAX as the initial value for the iteration in clk_mux_determine_rate_flags() Yang Xiwen via B4 Relay @ 2023-04-25 7:46 ` Yang Xiwen via B4 Relay 2023-04-25 19:40 ` Stephen Boyd 1 sibling, 1 reply; 4+ messages in thread From: Yang Xiwen via B4 Relay @ 2023-04-25 7:46 UTC (permalink / raw) To: Michael Turquette, Stephen Boyd; +Cc: linux-clk, linux-kernel, Yang Xiwen From: Yang Xiwen <forbidden405@outlook.com> Add a missing test case for determine_rate implemented by mux. It tests the behavior of determine_rate when requesting a rate that none of the parents could give. Signed-off-by: Yang Xiwen <forbidden405@outlook.com> --- drivers/clk/clk_test.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/clk/clk_test.c b/drivers/clk/clk_test.c index f9a5c2964c65d..9b1c90de90454 100644 --- a/drivers/clk/clk_test.c +++ b/drivers/clk/clk_test.c @@ -2215,6 +2215,15 @@ static void clk_leaf_mux_set_rate_parent_determine_rate(struct kunit *test) KUNIT_EXPECT_EQ(test, req.best_parent_rate, DUMMY_CLOCK_RATE_2); KUNIT_EXPECT_PTR_EQ(test, req.best_parent_hw, &ctx->mux_ctx.hw); + // Test a non-existant rate which none of the parents could give + clk_hw_init_rate_request(hw, &req, DUMMY_CLOCK_INIT_RATE); + + ret = __clk_determine_rate(hw, &req); + KUNIT_ASSERT_EQ(test, ret, 0); + + KUNIT_EXPECT_EQ(test, req.rate, DUMMY_CLOCK_RATE_1); + KUNIT_EXPECT_EQ(test, req.best_parent_rate, DUMMY_CLOCK_RATE_1); + KUNIT_EXPECT_PTR_EQ(test, req.best_parent_hw, &ctx->mux_ctx.hw); clk_put(clk); } -- 2.39.2 ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2 2/2] clk: tests: Add missing test case for mux determine_rate 2023-04-25 7:46 ` [PATCH v2 2/2] clk: tests: Add missing test case for mux determine_rate Yang Xiwen via B4 Relay @ 2023-04-25 19:40 ` Stephen Boyd 0 siblings, 0 replies; 4+ messages in thread From: Stephen Boyd @ 2023-04-25 19:40 UTC (permalink / raw) To: Michael Turquette, Yang Xiwen via B4 Relay, forbidden405 Cc: linux-clk, linux-kernel, Yang Xiwen Quoting Yang Xiwen via B4 Relay (2023-04-25 00:46:40) > From: Yang Xiwen <forbidden405@outlook.com> > > Add a missing test case for determine_rate implemented by mux. It tests > the behavior of determine_rate when requesting a rate that none of the > parents could give. > > Signed-off-by: Yang Xiwen <forbidden405@outlook.com> > --- > drivers/clk/clk_test.c | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/drivers/clk/clk_test.c b/drivers/clk/clk_test.c > index f9a5c2964c65d..9b1c90de90454 100644 > --- a/drivers/clk/clk_test.c > +++ b/drivers/clk/clk_test.c > @@ -2215,6 +2215,15 @@ static void clk_leaf_mux_set_rate_parent_determine_rate(struct kunit *test) > KUNIT_EXPECT_EQ(test, req.best_parent_rate, DUMMY_CLOCK_RATE_2); > KUNIT_EXPECT_PTR_EQ(test, req.best_parent_hw, &ctx->mux_ctx.hw); > > + // Test a non-existant rate which none of the parents could give > + clk_hw_init_rate_request(hw, &req, DUMMY_CLOCK_INIT_RATE); > + > + ret = __clk_determine_rate(hw, &req); > + KUNIT_ASSERT_EQ(test, ret, 0); > + > + KUNIT_EXPECT_EQ(test, req.rate, DUMMY_CLOCK_RATE_1); > + KUNIT_EXPECT_EQ(test, req.best_parent_rate, DUMMY_CLOCK_RATE_1); > + KUNIT_EXPECT_PTR_EQ(test, req.best_parent_hw, &ctx->mux_ctx.hw); Please make an entire test case instead of modifying an existing test case. ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-04-25 19:40 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2023-04-25 7:46 [PATCH v2 0/2] clk: fix corner case of clk_mux_determine_rate_flags() Yang Xiwen via B4 Relay 2023-04-25 7:46 ` [PATCH v2 1/2] clk: use ULONG_MAX as the initial value for the iteration in clk_mux_determine_rate_flags() Yang Xiwen via B4 Relay 2023-04-25 7:46 ` [PATCH v2 2/2] clk: tests: Add missing test case for mux determine_rate Yang Xiwen via B4 Relay 2023-04-25 19:40 ` Stephen Boyd
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®