Skip to content

Commit ceb87a3

Browse files
alessandrocarminatibebarino
authored andcommitted
clk: Sanitize possible_parent_show to Handle Return Value of of_clk_get_parent_name
In the possible_parent_show function, ensure proper handling of the return value from of_clk_get_parent_name to prevent potential issues arising from a NULL return. The current implementation invokes seq_puts directly on the result of of_clk_get_parent_name without verifying the return value, which can lead to kernel panic if the function returns NULL. This patch addresses the concern by introducing a check on the return value of of_clk_get_parent_name. If the return value is not NULL, the function proceeds to call seq_puts, providing the returned value as argument. However, if of_clk_get_parent_name returns NULL, the function provides a static string as argument, avoiding the panic. Fixes: 1ccc0dd ("clk: Use seq_puts() in possible_parent_show()") Reported-by: Philip Daly <[email protected]> Signed-off-by: Alessandro Carminati (Red Hat) <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Stephen Boyd <[email protected]>
1 parent 601cb6d commit ceb87a3

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

drivers/clk/clk.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3416,6 +3416,7 @@ static void possible_parent_show(struct seq_file *s, struct clk_core *core,
34163416
unsigned int i, char terminator)
34173417
{
34183418
struct clk_core *parent;
3419+
const char *name = NULL;
34193420

34203421
/*
34213422
* Go through the following options to fetch a parent's name.
@@ -3430,18 +3431,20 @@ static void possible_parent_show(struct seq_file *s, struct clk_core *core,
34303431
* registered (yet).
34313432
*/
34323433
parent = clk_core_get_parent_by_index(core, i);
3433-
if (parent)
3434+
if (parent) {
34343435
seq_puts(s, parent->name);
3435-
else if (core->parents[i].name)
3436+
} else if (core->parents[i].name) {
34363437
seq_puts(s, core->parents[i].name);
3437-
else if (core->parents[i].fw_name)
3438+
} else if (core->parents[i].fw_name) {
34383439
seq_printf(s, "<%s>(fw)", core->parents[i].fw_name);
3439-
else if (core->parents[i].index >= 0)
3440-
seq_puts(s,
3441-
of_clk_get_parent_name(core->of_node,
3442-
core->parents[i].index));
3443-
else
3444-
seq_puts(s, "(missing)");
3440+
} else {
3441+
if (core->parents[i].index >= 0)
3442+
name = of_clk_get_parent_name(core->of_node, core->parents[i].index);
3443+
if (!name)
3444+
name = "(missing)";
3445+
3446+
seq_puts(s, name);
3447+
}
34453448

34463449
seq_putc(s, terminator);
34473450
}

0 commit comments

Comments
 (0)