Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Miquel Raynal (Schneider Electric)" <miquel.raynal@bootlin.com>
Cc: robh@kernel.org, devicetree@vger.kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v4 3/7] clk: tests: Add Kunit testing for of_clk_get_parent_name()
Date: Fri, 17 Jul 2026 17:11:42 +0000	[thread overview]
Message-ID: <20260717171143.3C7831F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260717-schneider-v7-2-rc1-eip201-upstream-v4-3-751547e160e5@bootlin.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Potential use-after-free of device tree strings and clock names when returning clock parent names.
--

--- Patch [3]: [PATCH v4 3/7] clk: tests: Add Kunit testing for of_clk_get_parent_name() ---
commit 4b760cb4ff3b2b61c5f90468c3fd87c387504cd7
Author: Miquel Raynal (Schneider Electric) <miquel.raynal@bootlin.com>

clk: tests: Add Kunit testing for of_clk_get_parent_name()

This commit adds a Kunit test to verify that of_clk_get_parent_name()
returns the correct clock name when looking up by index.

> diff --git a/drivers/clk/clk_test.c b/drivers/clk/clk_test.c
> index f47f81b7d72a4..4084559e157df 100644
> --- a/drivers/clk/clk_test.c
> +++ b/drivers/clk/clk_test.c

[ ... ]

> @@ -3637,9 +3637,23 @@ static void clk_parse_clkspec_with_incorrect_index_and_name(struct kunit *test)
>  	KUNIT_EXPECT_TRUE(test, IS_ERR(hw));
>  }
>  
> +/*
> + * Verify that of_clk_get_parent_name() returns the correct clock name when
> + * looking up by index through the consumer's clocks property.
> + */
> +static void of_clk_get_parent_name_gets_parent_name(struct kunit *test)
> +{
> +	struct clk_parse_clkspec_ctx *ctx = test->priv;
> +	const char *expected_name = "clk_parse_clkspec_1";
> +
> +	KUNIT_EXPECT_STREQ(test, expected_name,
> +			   of_clk_get_parent_name(ctx->cons_np, 0));

[Severity: High]
This isn't a bug introduced by this patch, but does of_clk_get_parent_name()
return a potentially dangling pointer here?

Looking at of_clk_get_parent_name() in drivers/clk/clk.c:

    clk_name = __clk_get_name(clk);
    clk_put(clk);
    ...
    of_node_put(clkspec.np);
    return clk_name;

The string pointer is extracted and the reference to its owning object (the
clock or the device node) is dropped before returning. If the node is from a
removed DT overlay or the clock provider is concurrently unregistered, and
this was the last reference, wouldn't the memory backing the string be freed
leaving the caller with a dangling pointer?

> +}
> +
>  static struct kunit_case clk_parse_clkspec_test_cases[] = {
>  	KUNIT_CASE(clk_parse_clkspec_with_correct_index_and_name),
>  	KUNIT_CASE(clk_parse_clkspec_with_incorrect_index_and_name),
> +	KUNIT_CASE(of_clk_get_parent_name_gets_parent_name),
>  	{}
>  };

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260717-schneider-v7-2-rc1-eip201-upstream-v4-0-751547e160e5@bootlin.com?part=3

  reply	other threads:[~2026-07-17 17:11 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-17 15:59 [PATCH v4 0/7] clk: Add support for clock nexus Miquel Raynal (Schneider Electric)
2026-07-17 15:59 ` [PATCH v4 1/7] dt-bindings: clock: Introduce nexus nodes Miquel Raynal (Schneider Electric)
2026-07-17 16:51   ` sashiko-bot
2026-07-17 15:59 ` [PATCH v4 2/7] clk: tests: Add clk_parse_clkspec() Kunit testing Miquel Raynal (Schneider Electric)
2026-07-17 15:59 ` [PATCH v4 3/7] clk: tests: Add Kunit testing for of_clk_get_parent_name() Miquel Raynal (Schneider Electric)
2026-07-17 17:11   ` sashiko-bot [this message]
2026-07-17 15:59 ` [PATCH v4 4/7] clk: Improve a couple of comments Miquel Raynal (Schneider Electric)
2026-07-17 15:59 ` [PATCH v4 5/7] clk: Use the generic OF phandle parsing in only one place Miquel Raynal (Schneider Electric)
2026-07-17 17:28   ` sashiko-bot
2026-07-17 15:59 ` [PATCH v4 6/7] clk: Add support for clock nexus dt bindings Miquel Raynal (Schneider Electric)
2026-07-17 15:59 ` [PATCH v4 7/7] clk: tests: Add Kunit testing for nexus nodes Miquel Raynal (Schneider Electric)
2026-07-17 17:41   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260717171143.3C7831F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=miquel.raynal@bootlin.com \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox