[PATCH v2 0/2] Fix clk_divider_bestdiv() to get max clk rate supported and add some kunit test suites

Prabhakar
2026-04-13T12:49:20Z

From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>

Hi all,

This patch series includes two patches. The first patch fixes the
clk_divider_bestdiv() function in clk-divider driver to return the
maximum clock rate supported by the divider when the requested rate
is larger than the parent clock rate. The second patch adds some
kunit test suites for clk-divider driver to verify the fix.

kunit test case logs:
case #1 without the fix:
------------------------
[ 44.288459] KTAP version 1
[ 44.291655] 1..1
[ 44.293844] KTAP version 1
[ 44.297411] # Subtest: clk_divider_bestdiv
[ 44.302575] # module: clk_divider_test
[ 44.302583] 1..2
[ 44.310280] # clk_divider_bestdiv_ulong_max_returns_max_rate: EXPECTATION FAILED at drivers/clk/clk-divider_test.c:71
[ 44.310280] Expected rate == 1000000000UL / 2, but
[ 44.310280] rate == 125000000 (0x7735940)
[ 44.310280] 1000000000UL / 2 == 500000000 (0x1dcd6500)
[ 44.310705] not ok 1 clk_divider_bestdiv_ulong_max_returns_max_rate
[ 44.341802] # clk_divider_bestdiv_mux_ulong_max_returns_max_rate: EXPECTATION FAILED at drivers/clk/clk-divider_test.c:134
[ 44.341802] Expected rate == (4 * 1000000000UL) / 2, but
[ 44.341802] rate == 0 (0x0)
[ 44.341802] (4 * 1000000000UL) / 2 == 2000000000 (0x77359400)
[ 44.349940] not ok 2 clk_divider_bestdiv_mux_ulong_max_returns_max_rate
[ 44.381047] # clk_divider_bestdiv: pass:0 fail:2 skip:0 total:2
[ 44.388922] # Totals: pass:0 fail:2 skip:0 total:2
[ 44.395783] not ok 1 clk_divider_bestdiv

case #2 with the fix:
---------------------
[ 22.077769] KTAP version 1
[ 22.080931] 1..1
[ 22.083168] KTAP version 1
[ 22.086739] # Subtest: clk_divider_bestdiv
[ 22.091826] # module: clk_divider_test
[ 22.091835] 1..2
[ 22.099869] ok 1 clk_divider_bestdiv_ulong_max_returns_max_rate
[ 22.100612] ok 2 clk_divider_bestdiv_mux_ulong_max_returns_max_rate
[ 22.107902] # clk_divider_bestdiv: pass:2 fail:0 skip:0 total:2
[ 22.115589] # Totals: pass:2 fail:0 skip:0 total:2
[ 22.122473] ok 1 clk_divider_bestdiv

v1->v2:
- Updated the patch#1 fixing review comments from Sashiko
- Added a new patch#2 to add some kunit test suites for clk-divider driver

Cheers,
Prabhakar

Lad Prabhakar (2):
clk: divider: Fix clk_divider_bestdiv() returning min rate for large
rate requests
clk: divider: Add some kunit test suites

drivers/clk/Kconfig | 7 ++
drivers/clk/Makefile | 1 +
drivers/clk/clk-divider.c | 25 ++++--
drivers/clk/clk-divider_test.c | 151 +++++++++++++++++++++++++++++++++
4 files changed, 176 insertions(+), 8 deletions(-)
create mode 100644 drivers/clk/clk-divider_test.c

--
2.53.0