Skip to contentSkip to conversation

clk: handle get_parent callbacks returning an error

PATCH Applied Ahmad Fatoum 2 participants 2 messages Oct 25 – Oct 26 Common clk

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clk: handle get_parent callbacks returning an error

A mux with a value table returns -EINVAL from get_parent when the register holds a value missing from the table. clk_get_parent() only rejected indices >= num_parents, so -EINVAL went on to index the parents array as u8 234 and clk_dump crashed on the Amlogic G12 clock controller.

Let's return -ENODEV for negative indices as well.

---
 drivers/clk/clk.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/clk/clk.c +2 -1
index 99f995fb0224..1d6aaa46d9b1 100644
@@ -382,7 +382,8 @@ struct clk *clk_get_parent(struct clk *clk)
 
 		idx = clk->ops->get_parent(hw);
 
-		if (idx >= clk->num_parents)
+		/* an error means the register selects no known parent */
+		if (idx < 0 || idx >= clk->num_parents)
 			return ERR_PTR(-ENODEV);
 	} else {
 		idx = 0;
Signature · 1 line
2.47.3
Applied
#1 lore raw
Quoted 9 lines · Ahmad Fatoum

A mux with a value table returns -EINVAL from get_parent when the register holds a value missing from the table. clk_get_parent() only rejected indices >= num_parents, so -EINVAL went on to index the parents array as u8 234 and clk_dump crashed on the Amlogic G12 clock controller.

Let's return -ENODEV for negative indices as well.

[...]

Applied, thanks!

[1/1] clk: handle get_parent callbacks returning an error
https://git.pengutronix.de/cgit/barebox/commit/?id=22f58f5dea50 (link may not be stable)

Best regards,

Signature · 1 line
Sascha Hauer <[email protected]>