mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] clk: cdce925: Size the PLL child name buffer for any int
@ 2026-10-14 16:11 Jerome Brunet
  2026-10-14 22:32 ` Brian Masney
       [not found] ` <1b153bce-a66a-45ee-a5c6-963ea6fb1c82.949ef384-8293-46b8-903f-40a477c056ae.1dd36950-a9a7-41bb-847b-d859a91bcfad@emailsignatures365.codetwo.com>
  0 siblings, 2 replies; 3+ messages in thread
From: Jerome Brunet @ 2026-10-14 16:11 UTC (permalink / raw)
  To: Stephen Boyd, Brian Masney, Jerome Brunet, Michael Turquette,
	Mike Looijmans
  Cc: linux-clk, linux-kernel, Jerome Brunet

The PLL child node name is built from "PLL%d" in a 6 byte stack buffer.
The PLL index is bounded by the chip's num_plls, at most 4, but GCC
cannot see that bound and, with W=1, warns that the formatted string
may not fit.

Make the buffer large enough to hold any int and use snprintf() with
sizeof() so the size stays tied to the declaration.

Fixes: 19fbbbbcd3a3 ("Add TI CDCE925 I2C controlled clock synthesizer driver")
Signed-off-by: Jerome Brunet <jbrunet@baylibre.com>
---
 drivers/clk/clk-cdce925.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/clk/clk-cdce925.c b/drivers/clk/clk-cdce925.c
index 4d49cc1659c0..56b69d4fe4c2 100644
--- a/drivers/clk/clk-cdce925.c
+++ b/drivers/clk/clk-cdce925.c
@@ -625,7 +625,12 @@ static int cdce925_probe(struct i2c_client *client)
 	int i;
 	int err;
 	struct device_node *np_output;
-	char child_name[6];
+	/*
+	 * The PLL number isn't a compile time constant so GCC can't infer
+	 * the number. Make the stack buffer large enough to hold any int
+	 * so Wformat-truncation does not complain.
+	 */
+	char child_name[15];
 	struct regmap_config config = {
 		.name = "configuration0",
 		.reg_bits = 8,
@@ -697,7 +702,7 @@ static int cdce925_probe(struct i2c_client *client)
 			dev_err(&client->dev, "Failed register PLL %d\n", i);
 			goto error;
 		}
-		sprintf(child_name, "PLL%d", i+1);
+		snprintf(child_name, sizeof(child_name), "PLL%d", i + 1);
 		np_output = of_get_child_by_name(node, child_name);
 		if (!np_output)
 			continue;

---
base-commit: a5929cbf1406eb3da217d4a182ff6c5b73f3ed91
base-tree: git://git.kernel.org/pub/scm/linux/kernel/git/clk/linux.git clk-next
change-id: 20261014-cdce925-truncate-child-name-a4d9db9cf003

Best regards,
--  
Jerome


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] clk: cdce925: Size the PLL child name buffer for any int
  2026-10-14 16:11 [PATCH] clk: cdce925: Size the PLL child name buffer for any int Jerome Brunet
@ 2026-10-14 22:32 ` Brian Masney
       [not found] ` <1b153bce-a66a-45ee-a5c6-963ea6fb1c82.949ef384-8293-46b8-903f-40a477c056ae.1dd36950-a9a7-41bb-847b-d859a91bcfad@emailsignatures365.codetwo.com>
  1 sibling, 0 replies; 3+ messages in thread
From: Brian Masney @ 2026-10-14 22:32 UTC (permalink / raw)
  To: Stephen Boyd, Brian Masney, Jerome Brunet, Michael Turquette,
	Mike Looijmans, Jerome Brunet
  Cc: linux-clk, linux-kernel


On Wed, 14 Oct 2026 18:11:53 +0200, Jerome Brunet wrote:
> clk: cdce925: Size the PLL child name buffer for any int

Applied, thanks!

[1/1] clk: cdce925: Size the PLL child name buffer for any int
      commit: bca4927f760a77cd59f394b0b201f48c48e402c8

Best regards,
-- 
Brian Masney <masneyb@kernel.org>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] clk: cdce925: Size the PLL child name buffer for any int
       [not found]   ` <a61f0060-c43c-4c0f-afcd-1db262cf62ae@topic.nl>
@ 2026-10-15 10:19     ` Jerome Brunet
  0 siblings, 0 replies; 3+ messages in thread
From: Jerome Brunet @ 2026-10-15 10:19 UTC (permalink / raw)
  To: Mike Looijmans, Stephen Boyd, Brian Masney, Jerome Brunet,
	Michael Turquette
  Cc: linux-clk, linux-kernel

On jeu. 15 oct. 2026 at 11:18, Mike Looijmans <mike.looijmans@topic.nl> wrote:

> Met vriendelijke groet / kind regards,
>
> Mike Looijmans
> System Expert
>
> [cid:topic_3fa16e61-8444-4c42-bbdd-4da663de69ef.png]
> TOPIC Embedded Products B.V.
> Materiaalweg 4
> 5681 RJ Best    T:      +31 (0) 499 33 69 69
> The Netherlands E:      mike.looijmans@topic.nl<mailto:mike.looijmans@topic.nl>
>         W:      www.topic.nl<http://www.topic.nl>
>         L:      LinkedIn<https://www.linkedin.com/company/topic-embedded-systems>
>
> Please consider the environment before printing this e-mail
>
> On 10/14/26 18:11, Jerome Brunet wrote:
>
> The PLL child node name is built from "PLL%d" in a 6 byte stack buffer.
> The PLL index is bounded by the chip's num_plls, at most 4, but GCC
> cannot see that bound and, with W=1, warns that the formatted string
> may not fit.
>
> Make the buffer large enough to hold any int and use snprintf() with
> sizeof() so the size stays tied to the declaration.
>
> Fixes: 19fbbbbcd3a3 ("Add TI CDCE925 I2C controlled clock synthesizer driver")
> Signed-off-by: Jerome Brunet <jbrunet@baylibre.com><mailto:jbrunet@baylibre.com>
> ---
>  drivers/clk/clk-cdce925.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/clk/clk-cdce925.c b/drivers/clk/clk-cdce925.c
> index 4d49cc1659c0..56b69d4fe4c2 100644
> --- a/drivers/clk/clk-cdce925.c
> +++ b/drivers/clk/clk-cdce925.c
> @@ -625,7 +625,12 @@ static int cdce925_probe(struct i2c_client *client)
>         int i;
>         int err;
>         struct device_node *np_output;
> -       char child_name[6];
> +       /*
> +        * The PLL number isn't a compile time constant so GCC can't infer
> +        * the number. Make the stack buffer large enough to hold any int
> +        * so Wformat-truncation does not complain.
> +        */
> +       char child_name[15];
>         struct regmap_config config = {
>                 .name = "configuration0",
>                 .reg_bits = 8,
> @@ -697,7 +702,7 @@ static int cdce925_probe(struct i2c_client *client)
>                         dev_err(&client->dev, "Failed register PLL %d\n", i);
>                         goto error;
>                 }
> -               sprintf(child_name, "PLL%d", i+1);
> +               snprintf(child_name, sizeof(child_name), "PLL%d", i + 1);
>
> This would also avoid the warning, without using a larger stack:
>
> sprintf(child_name, "PLL%c", i + '1');
>

If you keep snprintf and properly cast i, possibly.
Feel free to send a follow-up change.

NOTE: please reply to PATCHes using plain text emails.

>
>
>
>                 np_output = of_get_child_by_name(node, child_name);
>                 if (!np_output)
>                         continue;
>
> ---
> base-commit: a5929cbf1406eb3da217d4a182ff6c5b73f3ed91
> base-tree: git://git.kernel.org/pub/scm/linux/kernel/git/clk/linux.git clk-next
> change-id: 20261014-cdce925-truncate-child-name-a4d9db9cf003
>
> Best regards,
> --
> Jerome
>
>
>

-- 
Jerome

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-10-15 10:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-14 16:11 [PATCH] clk: cdce925: Size the PLL child name buffer for any int Jerome Brunet
2026-10-14 22:32 ` Brian Masney
     [not found] ` <1b153bce-a66a-45ee-a5c6-963ea6fb1c82.949ef384-8293-46b8-903f-40a477c056ae.1dd36950-a9a7-41bb-847b-d859a91bcfad@emailsignatures365.codetwo.com>
     [not found]   ` <a61f0060-c43c-4c0f-afcd-1db262cf62ae@topic.nl>
2026-10-15 10:19     ` Jerome Brunet

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®