clk: sprd: Hold reference returned by of_get_parent()
authorLiang He <windhl@126.com>
Mon, 4 Jul 2022 00:47:29 +0000 (08:47 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 26 Oct 2022 10:35:04 +0000 (12:35 +0200)
[ Upstream commit 91e6455bf715fb1558a0bf8f645ec1c131254a3c ]

We should hold the reference returned by of_get_parent() and use it
to call of_node_put() for refcount balance.

Fixes: f95e8c7923d1 ("clk: sprd: support to get regmap from parent node")
Signed-off-by: Liang He <windhl@126.com>
Link: https://lore.kernel.org/r/20220704004729.272481-1-windhl@126.com
Reviewed-by: Orson Zhai <orsonzhai@gmail.com>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/clk/sprd/common.c

index d620bbb..ce81e40 100644 (file)
@@ -41,7 +41,7 @@ int sprd_clk_regmap_init(struct platform_device *pdev,
 {
        void __iomem *base;
        struct device *dev = &pdev->dev;
-       struct device_node *node = dev->of_node;
+       struct device_node *node = dev->of_node, *np;
        struct regmap *regmap;
 
        if (of_find_property(node, "sprd,syscon", NULL)) {
@@ -50,9 +50,10 @@ int sprd_clk_regmap_init(struct platform_device *pdev,
                        pr_err("%s: failed to get syscon regmap\n", __func__);
                        return PTR_ERR(regmap);
                }
-       } else if (of_device_is_compatible(of_get_parent(dev->of_node),
-                          "syscon")) {
-               regmap = device_node_to_regmap(of_get_parent(dev->of_node));
+       } else if (of_device_is_compatible(np = of_get_parent(node), "syscon") ||
+                  (of_node_put(np), 0)) {
+               regmap = device_node_to_regmap(np);
+               of_node_put(np);
                if (IS_ERR(regmap)) {
                        dev_err(dev, "failed to get regmap from its parent.\n");
                        return PTR_ERR(regmap);