Skip to contentSkip to conversation

clk/meson: Hold reference returned by of_get_parent()

PATCH Superseded Liang He 2 participants 3 messages Jun 24, 2022 – Jun 26, 2022

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Liang He

author
#0 lore raw

PATCH 1/1 clk/meson: Hold reference returned by of_get_parent()

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

Fixes 88e2da81241e ("clk: meson: aoclk: refactor common code into dedicated file")
Fixes 6682bd4d443f ("clk: meson: factorise meson64 peripheral clock controller drivers")
Fixes bb6eddd1d28c ("clk: meson: meson8b: use the HHI syscon if available")

---
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/meson/meson-aoclk.c | 5 ++++-
 drivers/clk/meson/meson-eeclk.c | 5 ++++-
 drivers/clk/meson/meson8b.c     | 5 ++++-
 3 files changed, 12 insertions(+), 3 deletions(-)
drivers/clk/meson/meson-aoclk.c +4 -1
index 27cd2c1f3f61..434cd8f9de82 100644
@@ -38,6 +38,7 @@ int meson_aoclkc_probe(struct platform_device *pdev)
 	struct meson_aoclk_reset_controller *rstc;
 	struct meson_aoclk_data *data;
 	struct device *dev = &pdev->dev;
+	struct device_node *np;
 	struct regmap *regmap;
 	int ret, clkid;
 
@@ -49,7 +50,9 @@ int meson_aoclkc_probe(struct platform_device *pdev)
 	if (!rstc)
 		return -ENOMEM;
 
-	regmap = syscon_node_to_regmap(of_get_parent(dev->of_node));
+	np = of_get_parent(dev->of_node);
+	regmap = syscon_node_to_regmap(np);
+	of_node_put(np);
 	if (IS_ERR(regmap)) {
 		dev_err(dev, "failed to get regmap\n");
 		return PTR_ERR(regmap);
drivers/clk/meson/meson-eeclk.c +4 -1
index 8d5a5dab955a..0e5e6b57eb20 100644
@@ -18,6 +18,7 @@ int meson_eeclkc_probe(struct platform_device *pdev)
 {
 	const struct meson_eeclkc_data *data;
 	struct device *dev = &pdev->dev;
+	struct device_node *np;
 	struct regmap *map;
 	int ret, i;
 
@@ -26,7 +27,9 @@ int meson_eeclkc_probe(struct platform_device *pdev)
 		return -EINVAL;
 
 	/* Get the hhi system controller node */
-	map = syscon_node_to_regmap(of_get_parent(dev->of_node));
+	np = of_get_parent(dev->of_node);
+	map = syscon_node_to_regmap(np);
+	of_node_put(np);
 	if (IS_ERR(map)) {
 		dev_err(dev,
 			"failed to get HHI regmap\n");
drivers/clk/meson/meson8b.c +4 -1
index 8f3b7a94a667..54188319f349 100644
@@ -3796,8 +3796,11 @@ static void __init meson8b_clkc_init_common(struct device_node *np,
 	struct clk *notifier_clk;
 	struct regmap *map;
 	int i, ret;
+	struct device_node *tp;
 
-	map = syscon_node_to_regmap(of_get_parent(np));
+	tp = of_get_parent(np);
+	map = syscon_node_to_regmap(tp);
+	of_node_put(tp);
 	if (IS_ERR(map)) {
 		pr_err("failed to get HHI regmap - Trying obsolete regs\n");
 		return;
Signature · 1 line
2.25.1
#1 lore raw

Hello,

thank you for submitting this patch!

On Fri, Jun 24, 2022 at 12:28 PM Liang He <[email protected]> wrote:
[...]

Quoted 1 line

these bugs are compiled tested in 5.19rc2 with at91_dt_defconfig

Please note that you're changing some drivers which are only in the arch/arm/configs/multi_v7_defconfig while others are only in arch/arm64/configs/defconfig
I think at91_dt_defconfig will not compile any of the drivers below

[...]

drivers/clk/meson/meson8b.c static void __init meson8b_clkc_init_common(struct device_node *np, · line 3799

Quoted 9 lines
drivers/clk/meson/meson8b.c +1 -0
index 8f3b7a94a667..54188319f349 100644
@@ -3796,8 +3796,11 @@ static void __init meson8b_clkc_init_common(struct device_node *np,
        struct clk *notifier_clk;
        struct regmap *map;
        int i, ret;
+       struct device_node *tp;

This function uses reverse christmas tree sorting, so the longest line goes on top while the shortest should stay on the bottom. Can you please explain what "tp" stands for? Personally I would call this variable parent_np, but maybe "tp" has a similar meaning.

Best regards,
Martin

author
#2 lore raw
Quoted 4 lines · Martin Blumenstingl

Hello,

thank you for submitting this patch!

Quoted 8 lines

On Fri, Jun 24, 2022 at 12:28 PM Liang He <[email protected]> wrote:
[...]

Quoted 1 line

these bugs are compiled tested in 5.19rc2 with at91_dt_defconfig

Please note that you're changing some drivers which are only in the arch/arm/configs/multi_v7_defconfig while others are only in arch/arm64/configs/defconfig
I think at91_dt_defconfig will not compile any of the drivers below

Hi, Martin.

To simplify the building test, I use the at91_dt_defconfig to build .config for these similar bugs in clk-at91, clk-sprd,etc.
Then I use following command to complete different compile tests for clk-meson:

make CONFIG_ARCH_MESON=y CONFIG_COMMON_CLK_MESON8B=y CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm ./drivers/clk/meson/meson8b.o make CONFIG_ARCH_MESON=y CONFIG_COMMON_CLK_MESON_EE_CLKC=y CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm ./drivers/clk/meson/meson-eeclk.o make CONFIG_ARCH_MESON=y CONFIG_COMMON_CLK_MESON_AO_CLKC=y CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm ./drivers/clk/meson/meson-aoclk.o

I will add these detailed compile commands in my version-2 patch and also in future patch commit.

Quoted 16 lines

[...]

drivers/clk/meson/meson8b.c static void __init meson8b_clkc_init_common(struct device_node *np, · line 3799

Quoted 9 lines
drivers/clk/meson/meson8b.c +1 -0
index 8f3b7a94a667..54188319f349 100644
@@ -3796,8 +3796,11 @@ static void __init meson8b_clkc_init_common(struct device_node *np,
        struct clk *notifier_clk;
        struct regmap *map;
        int i, ret;
+       struct device_node *tp;

This function uses reverse christmas tree sorting, so the longest line goes on top while the shortest should stay on the bottom. Can you please explain what "tp" stands for? Personally I would call this variable parent_np, but maybe "tp" has a similar meaning.

Quoted 2 lines

Best regards,
Martin

Thanks very much, Martin.

I will send version-2 patch to keep the reverse christmas tree. And I will follow this rule in my future patch code.

I just want to ues 'tp' as 'tmp_pointer', but your advice is more reasonable and I will change that in version-2 patch.

Liang