2010-11-22 08:37:46

by Axel Lin

[permalink] [raw]
Subject: [PATCH 0/4] fix a memory leak related to request_mem_region/release_mem_region usage

This serial of patches fixes a memory leak related to request_mem_region
and release_mem_region usage.

request_mem_region() will call kzalloc to allocate memory for struct resource.
release_resource() unregisters the resource but does not free the allocated
memory, thus use release_mem_region() instead to fix the memory leak.


Axel Lin (4):
[ARM] davinci_mmc: fix a memory leak
[ARM] mvsdio: fix a memory leak
[ARM] pxamci: fix a memory leak
[ARM] mxcmmc: remove a unnecessary release_resource() call

drivers/mmc/host/davinci_mmc.c | 5 +++--
drivers/mmc/host/mvsdio.c | 4 ++--
drivers/mmc/host/mxcmmc.c | 1 -
drivers/mmc/host/pxamci.c | 4 ++--
4 files changed, 7 insertions(+), 7 deletions(-)

--
1.7.2



2010-11-22 08:39:30

by Axel Lin

[permalink] [raw]
Subject: [PATCH 1/4] [ARM] davinci_mmc: fix a memory leak

request_mem_region() will call kzalloc to allocate memory for struct resource.
release_resource() unregisters the resource but does not free the allocated
memory, thus use release_mem_region() instead to fix the memory leak.

Signed-off-by: Axel Lin <[email protected]>
---
drivers/mmc/host/davinci_mmc.c | 5 +++--
1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/mmc/host/davinci_mmc.c b/drivers/mmc/host/davinci_mmc.c
index e15547c..7c7d268 100644
--- a/drivers/mmc/host/davinci_mmc.c
+++ b/drivers/mmc/host/davinci_mmc.c
@@ -1297,7 +1297,7 @@ cpu_freq_fail:
mmc_free_host(mmc);

if (mem)
- release_resource(mem);
+ release_mem_region(mem->start, resource_size(mem));

dev_dbg(&pdev->dev, "probe err %d\n", ret);

@@ -1322,7 +1322,8 @@ static int __exit davinci_mmcsd_remove(struct platform_device *pdev)

iounmap(host->base);

- release_resource(host->mem_res);
+ release_mem_region(host->mem_res->start,
+ resource_size(host->mem_res));

mmc_free_host(host->mmc);
}
--
1.7.2


2010-11-22 08:40:37

by Axel Lin

[permalink] [raw]
Subject: [PATCH 2/4] [ARM] mvsdio: fix a memory leak

request_mem_region() will call kzalloc to allocate memory for struct resource.
release_resource() unregisters the resource but does not free the allocated
memory, thus use release_mem_region() instead to fix the memory leak.

Signed-off-by: Axel Lin <[email protected]>
---
drivers/mmc/host/mvsdio.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mmc/host/mvsdio.c b/drivers/mmc/host/mvsdio.c
index a5bf60e..6a29972 100644
--- a/drivers/mmc/host/mvsdio.c
+++ b/drivers/mmc/host/mvsdio.c
@@ -825,7 +825,7 @@ out:
iounmap(host->base);
}
if (r)
- release_resource(r);
+ release_mem_region(r->start, SZ_1K);
if (mmc)
mmc_free_host(mmc);

@@ -850,7 +850,7 @@ static int __exit mvsd_remove(struct platform_device *pdev)
del_timer_sync(&host->timer);
mvsd_power_down(host);
iounmap(host->base);
- release_resource(host->res);
+ release_mem_region(host->res->start, SZ_1K);
mmc_free_host(mmc);
}
platform_set_drvdata(pdev, NULL);
--
1.7.2


2010-11-22 08:41:39

by Axel Lin

[permalink] [raw]
Subject: [PATCH 3/4] [ARM] pxamci: fix a memory leak

request_mem_region() will call kzalloc to allocate memory for struct resource.
release_resource() unregisters the resource but does not free the allocated
memory, thus use release_mem_region() instead to fix the memory leak.

Signed-off-by: Axel Lin <[email protected]>
---
drivers/mmc/host/pxamci.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mmc/host/pxamci.c b/drivers/mmc/host/pxamci.c
index 7257738..d98e647 100644
--- a/drivers/mmc/host/pxamci.c
+++ b/drivers/mmc/host/pxamci.c
@@ -774,7 +774,7 @@ err_gpio_ro:
}
if (mmc)
mmc_free_host(mmc);
- release_resource(r);
+ release_mem_region(r->start, SZ_4K);
return ret;
}

@@ -824,7 +824,7 @@ static int pxamci_remove(struct platform_device *pdev)

clk_put(host->clk);

- release_resource(host->res);
+ release_mem_region(host->res->start, SZ_4K);

mmc_free_host(mmc);
}
--
1.7.2


2010-11-22 08:42:53

by Axel Lin

[permalink] [raw]
Subject: [PATCH 4/4] [ARM] mxcmmc: remove a unnecessary release_resource() call

Remove release_resource() after release_mem_region().

Signed-off-by: Axel Lin <[email protected]>
---
drivers/mmc/host/mxcmmc.c | 1 -
1 files changed, 0 insertions(+), 1 deletions(-)

diff --git a/drivers/mmc/host/mxcmmc.c b/drivers/mmc/host/mxcmmc.c
index 2b9f7c8..4428594 100644
--- a/drivers/mmc/host/mxcmmc.c
+++ b/drivers/mmc/host/mxcmmc.c
@@ -967,7 +967,6 @@ static int mxcmci_remove(struct platform_device *pdev)
clk_put(host->clk);

release_mem_region(host->res->start, resource_size(host->res));
- release_resource(host->res);

mmc_free_host(mmc);

--
1.7.2


2010-11-25 09:03:25

by Sascha Hauer

[permalink] [raw]
Subject: Re: [PATCH 4/4] [ARM] mxcmmc: remove a unnecessary release_resource() call

On Mon, Nov 22, 2010 at 04:47:51PM +0800, Axel Lin wrote:
> Remove release_resource() after release_mem_region().
>
> Signed-off-by: Axel Lin <[email protected]>

Acked-by: Sascha Hauer <[email protected]>

> ---
> drivers/mmc/host/mxcmmc.c | 1 -
> 1 files changed, 0 insertions(+), 1 deletions(-)
>
> diff --git a/drivers/mmc/host/mxcmmc.c b/drivers/mmc/host/mxcmmc.c
> index 2b9f7c8..4428594 100644
> --- a/drivers/mmc/host/mxcmmc.c
> +++ b/drivers/mmc/host/mxcmmc.c
> @@ -967,7 +967,6 @@ static int mxcmci_remove(struct platform_device *pdev)
> clk_put(host->clk);
>
> release_mem_region(host->res->start, resource_size(host->res));
> - release_resource(host->res);
>
> mmc_free_host(mmc);
>
> --
> 1.7.2
>
>
>
>

--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |

2010-12-05 02:52:05

by Chris Ball

[permalink] [raw]
Subject: Re: [PATCH 4/4] [ARM] mxcmmc: remove a unnecessary release_resource() call

Hi,

On Thu, Nov 25, 2010 at 10:03:11AM +0100, Sascha Hauer wrote:
> On Mon, Nov 22, 2010 at 04:47:51PM +0800, Axel Lin wrote:
> > Remove release_resource() after release_mem_region().
> >
> > Signed-off-by: Axel Lin <[email protected]>
>
> Acked-by: Sascha Hauer <[email protected]>
>
> > ---
> > drivers/mmc/host/mxcmmc.c | 1 -
> > 1 files changed, 0 insertions(+), 1 deletions(-)
> >
> > diff --git a/drivers/mmc/host/mxcmmc.c b/drivers/mmc/host/mxcmmc.c
> > index 2b9f7c8..4428594 100644
> > --- a/drivers/mmc/host/mxcmmc.c
> > +++ b/drivers/mmc/host/mxcmmc.c
> > @@ -967,7 +967,6 @@ static int mxcmci_remove(struct platform_device *pdev)
> > clk_put(host->clk);
> >
> > release_mem_region(host->res->start, resource_size(host->res));
> > - release_resource(host->res);
> >
> > mmc_free_host(mmc);
> >

Pushed to mmc-next for .38, thanks.

--
Chris Ball <[email protected]> <http://printf.net/>
One Laptop Per Child