clk: Skip clk provider registration when np is NULL

commit 6579c8d97ad7 ("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: 6579c8d97ad7 ("clk: Mark fwnodes when their clock provider is added")
Fixes: 3c9ea42802a1 ("clk: Mark fwnodes when their clock provider is added/removed")
Reported-by: Marek Szyprowski <m.szyprowski@samsung.com>
Tested-by: Guenter Roeck <linux@roeck-us.net>
Tested-by: Nathan Chancellor <nathan@kernel.org>
Reviewed-by: Stephen Boyd <sboyd@kernel.org>
Reviewed-by: Saravana Kannan <saravanak@google.com>
Reviewed-by: Nicolas Saenz Julienne <nsaenz@kernel.org>
Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
Link: https://lore.kernel.org/r/20210426065618.588144-1-tudor.ambarus@microchip.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by Tudor Ambarus and committed by Greg Kroah-Hartman bb4031b8 28ec344b

Changed files
+9
drivers
clk
+9
drivers/clk/clk.c
··· 4540 4540 struct of_clk_provider *cp; 4541 4541 int ret; 4542 4542 4543 + if (!np) 4544 + return 0; 4545 + 4543 4546 cp = kzalloc(sizeof(*cp), GFP_KERNEL); 4544 4547 if (!cp) 4545 4548 return -ENOMEM; ··· 4581 4578 { 4582 4579 struct of_clk_provider *cp; 4583 4580 int ret; 4581 + 4582 + if (!np) 4583 + return 0; 4584 4584 4585 4585 cp = kzalloc(sizeof(*cp), GFP_KERNEL); 4586 4586 if (!cp) ··· 4681 4675 void of_clk_del_provider(struct device_node *np) 4682 4676 { 4683 4677 struct of_clk_provider *cp; 4678 + 4679 + if (!np) 4680 + return; 4684 4681 4685 4682 mutex_lock(&of_clk_mutex); 4686 4683 list_for_each_entry(cp, &of_clk_providers, link) {