[PATCH 2/2] clk: bcm: rpi: Do not call devm_of_clk_add_hw_provider with a NULL dev->of_node

Tudor Ambarus
2021-04-23T17:14:05Z

devm_of_clk_add_hw_provider() expects, as the "_of_" string indicates,
a non NULL dev->of_node, otherwise it will return -ENODEV.
Since this driver can be probed either through the old-fashioned
platform device registration or through a DT node that is a child of the
firmware node, call devm_of_clk_add_hw_provider() only when the DT node
is present.

Reported-by: Marek Szyprowski <m.szyprowski@samsung.com>
Fixes: 6579c8d97ad7 ("clk: Mark fwnodes when their clock provider is added")
Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
drivers/clk/bcm/clk-raspberrypi.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/clk/bcm/clk-raspberrypi.c b/drivers/clk/bcm/clk-raspberrypi.c
index dd3b71eafabf..84a4e14babff 100644
--- a/drivers/clk/bcm/clk-raspberrypi.c
+++ b/drivers/clk/bcm/clk-raspberrypi.c
@@ -337,10 +337,12 @@ static int raspberrypi_clk_probe(struct platform_device *pdev)
if (ret)
return ret;

- ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,
- clk_data);
- if (ret)
- return ret;
+ if (dev->of_node) {
+ ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,
+ clk_data);
+ if (ret)
+ return ret;
+ }

rpi->cpufreq = platform_device_register_data(dev, "raspberrypi-cpufreq",
-1, NULL, 0);
--
2.25.1