* [PATCH] drivers/mmc/host/sdhci-s3c.c: use devm_ functions
@ 2012-02-18 20:13 Julia Lawall
2012-03-09 4:27 ` Chris Ball
0 siblings, 1 reply; 2+ messages in thread
From: Julia Lawall @ 2012-02-18 20:13 UTC (permalink / raw)
To: Ben Dooks; +Cc: kernel-janitors, Chris Ball, linux-mmc, linux-kernel
From: Julia Lawall <Julia.Lawall@lip6.fr>
The various devm_ functions allocate memory that is released when a driver
detaches. This patch uses these functions for data that is allocated in
the probe function of a platform device and is only freed in the remove
function.
By using devm_ioremap, it also removes a potential memory leak, because
there was no call to iounmap in the probe function.
The call to platform_get_resource was moved just to make it closer to the
place where its result it used.
Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
---
drivers/mmc/host/sdhci-s3c.c | 26 +++-----------------------
1 file changed, 3 insertions(+), 23 deletions(-)
diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
index b19e7d4..10ec7c6 100644
--- a/drivers/mmc/host/sdhci-s3c.c
+++ b/drivers/mmc/host/sdhci-s3c.c
@@ -402,12 +402,6 @@ static int __devinit sdhci_s3c_probe(struct platform_device *pdev)
return irq;
}
- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
- if (!res) {
- dev_err(dev, "no memory specified\n");
- return -ENOENT;
- }
-
host = sdhci_alloc_host(dev, sizeof(struct sdhci_s3c));
if (IS_ERR(host)) {
dev_err(dev, "sdhci_alloc_host() failed\n");
@@ -464,15 +458,9 @@ static int __devinit sdhci_s3c_probe(struct platform_device *pdev)
goto err_no_busclks;
}
- sc->ioarea = request_mem_region(res->start, resource_size(res),
- mmc_hostname(host->mmc));
- if (!sc->ioarea) {
- dev_err(dev, "failed to reserve register area\n");
- ret = -ENXIO;
- goto err_req_regs;
- }
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
- host->ioaddr = ioremap_nocache(res->start, resource_size(res));
+ host->ioaddr = devm_request_and_ioremap(&pdev->dev, res);
if (!host->ioaddr) {
dev_err(dev, "failed to map registers\n");
ret = -ENXIO;
@@ -547,7 +535,7 @@ static int __devinit sdhci_s3c_probe(struct platform_device *pdev)
ret = sdhci_add_host(host);
if (ret) {
dev_err(dev, "sdhci_add_host() failed\n");
- goto err_add_host;
+ goto err_req_regs;
}
/* The following two methods of card detection might call
@@ -561,10 +549,6 @@ static int __devinit sdhci_s3c_probe(struct platform_device *pdev)
return 0;
- err_add_host:
- release_resource(sc->ioarea);
- kfree(sc->ioarea);
-
err_req_regs:
for (ptr = 0; ptr < MAX_BUS_CLK; ptr++) {
if (sc->clk_bus[ptr]) {
@@ -610,10 +594,6 @@ static int __devexit sdhci_s3c_remove(struct platform_device *pdev)
clk_disable(sc->clk_io);
clk_put(sc->clk_io);
- iounmap(host->ioaddr);
- release_resource(sc->ioarea);
- kfree(sc->ioarea);
-
sdhci_free_host(host);
platform_set_drvdata(pdev, NULL);
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] drivers/mmc/host/sdhci-s3c.c: use devm_ functions
2012-02-18 20:13 [PATCH] drivers/mmc/host/sdhci-s3c.c: use devm_ functions Julia Lawall
@ 2012-03-09 4:27 ` Chris Ball
0 siblings, 0 replies; 2+ messages in thread
From: Chris Ball @ 2012-03-09 4:27 UTC (permalink / raw)
To: Julia Lawall; +Cc: Ben Dooks, kernel-janitors, linux-mmc, linux-kernel
Hi Julia,
On Sat, Feb 18 2012, Julia Lawall wrote:
> From: Julia Lawall <Julia.Lawall@lip6.fr>
>
> The various devm_ functions allocate memory that is released when a driver
> detaches. This patch uses these functions for data that is allocated in
> the probe function of a platform device and is only freed in the remove
> function.
>
> By using devm_ioremap, it also removes a potential memory leak, because
> there was no call to iounmap in the probe function.
>
> The call to platform_get_resource was moved just to make it closer to the
> place where its result it used.
>
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Thanks very much, pushed to mmc-next for 3.4.
- Chris.
--
Chris Ball <cjb@laptop.org> <http://printf.net/>
One Laptop Per Child
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-03-09 4:27 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-18 20:13 [PATCH] drivers/mmc/host/sdhci-s3c.c: use devm_ functions Julia Lawall
2012-03-09 4:27 ` Chris Ball
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®