Skip to content

Commit 24876f0

Browse files
xdarklightbebarino
authored andcommitted
clk: Fix potential NULL dereference in clk_fetch_parent_index()
Don't compare the parent clock name with a NULL name in the clk_parent_map. This prevents a kernel crash when passing NULL core->parents[i].name to strcmp(). An example which triggered this is a mux clock with four parents when each of them is referenced in the clock driver using clk_parent_data.fw_name and then calling clk_set_parent(clk, 3rd_parent) on this mux. In this case the first parent is also the HW default so core->parents[i].hw is populated when the clock is registered. Calling clk_set_parent(clk, 3rd_parent) will then go through all parents and skip the first parent because it's hw pointer doesn't match. For the second parent no hw pointer is cached yet and clk_core_get(core, 1) returns a non-matching pointer (which is correct because we are comparing the second with the third parent). Comparing the result of clk_core_get(core, 2) with the requested parent gives a match. However we don't reach this point because right after the clk_core_get(core, 1) mismatch the old code tried to !strcmp(parent->name, NULL) (where the second argument is actually core->parents[i].name, but that was never populated by the clock driver). Signed-off-by: Martin Blumenstingl <[email protected]> Link: https://lkml.kernel.org/r/[email protected] Fixes: fc0c209 ("clk: Allow parents to be specified without string names") Signed-off-by: Stephen Boyd <[email protected]>
1 parent 4f8c6ab commit 24876f0

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/clk/clk.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1654,7 +1654,8 @@ static int clk_fetch_parent_index(struct clk_core *core,
16541654
break;
16551655

16561656
/* Fallback to comparing globally unique names */
1657-
if (!strcmp(parent->name, core->parents[i].name))
1657+
if (core->parents[i].name &&
1658+
!strcmp(parent->name, core->parents[i].name))
16581659
break;
16591660
}
16601661

0 commit comments

Comments
 (0)