From: Justin Stitt <justinstitt@google.com>
To: Ben Cressey <ben@cressey.dev>
Cc: Junhui Liu <junhui.liu@pigmoral.tech>,
Manivannan Sadhasivam <mani@kernel.org>,
Nobuhiro Iwamatsu <nobuhiro.iwamatsu.x90@mail.toshiba>,
Michal Simek <michal.simek@amd.com>,
Stephen Boyd <sboyd@kernel.org>,
Brian Masney <bmasney+clk@redhat.com>,
Jerome Brunet <jbrunet+clk@baylibre.com>,
Paul Walmsley <pjw@kernel.org>,
Samuel Holland <samuel.holland@sifive.com>,
Emil Renner Berthing <kernel@esmil.dk>,
Hal Feng <hal.feng@starfivetech.com>,
Nathan Chancellor <nathan@kernel.org>,
Kees Cook <kees@kernel.org>,
Nick Desaulniers <ndesaulniers@google.com>,
Bill Wendling <morbo@google.com>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
linux-arm-kernel@lists.infradead.org, linux-clk@vger.kernel.org,
linux-riscv@lists.infradead.org, llvm@lists.linux.dev,
linux-hardening@vger.kernel.org,
Harry Austen <hpausten@protonmail.com>,
Changhuang Liang <changhuang.liang@starfivetech.com>,
stable@vger.kernel.org
Subject: Re: [PATCH 11/11] clk: zynqmp: Assign .num before accessing .hws
Date: Fri, 4 Dec 2026 11:40:06 -0800 [thread overview]
Message-ID: <axMXB0l1jXi6Ng0r@google.com> (raw)
In-Reply-To: <20261203-clk-onecell-count-order-v1-11-2b0e4e8d9ea6@cressey.dev>
Hi,
On Thu, Dec 03, 2026 at 04:15:49PM -0800, Ben Cressey wrote:
> hws[] is annotated with __counted_by(num), but zynqmp_register_clocks()
> fills it before zynqmp_clk_setup() sets num. The count is still zero
> with Clang 20 and 21, where kzalloc_flex() does not set it, and on v6.6
> to v6.19, which use kzalloc(). With __counted_by enabled,
> CONFIG_UBSAN_BOUNDS reports the accesses and CONFIG_UBSAN_TRAP makes the
> first one trap during probe.
>
> Set num right after the allocation.
>
> Found by an LLM-assisted check of __counted_by users.
>
> Fixes: f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with __counted_by")
> Cc: stable@vger.kernel.org
> Signed-off-by: Ben Cressey <ben@cressey.dev>
> ---
> drivers/clk/zynqmp/clkc.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/clk/zynqmp/clkc.c b/drivers/clk/zynqmp/clkc.c
> index d62f1901d0ab5..88d1281c284b8 100644
> --- a/drivers/clk/zynqmp/clkc.c
> +++ b/drivers/clk/zynqmp/clkc.c
> @@ -762,6 +762,7 @@ static int zynqmp_clk_setup(struct device_node *np)
> zynqmp_data = kzalloc_flex(*zynqmp_data, hws, clock_max_idx);
> if (!zynqmp_data)
> return -ENOMEM;
> + zynqmp_data->num = clock_max_idx;
>
> clock = kzalloc_objs(*clock, clock_max_idx);
> if (!clock) {
> @@ -772,7 +773,6 @@ static int zynqmp_clk_setup(struct device_node *np)
> zynqmp_get_clock_info();
> zynqmp_register_clocks(np);
>
> - zynqmp_data->num = clock_max_idx;
> return of_clk_add_hw_provider(np, of_clk_hw_onecell_get, zynqmp_data);
> }
>
>
> --
> 2.56.0
>
Reviewed-by: Justin Stitt <justinstitt@google.com>
Justin
WARNING: multiple messages have this Message-ID (diff)
From: Justin Stitt <justinstitt@google.com>
To: Ben Cressey <ben@cressey.dev>
Cc: Junhui Liu <junhui.liu@pigmoral.tech>,
Manivannan Sadhasivam <mani@kernel.org>,
Nobuhiro Iwamatsu <nobuhiro.iwamatsu.x90@mail.toshiba>,
Michal Simek <michal.simek@amd.com>,
Stephen Boyd <sboyd@kernel.org>,
Brian Masney <bmasney+clk@redhat.com>,
Jerome Brunet <jbrunet+clk@baylibre.com>,
Paul Walmsley <pjw@kernel.org>,
Samuel Holland <samuel.holland@sifive.com>,
Emil Renner Berthing <kernel@esmil.dk>,
Hal Feng <hal.feng@starfivetech.com>,
Nathan Chancellor <nathan@kernel.org>,
Kees Cook <kees@kernel.org>,
Nick Desaulniers <ndesaulniers@google.com>,
Bill Wendling <morbo@google.com>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
linux-arm-kernel@lists.infradead.org, linux-clk@vger.kernel.org,
linux-riscv@lists.infradead.org, llvm@lists.linux.dev,
linux-hardening@vger.kernel.org,
Harry Austen <hpausten@protonmail.com>,
Changhuang Liang <changhuang.liang@starfivetech.com>,
stable@vger.kernel.org
Subject: Re: [PATCH 11/11] clk: zynqmp: Assign .num before accessing .hws
Date: Fri, 4 Dec 2026 11:40:06 -0800 [thread overview]
Message-ID: <axMXB0l1jXi6Ng0r@google.com> (raw)
In-Reply-To: <20261203-clk-onecell-count-order-v1-11-2b0e4e8d9ea6@cressey.dev>
Hi,
On Thu, Dec 03, 2026 at 04:15:49PM -0800, Ben Cressey wrote:
> hws[] is annotated with __counted_by(num), but zynqmp_register_clocks()
> fills it before zynqmp_clk_setup() sets num. The count is still zero
> with Clang 20 and 21, where kzalloc_flex() does not set it, and on v6.6
> to v6.19, which use kzalloc(). With __counted_by enabled,
> CONFIG_UBSAN_BOUNDS reports the accesses and CONFIG_UBSAN_TRAP makes the
> first one trap during probe.
>
> Set num right after the allocation.
>
> Found by an LLM-assisted check of __counted_by users.
>
> Fixes: f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with __counted_by")
> Cc: stable@vger.kernel.org
> Signed-off-by: Ben Cressey <ben@cressey.dev>
> ---
> drivers/clk/zynqmp/clkc.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/clk/zynqmp/clkc.c b/drivers/clk/zynqmp/clkc.c
> index d62f1901d0ab5..88d1281c284b8 100644
> --- a/drivers/clk/zynqmp/clkc.c
> +++ b/drivers/clk/zynqmp/clkc.c
> @@ -762,6 +762,7 @@ static int zynqmp_clk_setup(struct device_node *np)
> zynqmp_data = kzalloc_flex(*zynqmp_data, hws, clock_max_idx);
> if (!zynqmp_data)
> return -ENOMEM;
> + zynqmp_data->num = clock_max_idx;
>
> clock = kzalloc_objs(*clock, clock_max_idx);
> if (!clock) {
> @@ -772,7 +773,6 @@ static int zynqmp_clk_setup(struct device_node *np)
> zynqmp_get_clock_info();
> zynqmp_register_clocks(np);
>
> - zynqmp_data->num = clock_max_idx;
> return of_clk_add_hw_provider(np, of_clk_hw_onecell_get, zynqmp_data);
> }
>
>
> --
> 2.56.0
>
Reviewed-by: Justin Stitt <justinstitt@google.com>
Justin
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2026-12-04 19:40 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 0:15 [PATCH 00/11] clk: Set __counted_by counts before filling the arrays Ben Cressey
2026-12-04 0:15 ` Ben Cressey
2026-12-04 0:15 ` [PATCH 01/11] clk: anlogic: Assign .num before accessing .hws Ben Cressey
2026-12-04 0:15 ` Ben Cressey
2026-12-04 19:17 ` Justin Stitt
2026-12-04 19:17 ` Justin Stitt
2026-12-04 0:15 ` [PATCH 02/11] clk: lmk04832: " Ben Cressey
2026-12-04 0:15 ` Ben Cressey
2026-12-04 19:21 ` Justin Stitt
2026-12-04 19:21 ` Justin Stitt
2026-12-04 0:15 ` [PATCH 03/11] clk: mmp: audio: " Ben Cressey
2026-12-04 0:15 ` Ben Cressey
2026-12-04 19:24 ` Justin Stitt
2026-12-04 19:24 ` Justin Stitt
2026-12-04 0:15 ` [PATCH 04/11] clk: sifive: prci: " Ben Cressey
2026-12-04 0:15 ` Ben Cressey
2026-12-04 19:26 ` Justin Stitt
2026-12-04 19:26 ` Justin Stitt
2026-12-04 0:15 ` [PATCH 05/11] clk: visconti: " Ben Cressey
2026-12-04 0:15 ` Ben Cressey
2026-12-04 19:29 ` Justin Stitt
2026-12-04 19:29 ` Justin Stitt
2026-12-04 0:15 ` [PATCH 06/11] clk: clocking-wizard: " Ben Cressey
2026-12-04 0:15 ` Ben Cressey
2026-12-04 19:29 ` Justin Stitt
2026-12-04 19:29 ` Justin Stitt
2026-12-04 0:15 ` [PATCH 07/11] clk: clps711x: " Ben Cressey
2026-12-04 0:15 ` Ben Cressey
2026-12-04 19:30 ` Justin Stitt
2026-12-04 19:30 ` Justin Stitt
2026-12-04 0:15 ` [PATCH 08/11] clk: starfive: jh7100: Assign .num_reg before accessing .reg Ben Cressey
2026-12-04 0:15 ` Ben Cressey
2026-12-04 19:31 ` Justin Stitt
2026-12-04 19:31 ` Justin Stitt
2026-12-04 0:15 ` [PATCH 09/11] clk: bm1880: Size .hws by the highest clock id Ben Cressey
2026-12-04 0:15 ` Ben Cressey
2026-12-04 19:38 ` Justin Stitt
2026-12-04 19:38 ` Justin Stitt
2026-12-04 0:15 ` [PATCH 10/11] clk: bm1880: Assign .num before accessing .hws Ben Cressey
2026-12-04 0:15 ` Ben Cressey
2026-12-04 19:39 ` Justin Stitt
2026-12-04 19:39 ` Justin Stitt
2026-12-04 0:15 ` [PATCH 11/11] clk: zynqmp: " Ben Cressey
2026-12-04 0:15 ` Ben Cressey
2026-12-04 19:40 ` Justin Stitt [this message]
2026-12-04 19:40 ` Justin Stitt
2026-12-04 23:49 ` [PATCH 00/11] clk: Set __counted_by counts before filling the arrays Kees Cook
2026-12-04 23:49 ` Kees Cook
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=axMXB0l1jXi6Ng0r@google.com \
--to=justinstitt@google.com \
--cc=ben@cressey.dev \
--cc=bmasney+clk@redhat.com \
--cc=changhuang.liang@starfivetech.com \
--cc=gustavoars@kernel.org \
--cc=hal.feng@starfivetech.com \
--cc=hpausten@protonmail.com \
--cc=jbrunet+clk@baylibre.com \
--cc=junhui.liu@pigmoral.tech \
--cc=kees@kernel.org \
--cc=kernel@esmil.dk \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=llvm@lists.linux.dev \
--cc=mani@kernel.org \
--cc=michal.simek@amd.com \
--cc=morbo@google.com \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=nobuhiro.iwamatsu.x90@mail.toshiba \
--cc=pjw@kernel.org \
--cc=samuel.holland@sifive.com \
--cc=sboyd@kernel.org \
--cc=stable@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.