Commit bb4031b8 authored by Tudor Ambarus's avatar Tudor Ambarus Committed by Greg Kroah-Hartman

clk: Skip clk provider registration when np is NULL

commit 6579c8d9 ("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: 6579c8d9 ("clk: Mark fwnodes when their clock provider is added")
Fixes: 3c9ea428 ("clk: Mark fwnodes when their clock provider is added/removed")
Reported-by: default avatarMarek Szyprowski <m.szyprowski@samsung.com>
Tested-by: default avatarGuenter Roeck <linux@roeck-us.net>
Tested-by: default avatarNathan Chancellor <nathan@kernel.org>
Reviewed-by: default avatarStephen Boyd <sboyd@kernel.org>
Reviewed-by: default avatarSaravana Kannan <saravanak@google.com>
Reviewed-by: default avatarNicolas Saenz Julienne <nsaenz@kernel.org>
Signed-off-by: default avatarTudor Ambarus <tudor.ambarus@microchip.com>
Link: https://lore.kernel.org/r/20210426065618.588144-1-tudor.ambarus@microchip.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 28ec344b
...@@ -4540,6 +4540,9 @@ int of_clk_add_provider(struct device_node *np, ...@@ -4540,6 +4540,9 @@ int of_clk_add_provider(struct device_node *np,
struct of_clk_provider *cp; struct of_clk_provider *cp;
int ret; int ret;
if (!np)
return 0;
cp = kzalloc(sizeof(*cp), GFP_KERNEL); cp = kzalloc(sizeof(*cp), GFP_KERNEL);
if (!cp) if (!cp)
return -ENOMEM; return -ENOMEM;
...@@ -4579,6 +4582,9 @@ int of_clk_add_hw_provider(struct device_node *np, ...@@ -4579,6 +4582,9 @@ int of_clk_add_hw_provider(struct device_node *np,
struct of_clk_provider *cp; struct of_clk_provider *cp;
int ret; int ret;
if (!np)
return 0;
cp = kzalloc(sizeof(*cp), GFP_KERNEL); cp = kzalloc(sizeof(*cp), GFP_KERNEL);
if (!cp) if (!cp)
return -ENOMEM; return -ENOMEM;
...@@ -4676,6 +4682,9 @@ void of_clk_del_provider(struct device_node *np) ...@@ -4676,6 +4682,9 @@ void of_clk_del_provider(struct device_node *np)
{ {
struct of_clk_provider *cp; struct of_clk_provider *cp;
if (!np)
return;
mutex_lock(&of_clk_mutex); mutex_lock(&of_clk_mutex);
list_for_each_entry(cp, &of_clk_providers, link) { list_for_each_entry(cp, &of_clk_providers, link) {
if (cp->node == np) { if (cp->node == np) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment