Skip to content

Commit bb4031b

Browse files
ambarusgregkh
authored andcommitted
clk: Skip clk provider registration when np is NULL
commit 6579c8d ("clk: Mark fwnodes when their clock provider is added") revealed that clk/bcm/clk-raspberrypi.c driver calls devm_of_clk_add_hw_provider(), with a NULL dev->of_node, which resulted in a NULL pointer dereference in of_clk_add_hw_provider() when calling fwnode_dev_initialized(). Returning 0 is reducing the if conditions in driver code and is being consistent with the CONFIG_OF=n inline stub that returns 0 when CONFIG_OF is disabled. The downside is that drivers will maybe register clkdev lookups when they don't need to and waste some memory. Fixes: 6579c8d ("clk: Mark fwnodes when their clock provider is added") Fixes: 3c9ea42 ("clk: Mark fwnodes when their clock provider is added/removed") Reported-by: Marek Szyprowski <[email protected]> Tested-by: Guenter Roeck <[email protected]> Tested-by: Nathan Chancellor <[email protected]> Reviewed-by: Stephen Boyd <[email protected]> Reviewed-by: Saravana Kannan <[email protected]> Reviewed-by: Nicolas Saenz Julienne <[email protected]> Signed-off-by: Tudor Ambarus <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 28ec344 commit bb4031b

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

drivers/clk/clk.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4540,6 +4540,9 @@ int of_clk_add_provider(struct device_node *np,
45404540
struct of_clk_provider *cp;
45414541
int ret;
45424542

4543+
if (!np)
4544+
return 0;
4545+
45434546
cp = kzalloc(sizeof(*cp), GFP_KERNEL);
45444547
if (!cp)
45454548
return -ENOMEM;
@@ -4579,6 +4582,9 @@ int of_clk_add_hw_provider(struct device_node *np,
45794582
struct of_clk_provider *cp;
45804583
int ret;
45814584

4585+
if (!np)
4586+
return 0;
4587+
45824588
cp = kzalloc(sizeof(*cp), GFP_KERNEL);
45834589
if (!cp)
45844590
return -ENOMEM;
@@ -4676,6 +4682,9 @@ void of_clk_del_provider(struct device_node *np)
46764682
{
46774683
struct of_clk_provider *cp;
46784684

4685+
if (!np)
4686+
return;
4687+
46794688
mutex_lock(&of_clk_mutex);
46804689
list_for_each_entry(cp, &of_clk_providers, link) {
46814690
if (cp->node == np) {

0 commit comments

Comments
 (0)