diff mbox series

[v2] clk: meson: Hold reference returned by of_get_parent()

Message ID 20220628141038.168383-1-windhl@126.com (mailing list archive)
State New, archived
Delegated to: Neil Armstrong
Headers show
Series [v2] clk: meson: Hold reference returned by of_get_parent() | expand

Commit Message

Liang He June 28, 2022, 2:10 p.m. UTC
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")

Signed-off-by: Liang He <windhl@126.com>
---
 changelog:
 
 v2: change the name of 'tp', change the title format, keep reverse christmas tree
 v1: hold reference returned by of_get_parent()

 v1-link: https://lore.kernel.org/all/20220624102719.4166125-1-windhl@126.com/

 Patched files have been compiled test in 5.19rc2.


 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(-)

Comments

Neil Armstrong June 28, 2022, 3:59 p.m. UTC | #1
On 28/06/2022 16:10, Liang He wrote:
> 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")
> 
> Signed-off-by: Liang He <windhl@126.com>
> ---
>   changelog:
>   
>   v2: change the name of 'tp', change the title format, keep reverse christmas tree
>   v1: hold reference returned by of_get_parent()
> 
>   v1-link: https://lore.kernel.org/all/20220624102719.4166125-1-windhl@126.com/
> 
>   Patched files have been compiled test in 5.19rc2.
> 
> 
>   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(-)
> 
> diff --git a/drivers/clk/meson/meson-aoclk.c b/drivers/clk/meson/meson-aoclk.c
> index 27cd2c1f3f61..434cd8f9de82 100644
> --- a/drivers/clk/meson/meson-aoclk.c
> +++ b/drivers/clk/meson/meson-aoclk.c
> @@ -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);
> diff --git a/drivers/clk/meson/meson-eeclk.c b/drivers/clk/meson/meson-eeclk.c
> index 8d5a5dab955a..0e5e6b57eb20 100644
> --- a/drivers/clk/meson/meson-eeclk.c
> +++ b/drivers/clk/meson/meson-eeclk.c
> @@ -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");
> diff --git a/drivers/clk/meson/meson8b.c b/drivers/clk/meson/meson8b.c
> index 8f3b7a94a667..827e78fb16a8 100644
> --- a/drivers/clk/meson/meson8b.c
> +++ b/drivers/clk/meson/meson8b.c
> @@ -3792,12 +3792,15 @@ static void __init meson8b_clkc_init_common(struct device_node *np,
>   			struct clk_hw_onecell_data *clk_hw_onecell_data)
>   {
>   	struct meson8b_clk_reset *rstc;
> +	struct device_node *parent_np;
>   	const char *notifier_clk_name;
>   	struct clk *notifier_clk;
>   	struct regmap *map;
>   	int i, ret;
>   
> -	map = syscon_node_to_regmap(of_get_parent(np));
> +	parent_np = of_get_parent(np);
> +	map = syscon_node_to_regmap(parent_np);
> +	of_node_put(parent_np);
>   	if (IS_ERR(map)) {
>   		pr_err("failed to get HHI regmap - Trying obsolete regs\n");
>   		return;

Reviewed-by: Neil Armstrong <narmstrong@baylibre.com>
Martin Blumenstingl June 29, 2022, 2:59 p.m. UTC | #2
On Tue, Jun 28, 2022 at 4:12 PM Liang He <windhl@126.com> wrote:
>
> 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")
>
> Signed-off-by: Liang He <windhl@126.com>
Reviewed-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>

> ---
>  changelog:
>
>  v2: change the name of 'tp', change the title format, keep reverse christmas tree
>  v1: hold reference returned by of_get_parent()
Thank you for these changes in v2!
Jerome Brunet June 30, 2022, 12:29 p.m. UTC | #3
On Tue 28 Jun 2022 at 22:10, Liang He <windhl@126.com> wrote:

> 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")

Fixing different commits with a single one is not going to make stable
backport easy. I would prefer if you could submit a patch for each
fixes/driver.

Not blocking for a v3 but worth considering after looking at the number
of drivers making the same mistake:
* make a syscon function to deal with of_get_parent(),
  syscon_node_to_regmap() and of_node_put() instead of duplicating the
  code everywhere.
* Propose a coccinelle script to detect/fix this in the future

>
> Signed-off-by: Liang He <windhl@126.com>
> ---
>  changelog:
>  
>  v2: change the name of 'tp', change the title format, keep reverse christmas tree
>  v1: hold reference returned by of_get_parent()
>
>  v1-link: https://lore.kernel.org/all/20220624102719.4166125-1-windhl@126.com/
>
>  Patched files have been compiled test in 5.19rc2.
>
>
>  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(-)
>
> diff --git a/drivers/clk/meson/meson-aoclk.c b/drivers/clk/meson/meson-aoclk.c
> index 27cd2c1f3f61..434cd8f9de82 100644
> --- a/drivers/clk/meson/meson-aoclk.c
> +++ b/drivers/clk/meson/meson-aoclk.c
> @@ -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);
> diff --git a/drivers/clk/meson/meson-eeclk.c b/drivers/clk/meson/meson-eeclk.c
> index 8d5a5dab955a..0e5e6b57eb20 100644
> --- a/drivers/clk/meson/meson-eeclk.c
> +++ b/drivers/clk/meson/meson-eeclk.c
> @@ -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");
> diff --git a/drivers/clk/meson/meson8b.c b/drivers/clk/meson/meson8b.c
> index 8f3b7a94a667..827e78fb16a8 100644
> --- a/drivers/clk/meson/meson8b.c
> +++ b/drivers/clk/meson/meson8b.c
> @@ -3792,12 +3792,15 @@ static void __init meson8b_clkc_init_common(struct device_node *np,
>  			struct clk_hw_onecell_data *clk_hw_onecell_data)
>  {
>  	struct meson8b_clk_reset *rstc;
> +	struct device_node *parent_np;
>  	const char *notifier_clk_name;
>  	struct clk *notifier_clk;
>  	struct regmap *map;
>  	int i, ret;
>  
> -	map = syscon_node_to_regmap(of_get_parent(np));
> +	parent_np = of_get_parent(np);
> +	map = syscon_node_to_regmap(parent_np);
> +	of_node_put(parent_np);
>  	if (IS_ERR(map)) {
>  		pr_err("failed to get HHI regmap - Trying obsolete regs\n");
>  		return;
Stephen Boyd Aug. 19, 2022, 9:29 p.m. UTC | #4
Quoting Liang He (2022-06-28 07:10:38)
> 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")
> 
> Signed-off-by: Liang He <windhl@126.com>
> ---

Applied to clk-next
diff mbox series

Patch

diff --git a/drivers/clk/meson/meson-aoclk.c b/drivers/clk/meson/meson-aoclk.c
index 27cd2c1f3f61..434cd8f9de82 100644
--- a/drivers/clk/meson/meson-aoclk.c
+++ b/drivers/clk/meson/meson-aoclk.c
@@ -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);
diff --git a/drivers/clk/meson/meson-eeclk.c b/drivers/clk/meson/meson-eeclk.c
index 8d5a5dab955a..0e5e6b57eb20 100644
--- a/drivers/clk/meson/meson-eeclk.c
+++ b/drivers/clk/meson/meson-eeclk.c
@@ -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");
diff --git a/drivers/clk/meson/meson8b.c b/drivers/clk/meson/meson8b.c
index 8f3b7a94a667..827e78fb16a8 100644
--- a/drivers/clk/meson/meson8b.c
+++ b/drivers/clk/meson/meson8b.c
@@ -3792,12 +3792,15 @@  static void __init meson8b_clkc_init_common(struct device_node *np,
 			struct clk_hw_onecell_data *clk_hw_onecell_data)
 {
 	struct meson8b_clk_reset *rstc;
+	struct device_node *parent_np;
 	const char *notifier_clk_name;
 	struct clk *notifier_clk;
 	struct regmap *map;
 	int i, ret;
 
-	map = syscon_node_to_regmap(of_get_parent(np));
+	parent_np = of_get_parent(np);
+	map = syscon_node_to_regmap(parent_np);
+	of_node_put(parent_np);
 	if (IS_ERR(map)) {
 		pr_err("failed to get HHI regmap - Trying obsolete regs\n");
 		return;