Skip to content

Commit ea977d7

Browse files
Frank Oltmannswens
authored andcommitted
clk: sunxi-ng: common: Don't call hw_to_ccu_common on hw without common
In order to set the rate range of a hw sunxi_ccu_probe calls hw_to_ccu_common() assuming all entries in desc->ccu_clks are contained in a ccu_common struct. This assumption is incorrect and, in consequence, causes invalid pointer de-references. Remove the faulty call. Instead, add one more loop that iterates over the ccu_clks and sets the rate range, if required. Fixes: b914ec3 ("clk: sunxi-ng: common: Support minimum and maximum rate") Reported-by: Robert J. Pafford <[email protected]> Closes: https://lore.kernel.org/lkml/DM6PR01MB58047C810DDD5D0AE397CADFF7C22@DM6PR01MB5804.prod.exchangelabs.com/ Cc: [email protected] Signed-off-by: Frank Oltmanns <[email protected]> Tested-by: Robert J. Pafford <[email protected]> Link: https://lore.kernel.org/r/20240623-sunxi-ng_fix_common_probe-v1-1-7c97e32824a1@oltmanns.dev Signed-off-by: Chen-Yu Tsai <[email protected]>
1 parent 1613e60 commit ea977d7

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

drivers/clk/sunxi-ng/ccu_common.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ static int sunxi_ccu_probe(struct sunxi_ccu *ccu, struct device *dev,
132132

133133
for (i = 0; i < desc->hw_clks->num ; i++) {
134134
struct clk_hw *hw = desc->hw_clks->hws[i];
135-
struct ccu_common *common = hw_to_ccu_common(hw);
136135
const char *name;
137136

138137
if (!hw)
@@ -147,14 +146,21 @@ static int sunxi_ccu_probe(struct sunxi_ccu *ccu, struct device *dev,
147146
pr_err("Couldn't register clock %d - %s\n", i, name);
148147
goto err_clk_unreg;
149148
}
149+
}
150+
151+
for (i = 0; i < desc->num_ccu_clks; i++) {
152+
struct ccu_common *cclk = desc->ccu_clks[i];
153+
154+
if (!cclk)
155+
continue;
150156

151-
if (common->max_rate)
152-
clk_hw_set_rate_range(hw, common->min_rate,
153-
common->max_rate);
157+
if (cclk->max_rate)
158+
clk_hw_set_rate_range(&cclk->hw, cclk->min_rate,
159+
cclk->max_rate);
154160
else
155-
WARN(common->min_rate,
161+
WARN(cclk->min_rate,
156162
"No max_rate, ignoring min_rate of clock %d - %s\n",
157-
i, name);
163+
i, clk_hw_get_name(&cclk->hw));
158164
}
159165

160166
ret = of_clk_add_hw_provider(node, of_clk_hw_onecell_get,

0 commit comments

Comments
 (0)