linux/drivers/clk/bcm
Nathan Chancellor 6dc445c190 clk: bcm: rpi: Assign ->num before accessing ->hws
Commit f316cdff8d ("clk: Annotate struct clk_hw_onecell_data with
__counted_by") annotated the hws member of 'struct clk_hw_onecell_data'
with __counted_by, which informs the bounds sanitizer about the number
of elements in hws, so that it can warn when hws is accessed out of
bounds. As noted in that change, the __counted_by member must be
initialized with the number of elements before the first array access
happens, otherwise there will be a warning from each access prior to the
initialization because the number of elements is zero. This occurs in
raspberrypi_discover_clocks() due to ->num being assigned after ->hws
has been accessed:

  UBSAN: array-index-out-of-bounds in drivers/clk/bcm/clk-raspberrypi.c:374:4
  index 3 is out of range for type 'struct clk_hw *[] __counted_by(num)' (aka 'struct clk_hw *[]')

Move the ->num initialization to before the first access of ->hws, which
clears up the warning.

Cc: stable@vger.kernel.org
Fixes: f316cdff8d ("clk: Annotate struct clk_hw_onecell_data with __counted_by")
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Link: https://lore.kernel.org/r/20240425-cbl-bcm-assign-counted-by-val-before-access-v1-2-e2db3b82d5ef@kernel.org
Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
2024-04-29 17:03:20 -07:00
..
clk-bcm63xx-gate.c clk: Explicitly include correct DT includes 2023-07-19 13:13:16 -07:00
clk-bcm63xx.c treewide: Replace GPLv2 boilerplate/reference with SPDX - gpl-2.0_30.RULE (part 1) 2022-06-10 14:51:35 +02:00
clk-bcm281xx.c treewide: Replace GPLv2 boilerplate/reference with SPDX - gpl-2.0_30.RULE (part 1) 2022-06-10 14:51:35 +02:00
clk-bcm2711-dvp.c clk: bcm: dvp: Assign ->num before accessing ->hws 2024-04-29 17:03:08 -07:00
clk-bcm2835-aux.c kbuild, clk: bcm2835: remove MODULE_LICENSE in non-modules 2023-03-06 11:29:15 -08:00
clk-bcm2835.c clk: Explicitly include correct DT includes 2023-07-19 13:13:16 -07:00
clk-bcm21664.c treewide: Replace GPLv2 boilerplate/reference with SPDX - gpl-2.0_30.RULE (part 1) 2022-06-10 14:51:35 +02:00
clk-bcm53573-ilp.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
clk-bcm63268-timer.c clk: bcm: Add BCM63268 timer clock and reset driver 2023-03-27 13:18:07 -07:00
clk-cygnus.c treewide: Replace GPLv2 boilerplate/reference with SPDX - gpl-2.0_30.RULE (part 1) 2022-06-10 14:51:35 +02:00
clk-hr2.c treewide: Replace GPLv2 boilerplate/reference with SPDX - gpl-2.0_30.RULE (part 1) 2022-06-10 14:51:35 +02:00
clk-iproc-armpll.c treewide: Replace GPLv2 boilerplate/reference with SPDX - gpl-2.0_30.RULE (part 1) 2022-06-10 14:51:35 +02:00
clk-iproc-asiu.c treewide: Replace GPLv2 boilerplate/reference with SPDX - gpl-2.0_30.RULE (part 1) 2022-06-10 14:51:35 +02:00
clk-iproc-pll.c clk: iproc: Do not rely on node name for correct PLL setup 2022-09-28 18:33:08 -07:00
clk-iproc.h treewide: Replace GPLv2 boilerplate/reference with SPDX - gpl-2.0_30.RULE (part 1) 2022-06-10 14:51:35 +02:00
clk-kona-setup.c treewide: Replace GPLv2 boilerplate/reference with SPDX - gpl-2.0_30.RULE (part 1) 2022-06-10 14:51:35 +02:00
clk-kona.c treewide: Replace GPLv2 boilerplate/reference with SPDX - gpl-2.0_30.RULE (part 1) 2022-06-10 14:51:35 +02:00
clk-kona.h treewide: Replace GPLv2 boilerplate/reference with SPDX - gpl-2.0_30.RULE (part 1) 2022-06-10 14:51:35 +02:00
clk-ns2.c treewide: Replace GPLv2 boilerplate/reference with SPDX - gpl-2.0_30.RULE (part 1) 2022-06-10 14:51:35 +02:00
clk-nsp.c treewide: Replace GPLv2 boilerplate/reference with SPDX - gpl-2.0_30.RULE (part 1) 2022-06-10 14:51:35 +02:00
clk-raspberrypi.c clk: bcm: rpi: Assign ->num before accessing ->hws 2024-04-29 17:03:20 -07:00
clk-sr.c clk: Explicitly include correct DT includes 2023-07-19 13:13:16 -07:00
Kconfig clk: bcm: Add BCM63268 timer clock and reset driver 2023-03-27 13:18:07 -07:00
Makefile clk: bcm: Add BCM63268 timer clock and reset driver 2023-03-27 13:18:07 -07:00