lkml.org 
[lkml]   [2012]   [Aug]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 2/6] i2c: at91: use devm_ functions
Date
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.

This code was missing a free of adapter in the remove function.

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
Not compiled.

drivers/i2c/busses/i2c-at91.c | 37 ++++++++++---------------------------
1 file changed, 10 insertions(+), 27 deletions(-)

diff --git a/drivers/i2c/busses/i2c-at91.c b/drivers/i2c/busses/i2c-at91.c
index e24484b..b921858 100644
--- a/drivers/i2c/busses/i2c-at91.c
+++ b/drivers/i2c/busses/i2c-at91.c
@@ -196,30 +196,23 @@ static int __devinit at91_i2c_probe(struct platform_device *pdev)
int rc;

res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
- if (!res)
- return -ENXIO;

- if (!request_mem_region(res->start, resource_size(res), "at91_i2c"))
- return -EBUSY;
-
- twi_base = ioremap(res->start, resource_size(res));
- if (!twi_base) {
- rc = -ENOMEM;
- goto fail0;
- }
+ twi_base = devm_request_and_ioremap(&pdev->dev, res);
+ if (!twi_base)
+ return -ENOMEM;

twi_clk = clk_get(NULL, "twi_clk");
if (IS_ERR(twi_clk)) {
dev_err(&pdev->dev, "no clock defined\n");
- rc = -ENODEV;
- goto fail1;
+ return -ENODEV;
}

- adapter = kzalloc(sizeof(struct i2c_adapter), GFP_KERNEL);
+ adapter = devm_kzalloc(&pdev->dev, sizeof(struct i2c_adapter),
+ GFP_KERNEL);
if (adapter == NULL) {
dev_err(&pdev->dev, "can't allocate inteface!\n");
rc = -ENOMEM;
- goto fail2;
+ goto fail1;
}
snprintf(adapter->name, sizeof(adapter->name), "AT91");
adapter->algo = &at91_algorithm;
@@ -236,22 +229,17 @@ static int __devinit at91_i2c_probe(struct platform_device *pdev)
if (rc) {
dev_err(&pdev->dev, "Adapter %s registration failed\n",
adapter->name);
- goto fail3;
+ goto fail2;
}

dev_info(&pdev->dev, "AT91 i2c bus driver.\n");
return 0;

-fail3:
+fail2:
platform_set_drvdata(pdev, NULL);
- kfree(adapter);
clk_disable(twi_clk);
-fail2:
- clk_put(twi_clk);
fail1:
- iounmap(twi_base);
-fail0:
- release_mem_region(res->start, resource_size(res));
+ clk_put(twi_clk);

return rc;
}
@@ -259,16 +247,11 @@ fail0:
static int __devexit at91_i2c_remove(struct platform_device *pdev)
{
struct i2c_adapter *adapter = platform_get_drvdata(pdev);
- struct resource *res;
int rc;

rc = i2c_del_adapter(adapter);
platform_set_drvdata(pdev, NULL);

- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
- iounmap(twi_base);
- release_mem_region(res->start, resource_size(res));
-
clk_disable(twi_clk); /* disable peripheral clock */
clk_put(twi_clk);



\
 
 \ /
  Last update: 2012-08-25 20:21    [W:0.028 / U:0.060 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site