diff mbox series

[03/12] clk: test: Introduce clk_put_kunit()

Message ID 20240815005520.1192374-4-sboyd@kernel.org (mailing list archive)
State New
Headers show
Series clk: Unit test clk unregistration paths | expand

Commit Message

Stephen Boyd Aug. 15, 2024, 12:55 a.m. UTC
Tests will need to put a clk at a specific point during the test. Add a
clk_put_kunit() function that releases the kunit action created by a
function like clk_get_kunit() so that code is kept tidy.

Cc: Brendan Higgins <brendan.higgins@linux.dev>
Cc: David Gow <davidgow@google.com>
Cc: Rae Moar <rmoar@google.com>
Cc: Nuno Sá <nuno.sa@analog.com>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
---
 drivers/clk/clk_kunit_helpers.c | 21 +++++++++++++++++++++
 include/kunit/clk.h             |  1 +
 2 files changed, 22 insertions(+)
diff mbox series

Patch

diff --git a/drivers/clk/clk_kunit_helpers.c b/drivers/clk/clk_kunit_helpers.c
index 87f97329ae0c..ddb9f2de1083 100644
--- a/drivers/clk/clk_kunit_helpers.c
+++ b/drivers/clk/clk_kunit_helpers.c
@@ -153,6 +153,27 @@  clk_hw_get_clk_prepared_enabled_kunit(struct kunit *test, struct clk_hw *hw,
 }
 EXPORT_SYMBOL_GPL(clk_hw_get_clk_prepared_enabled_kunit);
 
+/**
+ * clk_put_kunit() - Force a clk_put() call on a clk managed by the @test
+ * @test: The test context
+ * @clk: Clk consumer to put with clk_put()
+ *
+ * Just like clk_put(), except the clk must be managed by the @test, i.e.
+ * returned from something like clk_get_kunit(). clk_put() will be called
+ * immediately and the deferred action will be removed.
+ *
+ * Return: 0 on success or a negative errno value on failure to find the
+ * deferred action.
+ */
+int clk_put_kunit(struct kunit *test, struct clk *clk)
+{
+	kunit_release_action(test, clk_put_wrapper, clk);
+	/* TODO: Find the action and fail */
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(clk_put_kunit);
+
 KUNIT_DEFINE_ACTION_WRAPPER(clk_hw_unregister_wrapper,
 			    clk_hw_unregister, struct clk_hw *);
 
diff --git a/include/kunit/clk.h b/include/kunit/clk.h
index c513fec8099b..d37fa6b87c2b 100644
--- a/include/kunit/clk.h
+++ b/include/kunit/clk.h
@@ -18,6 +18,7 @@  clk_hw_get_clk_kunit(struct kunit *test, struct clk_hw *hw, const char *con_id);
 struct clk *
 clk_hw_get_clk_prepared_enabled_kunit(struct kunit *test, struct clk_hw *hw,
 				      const char *con_id);
+int clk_put_kunit(struct kunit *test, struct clk *clk);
 
 int clk_prepare_enable_kunit(struct kunit *test, struct clk *clk);