arm: mvebu: fix resource leak
Subsystems (6)
v2 cover arm: mvebu: fix resource leak
These patches try to fix resource leak by adding missing of_node_put(), iounmap or using devm_ioremap_resource() if available.
v2:
- use devm_ioremap_resource() as suggested by Ezequiel Garcia
- use gates_out instead of bail_out as suggested by Mike Turquette
Jisheng Zhang (4):
arm: mvebu: add missing of_node_put() to fix reference leak
bus: mvebu: add missing of_node_put() to fix reference leak
clk: mvebu: add missing iounmap
pinctrl: mvebu: Convert to use devm_ioremap_resource
arch/arm/mach-mvebu/armada-370-xp.c | 1 + arch/arm/mach-mvebu/coherency.c | 8 +++++++- arch/arm/mach-mvebu/platsmp.c | 1 + arch/arm/mach-mvebu/pmsu.c | 1 + arch/arm/mach-mvebu/system-controller.c | 1 + drivers/bus/mvebu-mbus.c | 6 +++++- drivers/clk/mvebu/clk-cpu.c | 4 +++- drivers/clk/mvebu/common.c | 18 ++++++++++++------ drivers/pinctrl/mvebu/pinctrl-mvebu.c | 11 +++++------ 9 files changed, 36 insertions(+), 15 deletions(-)
Signature · 1 line
1.8.4.rc3
PATCH v2 1/4 arm: mvebu: add missing of_node_put() to fix reference leak
Add of_node_put to properly decrement the refcount when we are done using a given node.
--- arch/arm/mach-mvebu/armada-370-xp.c | 1 + arch/arm/mach-mvebu/coherency.c | 8 +++++++- arch/arm/mach-mvebu/platsmp.c | 1 + arch/arm/mach-mvebu/pmsu.c | 1 + arch/arm/mach-mvebu/system-controller.c | 1 + 5 files changed, 11 insertions(+), 1 deletion(-)
arch/arm/mach-mvebu/armada-370-xp.c +1 -0
@@ -64,6 +64,7 @@ static void __init armada_370_xp_mbus_init(void)ARMADA_370_XP_MBUS_WINS_SIZE ,of_translate_address (dn, &sdram_wins_offs), ARMADA_370_XP_SDRAM_WINS_SIZE); +of_node_put (dn); }static void __init armada_370_xp_timer_and_clk_init (void )
arch/arm/mach-mvebu/coherency.c +7 -1
@@ -140,6 +140,7 @@ int __init coherency_init(void) coherency_base =of_iomap (np,0 ); coherency_cpu_base =of_iomap (np,1 );set_cpu_coherent (cpu_logical_map (smp_processor_id ()),0 ); +of_node_put (np); }return 0 ;
@@ -147,9 +148,14 @@ int __init coherency_init(void)static int __init coherency_late_init (void ) { -if (of_find_matching_node (NULL , of_coherency_table)) +struct device_node *np; + + np =of_find_matching_node (NULL , of_coherency_table); +if (np) {bus_register_notifier (&platform_bus_type, &mvebu_hwcc_platform_nb); +of_node_put (np); + }return 0 ; }
arch/arm/mach-mvebu/platsmp.c +1 -0
@@ -95,6 +95,7 @@ static void __init armada_xp_smp_init_cpus(void)panic ("No 'cpus' node found\n" ); ncores =of_get_child_count (np); +of_node_put (np);if (ncores ==0 || ncores >ARMADA_XP_MAX_CPUS )panic ("Invalid number of CPUs in DT\n" );
arch/arm/mach-mvebu/pmsu.c +1 -0
@@ -67,6 +67,7 @@ int __init armada_370_xp_pmsu_init(void)pr_info ("Initializing Power Management Service Unit\n" ); pmsu_mp_base =of_iomap (np,0 ); pmsu_reset_base =of_iomap (np,1 ); +of_node_put (np); }return 0 ;
arch/arm/mach-mvebu/system-controller.c +1 -0
@@ -98,6 +98,7 @@ static int __init mvebu_system_controller_init(void)BUG_ON (!match); system_controller_base =of_iomap (np,0 ); mvebu_sc = (struct mvebu_system_controller *)match->data; +of_node_put (np); }return 0 ;
Signature · 1 line
1.8.4.rc3
PATCH v2 2/4 bus: mvebu: add missing of_node_put() to fix reference leak
In reply to Jisheng ZhangAdd of_node_put to properly decrement the refcount when we are done using a given node.
--- drivers/bus/mvebu-mbus.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/bus/mvebu-mbus.c +5 -1
@@ -837,6 +837,7 @@ int __init mvebu_mbus_init(const char *soc, phys_addr_t mbuswins_phys_base, {struct mvebu_mbus_state *mbus = &mbus_state;const struct of_device_id *of_id; +struct device_node *np;int win;for (of_id = of_mvebu_mbus_ids; of_id->compatible; of_id++)
@@ -860,8 +861,11 @@ int __init mvebu_mbus_init(const char *soc, phys_addr_t mbuswins_phys_base,return -ENOMEM ; } -if (of_find_compatible_node (NULL ,NULL ,"marvell,coherency-fabric" )) + np =of_find_compatible_node (NULL ,NULL ,"marvell,coherency-fabric" ); +if (np) { mbus->hw_io_coherency =1 ; +of_node_put (np); + }for (win =0 ; win < mbus->soc->num_wins; win++)mvebu_mbus_disable_window (mbus, win);
Signature · 1 line
1.8.4.rc3
PATCH v2 3/4 clk: mvebu: add missing iounmap
In reply to Jisheng ZhangAdd missing iounmap to setup error path.
--- drivers/clk/mvebu/clk-cpu.c | 4 +++- drivers/clk/mvebu/common.c | 18 ++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-)
drivers/clk/mvebu/clk-cpu.c +3 -1
@@ -119,7 +119,7 @@ void __init of_cpu_clk_setup(struct device_node *node) cpuclk =kzalloc (ncpus *sizeof (*cpuclk),GFP_KERNEL );if (WARN_ON (!cpuclk)) -return ; + goto cpuclk_out; clks =kzalloc (ncpus *sizeof (*clks),GFP_KERNEL );if (WARN_ON (!clks))
@@ -170,6 +170,8 @@ bail_out:kfree (cpuclk[ncpus].clk_name); clks_out:kfree (cpuclk); +cpuclk_out: +iounmap (clock_complex_base); } CLK_OF_DECLARE(armada_xp_cpu_clock, "marvell,armada-xp-cpu-clock",
drivers/clk/mvebu/common.c +12 -6
@@ -45,8 +45,10 @@ void __init mvebu_coreclk_setup(struct device_node *np, clk_data.clk_num =2 + desc->num_ratios; clk_data.clks =kzalloc (clk_data.clk_num *sizeof (struct clk *),GFP_KERNEL ); -if (WARN_ON (!clk_data.clks)) +if (WARN_ON (!clk_data.clks)) { +iounmap (base);return ; + }/* Register TCLK */ of_property_read_string_index(np, "clock-output-names", 0,
@@ -134,7 +136,7 @@ void __init mvebu_clk_gating_setup(struct device_node *np, ctrl =kzalloc (sizeof (*ctrl),GFP_KERNEL );if (WARN_ON (!ctrl)) -return ; + goto ctrl_out;spin_lock_init (&ctrl->lock);
@@ -145,10 +147,8 @@ void __init mvebu_clk_gating_setup(struct device_node *np, ctrl->num_gates = n; ctrl->gates =kzalloc (ctrl->num_gates *sizeof (struct clk *),GFP_KERNEL ); -if (WARN_ON (!ctrl->gates)) { -kfree (ctrl); -return ; - } +if (WARN_ON (!ctrl->gates)) + goto gates_out;for (n =0 ; n < ctrl->num_gates; n++) { const char *parent =
@@ -160,4 +160,10 @@ void __init mvebu_clk_gating_setup(struct device_node *np, }of_clk_add_provider (np, clk_gating_get_src, ctrl); + +return ; +gates_out: +kfree (ctrl); +ctrl_out: +iounmap (base); }
Signature · 1 line
1.8.4.rc3
Re: [PATCH v2 3/4] clk: mvebu: add missing iounmap
Quoting Jisheng Zhang (2013-08-22 19:34:01)
Quoted 3 lines
Add missing iounmap to setup error path.
Change-Id: I4371569d14d7026aa9f90d7cd53f669d365fe26a
Please remove Change-Id's from the commit message for upstream patch submissions in the future. I can remove this one, this time.
I've taken the patch into clk-next.
Regards,
Mike
Quoted 79 lines
Signed-off-by Jisheng Zhang <[email protected]>--- drivers/clk/mvebu/clk-cpu.c | 4 +++- drivers/clk/mvebu/common.c | 18 ++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-)drivers/clk/mvebu/clk-cpu.c +3
-1@@ -119,7 +119,7 @@ void __init of_cpu_clk_setup(struct device_node *node) cpuclk =kzalloc (ncpus *sizeof (*cpuclk),GFP_KERNEL );if (WARN_ON (!cpuclk)) -return ; + goto cpuclk_out; clks =kzalloc (ncpus *sizeof (*clks),GFP_KERNEL );if (WARN_ON (!clks))@@ -170,6 +170,8 @@ bail_out:kfree (cpuclk[ncpus].clk_name); clks_out:kfree (cpuclk); +cpuclk_out: +iounmap (clock_complex_base); } CLK_OF_DECLARE(armada_xp_cpu_clock, "marvell,armada-xp-cpu-clock",drivers/clk/mvebu/common.c +12
-6@@ -45,8 +45,10 @@ void __init mvebu_coreclk_setup(struct device_node *np, clk_data.clk_num =2 + desc->num_ratios; clk_data.clks =kzalloc (clk_data.clk_num *sizeof (struct clk *),GFP_KERNEL ); -if (WARN_ON (!clk_data.clks)) +if (WARN_ON (!clk_data.clks)) { +iounmap (base);return ; + }/* Register TCLK */ of_property_read_string_index(np, "clock-output-names", 0,@@ -134,7 +136,7 @@ void __init mvebu_clk_gating_setup(struct device_node *np, ctrl =kzalloc (sizeof (*ctrl),GFP_KERNEL );if (WARN_ON (!ctrl)) -return ; + goto ctrl_out;spin_lock_init (&ctrl->lock);@@ -145,10 +147,8 @@ void __init mvebu_clk_gating_setup(struct device_node *np, ctrl->num_gates = n; ctrl->gates =kzalloc (ctrl->num_gates *sizeof (struct clk *),GFP_KERNEL ); -if (WARN_ON (!ctrl->gates)) { -kfree (ctrl); -return ; - } +if (WARN_ON (!ctrl->gates)) + goto gates_out;for (n =0 ; n < ctrl->num_gates; n++) { const char *parent =@@ -160,4 +160,10 @@ void __init mvebu_clk_gating_setup(struct device_node *np, }of_clk_add_provider (np, clk_gating_get_src, ctrl); + +return ; +gates_out: +kfree (ctrl); +ctrl_out: +iounmap (base); }Signature · 1 line
1.8.4.rc3
Re: [PATCH v2 3/4] clk: mvebu: add missing iounmap
Hi Mike,
Quoted 10 lines · On Fri, 23 Aug 2013 14:29:50 -0700 Mike Turquette <[email protected]> wrote:
Quoting Jisheng Zhang (2013-08-22 19:34:01)
Quoted 3 lines
Add missing iounmap to setup error path.
Change-Id: I4371569d14d7026aa9f90d7cd53f669d365fe26a
Please remove Change-Id's from the commit message for upstream patch submissions in the future. I can remove this one, this time.
I've taken the patch into clk-next.
Thanks for kindly reminding. I'll take care of this in the future.
Best Regards,
Jisheng
PATCH v2 4/4 pinctrl: mvebu: Convert to use devm_ioremap_resource
In reply to Jisheng Zhang--- drivers/pinctrl/mvebu/pinctrl-mvebu.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/pinctrl/mvebu/pinctrl-mvebu.c +5 -6
@@ -579,7 +579,7 @@ static int mvebu_pinctrl_build_functions(struct platform_device *pdev,int mvebu_pinctrl_probe (struct platform_device *pdev) {struct mvebu_pinctrl_soc_info *soc =dev_get_platdata (&pdev->dev); -struct device_node *np = pdev->dev.of_node; +struct resource *res;struct mvebu_pinctrl *pctl;void __iomem *base;struct pinctrl_pin_desc *pdesc;
@@ -591,11 +591,10 @@ int mvebu_pinctrl_probe(struct platform_device *pdev)return -EINVAL ; } - base =of_iomap (np,0 ); -if (!base) { -dev_err (&pdev->dev,"unable to get base address\n" ); -return -ENODEV ; - } + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + base =devm_ioremap_resource (&pdev->dev, res); +if (IS_ERR (base)) +return PTR_ERR (base); pctl =devm_kzalloc (&pdev->dev,sizeof (struct mvebu_pinctrl ),GFP_KERNEL );
Signature · 1 line
1.8.4.rc3
Re: [PATCH v2 4/4] pinctrl: mvebu: Convert to use devm_ioremap_resource
Hi Jisheng,
Quoted 5 lines · Jisheng Zhang
Signed-off-by Jisheng Zhang <[email protected]>--- drivers/pinctrl/mvebu/pinctrl-mvebu.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
Mmm.. I would prefer to see a better commit log for this patch. In particular, the current code is buggy (for there's a leak) and this patch fixes it.
Care to write something meaningful and re-send? (except the patch Mike already took, I guess).
With that changes you can add:
for the whole series.
Signature · 3 lines
Ezequiel Garc?a, Free Electrons Embedded Linux, Kernel and Android Engineering http://free-electrons.com
Re: [PATCH v2 4/4] pinctrl: mvebu: Convert to use devm_ioremap_resource
Hi Ezequiel,
Quoted 9 lines · On Sat, 24 Aug 2013 08:06:25 -0700 Ezequiel Garcia…
Hi Jisheng,
Quoted 5 lines · Jisheng Zhang
Signed-off-by Jisheng Zhang <[email protected]>--- drivers/pinctrl/mvebu/pinctrl-mvebu.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
Quoted 4 lines
Mmm.. I would prefer to see a better commit log for this patch. In particular, the current code is buggy (for there's a leak) and this patch fixes it.
Care to write something meaningful and re-send? (except the patch
Done. Could you please review again?
Quoted 5 lines
Mike already took, I guess).
With that changes you can add:
Reviewed-by Ezequiel Garcia <[email protected]>T
Thank you for your help
Quoted 2 lines
for the whole series.
Best Regards,
Jisheng