Re: [PATCH v2] clk: gate: Add some kunit test suites
From: Stephen Boyd
Date: Thu Jan 20 2022 - 12:51:44 EST
Quoting Daniel Latypov (2022-01-19 22:26:50)
> On Wed, Jan 19, 2022 at 9:23 PM Stephen Boyd <sboyd@xxxxxxxxxx> wrote:
> > +
> > +static void clk_gate_test_exit(struct kunit *test)
> > +{
> > + struct clk_gate_test_context *ctx = test->priv;
> > +
> > + clk_hw_unregister_gate(ctx->hw);
> > + clk_hw_unregister_fixed_rate(ctx->parent);
> > + kfree(ctx);
>
> I think we forgot to drop some kfree's now that we're using
> test->priv = ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL);
>
> This will result in duplicate kfree's.
Good catch! I forgot that it was a managed allocation like that. Doesn't
help that I had to go all the way to the kunit_kmalloc_array()
kernel-doc to read that test managed means it is freed when the test is
done.
> > +
> > +static void clk_gate_test_is_enabled(struct kunit *test)
> > +{
> > + struct clk_hw *hw;
> > + struct clk_gate_test_context *ctx;
> > +
> > + ctx = clk_gate_test_alloc_ctx(test);
> > + ctx->fake_reg = BIT(7);
> > + hw = clk_hw_register_gate(NULL, "test_gate", NULL, 0, ctx->fake_mem, 7,
> > + 0, NULL);
> > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, hw);
> > + KUNIT_ASSERT_TRUE(test, clk_hw_is_enabled(hw));
> > +
> > + clk_hw_unregister_gate(hw);
> > + kfree(ctx);
>
> ditto
>
>
Thanks! Next time can you trim your mails? It's quite long and I have to
scroll down to find everything.