ARM: ux500: Fix refcount leak in ux500_pm_domains_init

Message ID 20230102094733.3966825-1-linmq006@gmail.com
State New
Headers
Series ARM: ux500: Fix refcount leak in ux500_pm_domains_init |

Commit Message

Miaoqian Lin Jan. 2, 2023, 9:47 a.m. UTC
  of_irq_find_parent() returns a node pointer with refcount incremented,
We should use of_node_put() on it when not needed anymore.
Add missing of_node_put() in the error path to avoid refcount leak.

Fixes: cd931dcfda5e ("ARM: ux500: Initial support for PM domains")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
 arch/arm/mach-ux500/pm_domains.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
  

Comments

Ulf Hansson Jan. 2, 2023, 3:18 p.m. UTC | #1
On Mon, 2 Jan 2023 at 10:47, Miaoqian Lin <linmq006@gmail.com> wrote:
>
> of_irq_find_parent() returns a node pointer with refcount incremented,

Probably a cut and paste, as you probably mean of_find_matching_node().

> We should use of_node_put() on it when not needed anymore.
> Add missing of_node_put() in the error path to avoid refcount leak.
>
> Fixes: cd931dcfda5e ("ARM: ux500: Initial support for PM domains")
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>

Other than the above, which maybe Linus can fixup when applying:

Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>

Kind regards
Uffe

> ---
>  arch/arm/mach-ux500/pm_domains.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/arch/arm/mach-ux500/pm_domains.c b/arch/arm/mach-ux500/pm_domains.c
> index 427b9ac4af6c..01cae91854ca 100644
> --- a/arch/arm/mach-ux500/pm_domains.c
> +++ b/arch/arm/mach-ux500/pm_domains.c
> @@ -65,8 +65,10 @@ int __init ux500_pm_domains_init(void)
>                 return -ENODEV;
>
>         genpd_data = kzalloc(sizeof(*genpd_data), GFP_KERNEL);
> -       if (!genpd_data)
> +       if (!genpd_data) {
> +               of_node_put(np);
>                 return -ENOMEM;
> +       }
>
>         genpd_data->domains = ux500_pm_domains;
>         genpd_data->num_domains = ARRAY_SIZE(ux500_pm_domains);
> --
> 2.25.1
>
  
Linus Walleij April 9, 2023, 8:59 p.m. UTC | #2
On Mon, Jan 2, 2023 at 10:47 AM Miaoqian Lin <linmq006@gmail.com> wrote:

> of_irq_find_parent() returns a node pointer with refcount incremented,
> We should use of_node_put() on it when not needed anymore.
> Add missing of_node_put() in the error path to avoid refcount leak.
>
> Fixes: cd931dcfda5e ("ARM: ux500: Initial support for PM domains")
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>

Patch applied. Sorry for forgetting about this patch!

Yours,
Linus Walleij
  

Patch

diff --git a/arch/arm/mach-ux500/pm_domains.c b/arch/arm/mach-ux500/pm_domains.c
index 427b9ac4af6c..01cae91854ca 100644
--- a/arch/arm/mach-ux500/pm_domains.c
+++ b/arch/arm/mach-ux500/pm_domains.c
@@ -65,8 +65,10 @@  int __init ux500_pm_domains_init(void)
 		return -ENODEV;
 
 	genpd_data = kzalloc(sizeof(*genpd_data), GFP_KERNEL);
-	if (!genpd_data)
+	if (!genpd_data) {
+		of_node_put(np);
 		return -ENOMEM;
+	}
 
 	genpd_data->domains = ux500_pm_domains;
 	genpd_data->num_domains = ARRAY_SIZE(ux500_pm_domains);