Skip to contentSkip to conversation

clk: tests: Add tests for clk lookup by name

PATCH Superseded Chen-Yu Tsai 3 participants 3 messages Oct 15, 2025 – Nov 11, 2025 Common clk

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 clk: tests: Add tests for clk lookup by name

Clk lookup (by name) recently gained some performance improvements at the expense of more complexity within the lookup code.

To make sure that this works as intended and doesn't break, add some basic tests for this part of the CCF.

A new "clk_hw_lookup()" function is added purely for running kunit tests.

---
Changes since v1:
- Added missing prepare lock/unlock
- Switched to EXPORT_SYMBOL_IF_KUNIT and VISIBLE_IF_KUNIT kunit visibility macros for consistency (Brian)
This probably doesn't make much difference except that the symbol is now in the EXPORT_SYMBOL_IF_KUNIT namespace

---
 drivers/clk/clk.c      | 18 ++++++++++++
 drivers/clk/clk.h      |  4 +++
 drivers/clk/clk_test.c | 67 +++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 88 insertions(+), 1 deletion(-)
drivers/clk/clk.c +18 -0
index 85d2f2481acf..b39ad8944a06 100644
@@ -10,6 +10,7 @@
 #include <linux/clkdev.h>
 #include <linux/clk.h>
 #include <linux/clk-provider.h>
+#include <linux/compiler_attributes.h>
 #include <linux/device.h>
 #include <linux/err.h>
 #include <linux/hashtable.h>
@@ -25,6 +26,8 @@
 #include <linux/string.h>
 #include <linux/stringhash.h>
 
+#include <kunit/visibility.h>
+
 #include "clk.h"
 
 static DEFINE_SPINLOCK(enable_lock);
@@ -778,6 +781,21 @@ struct clk *__clk_lookup(const char *name)
 	return !core ? NULL : core->hw->clk;
 }
 
+/* This is only provided for kunit tests to test the core lookup functions. */
+#if IS_ENABLED(CONFIG_CLK_KUNIT_TEST)
+VISIBLE_IF_KUNIT struct clk_hw * __maybe_unused __must_check clk_hw_lookup(const char *name)
+{
+	struct clk_core *core;
+
+	clk_prepare_lock();
+	core = clk_core_lookup(name);
+	clk_prepare_unlock();
+
+	return !core ? NULL : core->hw;
+}
+EXPORT_SYMBOL_IF_KUNIT(clk_hw_lookup);
+#endif
+
 static void clk_core_get_boundaries(struct clk_core *core,
 				    unsigned long *min_rate,
 				    unsigned long *max_rate)
drivers/clk/clk.h +4 -0
index 2d801900cad5..a8ed54f5b572 100644
@@ -8,6 +8,10 @@ struct clk_hw;
 struct device;
 struct of_phandle_args;
 
+#if IS_ENABLED(CONFIG_CLK_KUNIT_TEST)
+struct clk_hw *clk_hw_lookup(const char *name);
+#endif
+
 #if defined(CONFIG_OF) && defined(CONFIG_COMMON_CLK)
 struct clk_hw *of_clk_get_hw(struct device_node *np,
 				    int index, const char *con_id);
drivers/clk/clk_test.c +66 -1

91 lines not on this page · raw message

Signature · 1 line
2.51.0.788.g6d19910ace-goog
Reviewed-by on v2 1/1
#1 lore raw
Quoted 10 lines · Chen-Yu Tsai

Clk lookup (by name) recently gained some performance improvements at the expense of more complexity within the lookup code.

To make sure that this works as intended and doesn't break, add some basic tests for this part of the CCF.

A new "clk_hw_lookup()" function is added purely for running kunit tests.

maintainer
#2 lore raw
In reply to Chen-Yu Tsai

Quoting Chen-Yu Tsai (2025-10-15 02:06:59)

Quoted 6 lines

Clk lookup (by name) recently gained some performance improvements at the expense of more complexity within the lookup code.

To make sure that this works as intended and doesn't break, add some basic tests for this part of the CCF.

Quoted 6 lines

A new "clk_hw_lookup()" function is added purely for running kunit tests.

---

Urgh I see I missed the new one. Please look at v1 and fix things up and resend.