From: Liang He <windhl@126.com>
To: mturquette@baylibre.com, sboyd@kernel.org, orsonzhai@gmail.com,
baolin.wang7@gmail.com, zhang.lyra@gmail.com,
linux-clk@vger.kernel.org, windhl@126.com
Subject: [PATCH] clk/sprd: Hold reference returned by of_get_parent()
Date: Fri, 24 Jun 2022 18:38:09 +0800 [thread overview]
Message-ID: <20220624103809.4167753-1-windhl@126.com> (raw)
We should hold the reference returned by of_get_parent() and use it
to call of_node_out() for refcount balance.
Fixes: f95e8c7923d1 ("clk: sprd: support to get regmap from parent node")
Signed-off-by: Liang He <windhl@126.com>
---
these bugs are found in 5.19rc2
these bugs are confirmed not fixed by lore.kernel.org
these bugs are compiled tested in 5.19rc2 with at91_dt_defconfig
drivers/clk/sprd/common.c | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/drivers/clk/sprd/common.c b/drivers/clk/sprd/common.c
index d620bbbcdfc8..08c1d7a9ec8b 100644
--- a/drivers/clk/sprd/common.c
+++ b/drivers/clk/sprd/common.c
@@ -41,35 +41,41 @@ 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;
+ np = of_get_parent(dev->of_node);
if (of_find_property(node, "sprd,syscon", NULL)) {
regmap = syscon_regmap_lookup_by_phandle(node, "sprd,syscon");
if (IS_ERR(regmap)) {
pr_err("%s: failed to get syscon regmap\n", __func__);
+ of_node_put(np);
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, "syscon")) {
+ regmap = device_node_to_regmap(np);
if (IS_ERR(regmap)) {
+ of_node_put(np);
dev_err(dev, "failed to get regmap from its parent.\n");
return PTR_ERR(regmap);
}
} else {
base = devm_platform_ioremap_resource(pdev, 0);
- if (IS_ERR(base))
+ if (IS_ERR(base)) {
+ of_node_put(np);
return PTR_ERR(base);
+ }
regmap = devm_regmap_init_mmio(&pdev->dev, base,
&sprdclk_regmap_config);
if (IS_ERR(regmap)) {
+ of_node_put(np);
pr_err("failed to init regmap\n");
return PTR_ERR(regmap);
}
}
+ of_node_put(np);
sprd_clk_set_regmap(desc, regmap);
return 0;
--
2.25.1
next reply other threads:[~2022-06-24 10:38 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-24 10:38 Liang He [this message]
2022-06-25 8:36 ` [PATCH] clk/sprd: Hold reference returned by of_get_parent() Orson Zhai
2022-06-25 15:32 ` Liang He
2022-06-26 3:32 ` Orson Zhai
2022-06-26 4:03 ` Liang He
2022-06-27 7:55 ` Orson Zhai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220624103809.4167753-1-windhl@126.com \
--to=windhl@126.com \
--cc=baolin.wang7@gmail.com \
--cc=linux-clk@vger.kernel.org \
--cc=mturquette@baylibre.com \
--cc=orsonzhai@gmail.com \
--cc=sboyd@kernel.org \
--cc=zhang.lyra@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox