Re: [PATCH 06/16] clk: tests: Add clk_parse_clkspec() Kunit testing
From: Brian Masney
Date: Wed Apr 01 2026 - 10:00:54 EST
Hi Miquel,
On Wed, Apr 01, 2026 at 10:59:20AM +0200, Miquel Raynal wrote:
> >> + of_node_put(ctx->prov1_np);
> >> +
> >> + /* Register provider 2 */
> >> + hw2 = kunit_kzalloc(test, sizeof(*hw2), GFP_KERNEL);
> >> + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, hw2);
> >> + hw2->init = &clk_parse_clkspec_2_init_data;
> >> +
> >> + ctx->prov2_np = of_find_compatible_node(NULL, NULL, "test,clock-provider2");
> >> + KUNIT_ASSERT_NOT_NULL(test, ctx->prov2_np);
> >> +
> >> + KUNIT_ASSERT_EQ(test, 0, of_clk_hw_register_kunit(test, ctx->prov2_np, hw2));
> >> + of_clk_add_hw_provider(ctx->prov2_np, kunit_clk_get, hw2);
> >> + of_node_put(ctx->prov2_np);
> >> +
> >> + ctx->cons_np = of_find_compatible_node(NULL, NULL, "test,clock-consumer");
> >> + KUNIT_ASSERT_NOT_NULL(test, ctx->cons_np);
> >> +
> >> + return 0;
> >> +}
> >> +
> >> +static void clk_parse_clkspec_exit(struct kunit *test)
> >> +{
> >> + struct clk_parse_clkspec_ctx *ctx = test->priv;
> >> +
> >> + of_node_put(ctx->prov1_np);
> >> + of_node_put(ctx->prov2_np);
> >
> > Is there a double free of prov1_np and prov2_np? If this is dropped from
> > the test exit, then they should't need to be in the ctx struct.
>
> These two calls increment the refcount on the node:
> - of_find_compatible_node()
> - of_clk_add_hw_provider()
>
> However this makes me realize maybe I should call of_clk_del_provider()
> in the exit() function. In any case, I believe keeping a reference over
> the nodes during the test is correct and if there is an of_node_put()
> call to remove, it should be the on in the _init().
Take a look at drivers/clk/clk_kunit_helpers.c.
of_clk_add_hw_provider_kunit() will call of_clk_del_provider() for you
via of_clk_del_provider_wrapper.
Brian