Skip to content

Commit a82fcb1

Browse files
committed
clk: test: Add test managed of_clk_add_hw_provider()
Add a test managed version of of_clk_add_hw_provider() that automatically unregisters the clk_hw provider upon test conclusion. Cc: Brendan Higgins <[email protected]> Cc: David Gow <[email protected]> Cc: Rae Moar <[email protected]> Cc: Peng Fan <[email protected]> Signed-off-by: Stephen Boyd <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 9852d85 commit a82fcb1

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

drivers/clk/clk_kunit_helpers.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,5 +203,35 @@ int of_clk_hw_register_kunit(struct kunit *test, struct device_node *node, struc
203203
}
204204
EXPORT_SYMBOL_GPL(of_clk_hw_register_kunit);
205205

206+
KUNIT_DEFINE_ACTION_WRAPPER(of_clk_del_provider_wrapper,
207+
of_clk_del_provider, struct device_node *);
208+
209+
/**
210+
* of_clk_add_hw_provider_kunit() - Test managed of_clk_add_hw_provider()
211+
* @test: The test context
212+
* @np: Device node pointer associated with clock provider
213+
* @get: Callback for decoding clk_hw
214+
* @data: Context pointer for @get callback.
215+
*
216+
* Just like of_clk_add_hw_provider(), except the clk_hw provider is managed by
217+
* the test case and is automatically unregistered after the test case
218+
* concludes.
219+
*
220+
* Return: 0 on success or a negative errno value on failure.
221+
*/
222+
int of_clk_add_hw_provider_kunit(struct kunit *test, struct device_node *np,
223+
struct clk_hw *(*get)(struct of_phandle_args *clkspec, void *data),
224+
void *data)
225+
{
226+
int ret;
227+
228+
ret = of_clk_add_hw_provider(np, get, data);
229+
if (ret)
230+
return ret;
231+
232+
return kunit_add_action_or_reset(test, of_clk_del_provider_wrapper, np);
233+
}
234+
EXPORT_SYMBOL_GPL(of_clk_add_hw_provider_kunit);
235+
206236
MODULE_LICENSE("GPL");
207237
MODULE_DESCRIPTION("KUnit helpers for clk providers and consumers");

include/kunit/clk.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,8 @@ int clk_hw_register_kunit(struct kunit *test, struct device *dev, struct clk_hw
2525
int of_clk_hw_register_kunit(struct kunit *test, struct device_node *node,
2626
struct clk_hw *hw);
2727

28+
int of_clk_add_hw_provider_kunit(struct kunit *test, struct device_node *np,
29+
struct clk_hw *(*get)(struct of_phandle_args *clkspec, void *data),
30+
void *data);
31+
2832
#endif

0 commit comments

Comments
 (0)