clk/meson: Hold reference returned by of_get_parent()
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.
---
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
@@ -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
@@ -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
@@ -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
Martin Blumenstingl
reviewerHello,
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@@ -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
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_defconfigPlease note that you're changing some drivers which are only in the
arch/arm/configs/multi_v7_defconfigwhile others are only inarch/arm64/configs/defconfig
I thinkat91_dt_defconfigwill 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@@ -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