2013-08-22 12:51:07

by Jisheng Zhang

[permalink] [raw]
Subject: [PATCH 0/4] arm: mvebu: add missing of_node_put and iounmap

These patches add missing of_node_put() to fix reference leak or
iounmap in setup/probe error path.

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: add missing iounmap

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 | 24 +++++++++++++++++-------
9 files changed, 48 insertions(+), 16 deletions(-)

--
1.8.4.rc3


2013-08-22 12:51:50

by Jisheng Zhang

[permalink] [raw]
Subject: [PATCH 3/4] clk: mvebu: add missing iounmap

Add missing iounmap to setup error path.

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

diff --git a/drivers/clk/mvebu/clk-cpu.c b/drivers/clk/mvebu/clk-cpu.c
index b0fbc07..1466865 100644
--- a/drivers/clk/mvebu/clk-cpu.c
+++ b/drivers/clk/mvebu/clk-cpu.c
@@ -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",
diff --git a/drivers/clk/mvebu/common.c b/drivers/clk/mvebu/common.c
index adaa4a1..6b415f9 100644
--- a/drivers/clk/mvebu/common.c
+++ b/drivers/clk/mvebu/common.c
@@ -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 bail_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;
+bail_out:
+ kfree(ctrl);
+ctrl_out:
+ iounmap(base);
}
--
1.8.4.rc3

2013-08-22 12:52:00

by Jisheng Zhang

[permalink] [raw]
Subject: [PATCH 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.

Signed-off-by: Jisheng Zhang <[email protected]>
---
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(-)

diff --git a/arch/arm/mach-mvebu/armada-370-xp.c b/arch/arm/mach-mvebu/armada-370-xp.c
index 97cbb80..8a1ae83 100644
--- a/arch/arm/mach-mvebu/armada-370-xp.c
+++ b/arch/arm/mach-mvebu/armada-370-xp.c
@@ -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)
diff --git a/arch/arm/mach-mvebu/coherency.c b/arch/arm/mach-mvebu/coherency.c
index 4c24303..58adf2f 100644
--- a/arch/arm/mach-mvebu/coherency.c
+++ b/arch/arm/mach-mvebu/coherency.c
@@ -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;
}

diff --git a/arch/arm/mach-mvebu/platsmp.c b/arch/arm/mach-mvebu/platsmp.c
index ce81d30..e7edb82 100644
--- a/arch/arm/mach-mvebu/platsmp.c
+++ b/arch/arm/mach-mvebu/platsmp.c
@@ -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");

diff --git a/arch/arm/mach-mvebu/pmsu.c b/arch/arm/mach-mvebu/pmsu.c
index 3cc4bef..27fc4f0 100644
--- a/arch/arm/mach-mvebu/pmsu.c
+++ b/arch/arm/mach-mvebu/pmsu.c
@@ -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;
diff --git a/arch/arm/mach-mvebu/system-controller.c b/arch/arm/mach-mvebu/system-controller.c
index f875124..5175083c 100644
--- a/arch/arm/mach-mvebu/system-controller.c
+++ b/arch/arm/mach-mvebu/system-controller.c
@@ -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;
--
1.8.4.rc3

2013-08-22 12:52:10

by Jisheng Zhang

[permalink] [raw]
Subject: [PATCH 4/4] pinctrl: mvebu: add missing iounmap

Add missing iounmap to prove error path and remove path

Signed-off-by: Jisheng Zhang <[email protected]>
---
drivers/pinctrl/mvebu/pinctrl-mvebu.c | 24 +++++++++++++++++-------
1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/drivers/pinctrl/mvebu/pinctrl-mvebu.c b/drivers/pinctrl/mvebu/pinctrl-mvebu.c
index bb7ddb1..d1ac6b7 100644
--- a/drivers/pinctrl/mvebu/pinctrl-mvebu.c
+++ b/drivers/pinctrl/mvebu/pinctrl-mvebu.c
@@ -601,7 +601,8 @@ int mvebu_pinctrl_probe(struct platform_device *pdev)
GFP_KERNEL);
if (!pctl) {
dev_err(&pdev->dev, "unable to alloc driver\n");
- return -ENOMEM;
+ ret = -ENOMEM;
+ goto bail_out;
}

pctl->desc.name = dev_name(&pdev->dev);
@@ -631,7 +632,8 @@ int mvebu_pinctrl_probe(struct platform_device *pdev)
if (ctrl->mpp_get || ctrl->mpp_set) {
if (!ctrl->name || !ctrl->mpp_get || !ctrl->mpp_set) {
dev_err(&pdev->dev, "wrong soc control info\n");
- return -EINVAL;
+ ret = -EINVAL;
+ goto bail_out;
}
pctl->num_groups += 1;
continue;
@@ -641,7 +643,8 @@ int mvebu_pinctrl_probe(struct platform_device *pdev)
names = devm_kzalloc(&pdev->dev, ctrl->npins * 8, GFP_KERNEL);
if (!names) {
dev_err(&pdev->dev, "failed to alloc mpp names\n");
- return -ENOMEM;
+ ret = -ENOMEM;
+ goto bail_out;
}
for (k = 0; k < ctrl->npins; k++)
sprintf(names + 8*k, "mpp%d", ctrl->pid+k);
@@ -653,7 +656,8 @@ int mvebu_pinctrl_probe(struct platform_device *pdev)
sizeof(struct pinctrl_pin_desc), GFP_KERNEL);
if (!pdesc) {
dev_err(&pdev->dev, "failed to alloc pinctrl pins\n");
- return -ENOMEM;
+ ret = -ENOMEM;
+ goto bail_out;
}

for (n = 0; n < pctl->desc.npins; n++)
@@ -664,7 +668,8 @@ int mvebu_pinctrl_probe(struct platform_device *pdev)
sizeof(struct mvebu_pinctrl_group), GFP_KERNEL);
if (!pctl->groups) {
dev_err(&pdev->dev, "failed to alloc pinctrl groups\n");
- return -ENOMEM;
+ ret = -ENOMEM;
+ goto bail_out;
}

/* assign mpp controls to groups */
@@ -735,13 +740,14 @@ int mvebu_pinctrl_probe(struct platform_device *pdev)
ret = mvebu_pinctrl_build_functions(pdev, pctl);
if (ret) {
dev_err(&pdev->dev, "unable to build functions\n");
- return ret;
+ goto bail_out;
}

pctl->pctldev = pinctrl_register(&pctl->desc, &pdev->dev, pctl);
if (!pctl->pctldev) {
dev_err(&pdev->dev, "unable to register pinctrl driver\n");
- return -EINVAL;
+ ret = -EINVAL;
+ goto bail_out;
}

dev_info(&pdev->dev, "registered pinctrl driver\n");
@@ -751,11 +757,15 @@ int mvebu_pinctrl_probe(struct platform_device *pdev)
pinctrl_add_gpio_range(pctl->pctldev, &soc->gpioranges[n]);

return 0;
+bail_out:
+ iounmap(base);
+ return ret;
}

int mvebu_pinctrl_remove(struct platform_device *pdev)
{
struct mvebu_pinctrl *pctl = platform_get_drvdata(pdev);
+ iounmap(pctl->base);
pinctrl_unregister(pctl->pctldev);
return 0;
}
--
1.8.4.rc3

2013-08-22 12:55:51

by Jisheng Zhang

[permalink] [raw]
Subject: [PATCH 2/4] bus: 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.

Signed-off-by: Jisheng Zhang <[email protected]>
---
drivers/bus/mvebu-mbus.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/bus/mvebu-mbus.c b/drivers/bus/mvebu-mbus.c
index 33c6947..20da90f 100644
--- a/drivers/bus/mvebu-mbus.c
+++ b/drivers/bus/mvebu-mbus.c
@@ -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);
--
1.8.4.rc3

2013-08-22 13:22:17

by Ezequiel Garcia

[permalink] [raw]
Subject: Re: [PATCH 4/4] pinctrl: mvebu: add missing iounmap

Hi Jisheng,

On Thu, Aug 22, 2013 at 08:46:51PM +0800, Jisheng Zhang wrote:
> Add missing iounmap to prove error path and remove path
>
> Signed-off-by: Jisheng Zhang <[email protected]>
> ---
> drivers/pinctrl/mvebu/pinctrl-mvebu.c | 24 +++++++++++++++++-------
> 1 file changed, 17 insertions(+), 7 deletions(-)

How about using devm_ioremap_resource() instead?

--
Ezequiel García, Free Electrons
Embedded Linux, Kernel and Android Engineering
http://free-electrons.com

2013-08-22 22:31:46

by Mike Turquette

[permalink] [raw]
Subject: Re: [PATCH 3/4] clk: mvebu: add missing iounmap

Quoting Jisheng Zhang (2013-08-22 05:46:50)
> Add missing iounmap to setup error path.
>
> Signed-off-by: Jisheng Zhang <[email protected]>

Patch looks good with one minor nitpick below.

> @@ -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 bail_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;
> +bail_out:
> + kfree(ctrl);
> +ctrl_out:
> + iounmap(base);

bail_out is not the best name. How about gates_out?

Regards,
Mike

2013-08-23 18:06:05

by Linus Walleij

[permalink] [raw]
Subject: Re: [PATCH 4/4] pinctrl: mvebu: add missing iounmap

On Thu, Aug 22, 2013 at 3:22 PM, Ezequiel Garcia
<[email protected]> wrote:
> On Thu, Aug 22, 2013 at 08:46:51PM +0800, Jisheng Zhang wrote:
>> Add missing iounmap to prove error path and remove path
>>
>> Signed-off-by: Jisheng Zhang <[email protected]>
>> ---
>> drivers/pinctrl/mvebu/pinctrl-mvebu.c | 24 +++++++++++++++++-------
>> 1 file changed, 17 insertions(+), 7 deletions(-)
>
> How about using devm_ioremap_resource() instead?

Yeah that's the right solution, Jisheng can you fix this?

Yours,
Linus Walleij

2013-08-23 20:19:35

by Ezequiel Garcia

[permalink] [raw]
Subject: Re: [PATCH 4/4] pinctrl: mvebu: add missing iounmap

On Fri, Aug 23, 2013 at 08:06:02PM +0200, Linus Walleij wrote:
> On Thu, Aug 22, 2013 at 3:22 PM, Ezequiel Garcia
> <[email protected]> wrote:
> > On Thu, Aug 22, 2013 at 08:46:51PM +0800, Jisheng Zhang wrote:
> >> Add missing iounmap to prove error path and remove path
> >>
> >> Signed-off-by: Jisheng Zhang <[email protected]>
> >> ---
> >> drivers/pinctrl/mvebu/pinctrl-mvebu.c | 24 +++++++++++++++++-------
> >> 1 file changed, 17 insertions(+), 7 deletions(-)
> >
> > How about using devm_ioremap_resource() instead?
>
> Yeah that's the right solution, Jisheng can you fix this?
>

I think he already did that, there's a v2 floating around
with such change. I plan to give it a test, maybe tomorrow,
if I can find some spare time.

Regards,
--
Ezequiel García, Free Electrons
Embedded Linux, Kernel and Android Engineering
http://free-electrons.com

2013-08-24 03:57:48

by Jisheng Zhang

[permalink] [raw]
Subject: Re: [PATCH 4/4] pinctrl: mvebu: add missing iounmap

Hi Linus and Ezequiel,

On Fri, 23 Aug 2013 13:19:26 -0700
Ezequiel Garcia <[email protected]> wrote:

> On Fri, Aug 23, 2013 at 08:06:02PM +0200, Linus Walleij wrote:
> > On Thu, Aug 22, 2013 at 3:22 PM, Ezequiel Garcia
> > <[email protected]> wrote:
> > > On Thu, Aug 22, 2013 at 08:46:51PM +0800, Jisheng Zhang wrote:
> > >> Add missing iounmap to prove error path and remove path
> > >>
> > >> Signed-off-by: Jisheng Zhang <[email protected]>
> > >> ---
> > >> drivers/pinctrl/mvebu/pinctrl-mvebu.c | 24 +++++++++++++++++-------
> > >> 1 file changed, 17 insertions(+), 7 deletions(-)
> > >
> > > How about using devm_ioremap_resource() instead?
> >
> > Yeah that's the right solution, Jisheng can you fix this?
> >
>
> I think he already did that, there's a v2 floating around
> with such change. I plan to give it a test, maybe tomorrow,
> if I can find some spare time.
>

Yep. Here is the V2

http://lists.infradead.org/pipermail/linux-arm-kernel/2013-August/194072.html

Thank you for your help,
Jisheng