Skip to content

Commit

Permalink
clk: en7523: Initialize num before accessing hws in en7523_register_c…
Browse files Browse the repository at this point in the history
…locks()

With the new __counted_by annotation in clk_hw_onecell_data, the "num"
struct member must be set before accessing the "hws" array. Failing to
do so will trigger a runtime warning when enabling CONFIG_UBSAN_BOUNDS
and CONFIG_FORTIFY_SOURCE.

Fixes: f316cdf ("clk: Annotate struct clk_hw_onecell_data with __counted_by")
Signed-off-by: Haoyu Li <lihaoyu499@gmail.com>
Link: https://lore.kernel.org/r/20241203142915.345523-1-lihaoyu499@gmail.com
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
  • Loading branch information
Haoyu Li authored and Stephen Boyd committed Dec 3, 2024
1 parent 2eb75f8 commit 52fd170
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/clk/clk-en7523.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,8 @@ static void en7523_register_clocks(struct device *dev, struct clk_hw_onecell_dat
u32 rate;
int i;

clk_data->num = EN7523_NUM_CLOCKS;

for (i = 0; i < ARRAY_SIZE(en7523_base_clks); i++) {
const struct en_clk_desc *desc = &en7523_base_clks[i];
u32 reg = desc->div_reg ? desc->div_reg : desc->base_reg;
Expand All @@ -525,8 +527,6 @@ static void en7523_register_clocks(struct device *dev, struct clk_hw_onecell_dat

hw = en7523_register_pcie_clk(dev, np_base);
clk_data->hws[EN7523_CLK_PCIE] = hw;

clk_data->num = EN7523_NUM_CLOCKS;
}

static int en7523_clk_hw_init(struct platform_device *pdev,
Expand Down

0 comments on commit 52fd170

Please sign in to comment.