From: Stephen Boyd <sboyd@kernel.org>
To: Binbin Zhou <zhoubb.aaron@gmail.com>,
Binbin Zhou <zhoubinbin@loongson.cn>,
Huacai Chen <chenhuacai@loongson.cn>,
Michael Turquette <mturquette@baylibre.com>,
Yinbo Zhu <zhuyinbo@loongson.cn>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: Huacai Chen <chenhuacai@kernel.org>,
linux-clk@vger.kernel.org, Xuerui Wang <kernel@xen0n.name>,
loongarch@lists.linux.dev, Binbin Zhou <zhoubinbin@loongson.cn>,
stable@vger.kernel.org
Subject: Re: [PATCH] clk: clk-loongson2: Fix the number count of clk provider
Date: Tue, 07 Jan 2025 13:25:48 -0800 [thread overview]
Message-ID: <526d7ad1f0b299145ab676900f81ba1a.sboyd@kernel.org> (raw)
In-Reply-To: <20241225060600.3094154-1-zhoubinbin@loongson.cn>
Quoting Binbin Zhou (2024-12-24 22:05:59)
> Since commit 02fb4f008433 ("clk: clk-loongson2: Fix potential buffer
> overflow in flexible-array member access"), the clk provider register is
> failed.
>
> The count of `clks_num` is shown below:
>
> for (p = data; p->name; p++)
> clks_num++;
>
> In fact, `clks_num` represents the number of SoC clocks and should be
> expressed as the maximum value of the clock binding id in use (p->id + 1).
>
> Now we fix it to avoid the following error when trying to register a clk
> provider:
>
> [ 13.409595] of_clk_hw_onecell_get: invalid index 17
>
> Fixes: 02fb4f008433 ("clk: clk-loongson2: Fix potential buffer overflow in flexible-array member access")
> Cc: stable@vger.kernel.org
> Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
> ---
It's common practice to Cc the author of a patch in Fixes. Please do it
next time.
> drivers/clk/clk-loongson2.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/clk/clk-loongson2.c b/drivers/clk/clk-loongson2.c
> index 6bf51d5a49a1..b1b2038acd0b 100644
> --- a/drivers/clk/clk-loongson2.c
> +++ b/drivers/clk/clk-loongson2.c
> @@ -294,7 +294,7 @@ static int loongson2_clk_probe(struct platform_device *pdev)
> return -EINVAL;
>
> for (p = data; p->name; p++)
> - clks_num++;
> + clks_num = max(clks_num, p->id + 1);
NULL is a valid clk. Either fill the onecell data with -ENOENT error
pointers, or stop using it and implement a custom version of
of_clk_hw_onecell_get() that doesn't allow invalid clks to be requested
from this provider.
>
> clp = devm_kzalloc(dev, struct_size(clp, clk_data.hws, clks_num),
> GFP_KERNEL);
next prev parent reply other threads:[~2025-01-07 21:25 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-25 6:05 [PATCH] clk: clk-loongson2: Fix the number count of clk provider Binbin Zhou
2025-01-07 21:25 ` Stephen Boyd [this message]
2025-01-08 1:41 ` Binbin Zhou
2025-01-08 19:20 ` Stephen Boyd
2025-01-09 3:06 ` Binbin Zhou
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=526d7ad1f0b299145ab676900f81ba1a.sboyd@kernel.org \
--to=sboyd@kernel.org \
--cc=chenhuacai@kernel.org \
--cc=chenhuacai@loongson.cn \
--cc=gustavoars@kernel.org \
--cc=kernel@xen0n.name \
--cc=linux-clk@vger.kernel.org \
--cc=loongarch@lists.linux.dev \
--cc=mturquette@baylibre.com \
--cc=stable@vger.kernel.org \
--cc=zhoubb.aaron@gmail.com \
--cc=zhoubinbin@loongson.cn \
--cc=zhuyinbo@loongson.cn \
/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