[PATCH v2] soc: amlogic: meson-pwrc: Hold reference returned by of_get_parent()

Jerome Brunet jbrunet at baylibre.com
Fri Aug 12 01:23:19 PDT 2022


On Tue 26 Jul 2022 at 15:38, Liang He <windhl at 126.com> wrote:

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

Considering you are making this type of changes more or less everywhere
in the tree it would be good to propose an helper function instead of
repeating the of_get_parent(), syscon_node_to_regmap(), of_node_put()
pattern.

A coccinelle script would be nice too.

Thx

>
> Signed-off-by: Liang He <windhl at 126.com>
> ---
>  drivers/soc/amlogic/meson-ee-pwrc.c     | 5 ++++-
>  drivers/soc/amlogic/meson-gx-pwrc-vpu.c | 5 ++++-
>  2 files changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/soc/amlogic/meson-ee-pwrc.c b/drivers/soc/amlogic/meson-ee-pwrc.c
> index 2be3afe6c2e3..dd5f2a13ceb5 100644
> --- a/drivers/soc/amlogic/meson-ee-pwrc.c
> +++ b/drivers/soc/amlogic/meson-ee-pwrc.c
> @@ -469,6 +469,7 @@ static int meson_ee_pwrc_probe(struct platform_device *pdev)
>  {
>  	const struct meson_ee_pwrc_domain_data *match;
>  	struct regmap *regmap_ao, *regmap_hhi;
> +	struct device_node *parent_np;
>  	struct meson_ee_pwrc *pwrc;
>  	int i, ret;
>  
> @@ -495,7 +496,9 @@ static int meson_ee_pwrc_probe(struct platform_device *pdev)
>  
>  	pwrc->xlate.num_domains = match->count;
>  
> -	regmap_hhi = syscon_node_to_regmap(of_get_parent(pdev->dev.of_node));
> +	parent_np = of_get_parent(pdev->dev.of_node);
> +	regmap_hhi = syscon_node_to_regmap(parent_np);
> +	of_node_put(parent_np);
>  	if (IS_ERR(regmap_hhi)) {
>  		dev_err(&pdev->dev, "failed to get HHI regmap\n");
>  		return PTR_ERR(regmap_hhi);
> diff --git a/drivers/soc/amlogic/meson-gx-pwrc-vpu.c b/drivers/soc/amlogic/meson-gx-pwrc-vpu.c
> index b4615b288625..312fd9afccb0 100644
> --- a/drivers/soc/amlogic/meson-gx-pwrc-vpu.c
> +++ b/drivers/soc/amlogic/meson-gx-pwrc-vpu.c
> @@ -273,6 +273,7 @@ static int meson_gx_pwrc_vpu_probe(struct platform_device *pdev)
>  	const struct meson_gx_pwrc_vpu *vpu_pd_match;
>  	struct regmap *regmap_ao, *regmap_hhi;
>  	struct meson_gx_pwrc_vpu *vpu_pd;
> +	struct device_node *parent_np;
>  	struct reset_control *rstc;
>  	struct clk *vpu_clk;
>  	struct clk *vapb_clk;
> @@ -291,7 +292,9 @@ static int meson_gx_pwrc_vpu_probe(struct platform_device *pdev)
>  
>  	memcpy(vpu_pd, vpu_pd_match, sizeof(*vpu_pd));
>  
> -	regmap_ao = syscon_node_to_regmap(of_get_parent(pdev->dev.of_node));
> +	parent_np = of_get_parent(pdev->dev.of_node);
> +	regmap_ao = syscon_node_to_regmap(parent_np);
> +	of_node_put(parent_np);
>  	if (IS_ERR(regmap_ao)) {
>  		dev_err(&pdev->dev, "failed to get regmap\n");
>  		return PTR_ERR(regmap_ao);




More information about the linux-amlogic mailing list