diff mbox

[v2] i2c: bfin: turn to Resource-managed API in probe function

Message ID 1400751219-7943-1-git-send-email-sonic.adi@gmail.com
State Changes Requested
Headers show

Commit Message

Sonic Zhang May 22, 2014, 9:33 a.m. UTC
From: Sonic Zhang <sonic.zhang@analog.com>

No need to free managed resources any more.

Signed-off-by: Sonic Zhang <sonic.zhang@analog.com>

---
v2-changes:
- Remove resource checking. devm_ioremap_resource will do it.
- Remove cast of the return value.
- Remove free_irq from the module remove function.
---
 drivers/i2c/busses/i2c-bfin-twi.c | 44 +++++++++++----------------------------
 1 file changed, 12 insertions(+), 32 deletions(-)

Comments

Wolfram Sang May 22, 2014, 11:13 a.m. UTC | #1
On Thu, May 22, 2014 at 05:33:39PM +0800, Sonic Zhang wrote:
> From: Sonic Zhang <sonic.zhang@analog.com>
> 
> No need to free managed resources any more.
> 
> Signed-off-by: Sonic Zhang <sonic.zhang@analog.com>
> 
> ---
> v2-changes:
> - Remove resource checking. devm_ioremap_resource will do it.
> - Remove cast of the return value.
> - Remove free_irq from the module remove function.

How did you test it?
Sonic Zhang May 23, 2014, 2:38 a.m. UTC | #2
Hi Wolfram,

On Thu, May 22, 2014 at 7:13 PM, Wolfram Sang <wsa@the-dreams.de> wrote:
> On Thu, May 22, 2014 at 05:33:39PM +0800, Sonic Zhang wrote:
>> From: Sonic Zhang <sonic.zhang@analog.com>
>>
>> No need to free managed resources any more.
>>
>> Signed-off-by: Sonic Zhang <sonic.zhang@analog.com>
>>
>> ---
>> v2-changes:
>> - Remove resource checking. devm_ioremap_resource will do it.
>> - Remove cast of the return value.
>> - Remove free_irq from the module remove function.
>
> How did you test it?
>

root:/> modprobe i2c-bfin-twi
i2c-bfin-twi i2c-bfin-twi.0: Blackfin on-chip I2C TWI Contoller,
regs_base@ffc01e00
i2c-bfin-twi i2c-bfin-twi.1: Blackfin on-chip I2C TWI Contoller,
regs_base@ffc01f00
root:/> random: nonblocking pool is initialized

root:/> lsmod
Module                  Size  Used by
i2c_bfin_twi            4322  0
root:/> rmmod i2c-bfin-twi
root:/> lsmod
Module                  Size  Used by
root:/>
root:/> modprobe i2c-bfin-twi
i2c-bfin-twi i2c-bfin-twi.0: Blackfin on-chip I2C TWI Contoller,
regs_base@ffc01e00
i2c-bfin-twi i2c-bfin-twi.1: Blackfin on-chip I2C TWI Contoller,
regs_base@ffc01f00
root:/> ls /dev/i2c-*
/dev/i2c-0  /dev/i2c-1
root:/> rmmod i2c-bfin-twi
root:/> ls /dev/i2c-*
ls: /dev/i2c-*: No such file or directory
root:/>


Regards,

Sonnic
--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Wolfram Sang June 2, 2014, 12:42 p.m. UTC | #3
> +	if (IS_ERR((void *)iface->regs_base)) {

You missed this cast.
diff mbox

Patch

diff --git a/drivers/i2c/busses/i2c-bfin-twi.c b/drivers/i2c/busses/i2c-bfin-twi.c
index e6d5162..9ef1e25 100644
--- a/drivers/i2c/busses/i2c-bfin-twi.c
+++ b/drivers/i2c/busses/i2c-bfin-twi.c
@@ -620,35 +620,27 @@  static int i2c_bfin_twi_probe(struct platform_device *pdev)
 	int rc;
 	unsigned int clkhilow;
 
-	iface = kzalloc(sizeof(struct bfin_twi_iface), GFP_KERNEL);
+	iface = devm_kzalloc(&pdev->dev, sizeof(struct bfin_twi_iface),
+			GFP_KERNEL);
 	if (!iface) {
 		dev_err(&pdev->dev, "Cannot allocate memory\n");
-		rc = -ENOMEM;
-		goto out_error_nomem;
+		return -ENOMEM;
 	}
 
 	spin_lock_init(&(iface->lock));
 
 	/* Find and map our resources */
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (res == NULL) {
-		dev_err(&pdev->dev, "Cannot get IORESOURCE_MEM\n");
-		rc = -ENOENT;
-		goto out_error_get_res;
-	}
-
-	iface->regs_base = ioremap(res->start, resource_size(res));
-	if (iface->regs_base == NULL) {
+	iface->regs_base = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR((void *)iface->regs_base)) {
 		dev_err(&pdev->dev, "Cannot map IO\n");
-		rc = -ENXIO;
-		goto out_error_ioremap;
+		return PTR_ERR(iface->regs_base);
 	}
 
 	iface->irq = platform_get_irq(pdev, 0);
 	if (iface->irq < 0) {
 		dev_err(&pdev->dev, "No IRQ specified\n");
-		rc = -ENOENT;
-		goto out_error_no_irq;
+		return -ENOENT;
 	}
 
 	p_adap = &iface->adap;
@@ -666,15 +658,15 @@  static int i2c_bfin_twi_probe(struct platform_device *pdev)
 			"i2c-bfin-twi");
 	if (rc) {
 		dev_err(&pdev->dev, "Can't setup pin mux!\n");
-		goto out_error_pin_mux;
+		return -EBUSY;
 	}
 
-	rc = request_irq(iface->irq, bfin_twi_interrupt_entry,
+	rc = devm_request_irq(&pdev->dev, iface->irq, bfin_twi_interrupt_entry,
 		0, pdev->name, iface);
 	if (rc) {
 		dev_err(&pdev->dev, "Can't get IRQ %d !\n", iface->irq);
 		rc = -ENODEV;
-		goto out_error_req_irq;
+		goto out_error;
 	}
 
 	/* Set TWI internal clock as 10MHz */
@@ -695,7 +687,7 @@  static int i2c_bfin_twi_probe(struct platform_device *pdev)
 	rc = i2c_add_numbered_adapter(p_adap);
 	if (rc < 0) {
 		dev_err(&pdev->dev, "Can't add i2c adapter!\n");
-		goto out_error_add_adapter;
+		goto out_error;
 	}
 
 	platform_set_drvdata(pdev, iface);
@@ -705,17 +697,8 @@  static int i2c_bfin_twi_probe(struct platform_device *pdev)
 
 	return 0;
 
-out_error_add_adapter:
-	free_irq(iface->irq, iface);
-out_error_req_irq:
-out_error_no_irq:
+out_error:
 	peripheral_free_list(dev_get_platdata(&pdev->dev));
-out_error_pin_mux:
-	iounmap(iface->regs_base);
-out_error_ioremap:
-out_error_get_res:
-	kfree(iface);
-out_error_nomem:
 	return rc;
 }
 
@@ -724,10 +707,7 @@  static int i2c_bfin_twi_remove(struct platform_device *pdev)
 	struct bfin_twi_iface *iface = platform_get_drvdata(pdev);
 
 	i2c_del_adapter(&(iface->adap));
-	free_irq(iface->irq, iface);
 	peripheral_free_list(dev_get_platdata(&pdev->dev));
-	iounmap(iface->regs_base);
-	kfree(iface);
 
 	return 0;
 }