提交 0709dc97 编写于 作者: S Sonic Zhang 提交者: Wolfram Sang

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

No need to free managed resources any more.
Signed-off-by: NSonic Zhang <sonic.zhang@analog.com>
Signed-off-by: NWolfram Sang <wsa@the-dreams.de>
上级 eae45e5d
...@@ -620,35 +620,27 @@ static int i2c_bfin_twi_probe(struct platform_device *pdev) ...@@ -620,35 +620,27 @@ static int i2c_bfin_twi_probe(struct platform_device *pdev)
int rc; int rc;
unsigned int clkhilow; 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) { if (!iface) {
dev_err(&pdev->dev, "Cannot allocate memory\n"); dev_err(&pdev->dev, "Cannot allocate memory\n");
rc = -ENOMEM; return -ENOMEM;
goto out_error_nomem;
} }
spin_lock_init(&(iface->lock)); spin_lock_init(&(iface->lock));
/* Find and map our resources */ /* Find and map our resources */
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (res == NULL) { iface->regs_base = devm_ioremap_resource(&pdev->dev, res);
dev_err(&pdev->dev, "Cannot get IORESOURCE_MEM\n"); if (IS_ERR(iface->regs_base)) {
rc = -ENOENT;
goto out_error_get_res;
}
iface->regs_base = ioremap(res->start, resource_size(res));
if (iface->regs_base == NULL) {
dev_err(&pdev->dev, "Cannot map IO\n"); dev_err(&pdev->dev, "Cannot map IO\n");
rc = -ENXIO; return PTR_ERR(iface->regs_base);
goto out_error_ioremap;
} }
iface->irq = platform_get_irq(pdev, 0); iface->irq = platform_get_irq(pdev, 0);
if (iface->irq < 0) { if (iface->irq < 0) {
dev_err(&pdev->dev, "No IRQ specified\n"); dev_err(&pdev->dev, "No IRQ specified\n");
rc = -ENOENT; return -ENOENT;
goto out_error_no_irq;
} }
p_adap = &iface->adap; p_adap = &iface->adap;
...@@ -666,15 +658,15 @@ static int i2c_bfin_twi_probe(struct platform_device *pdev) ...@@ -666,15 +658,15 @@ static int i2c_bfin_twi_probe(struct platform_device *pdev)
"i2c-bfin-twi"); "i2c-bfin-twi");
if (rc) { if (rc) {
dev_err(&pdev->dev, "Can't setup pin mux!\n"); 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); 0, pdev->name, iface);
if (rc) { if (rc) {
dev_err(&pdev->dev, "Can't get IRQ %d !\n", iface->irq); dev_err(&pdev->dev, "Can't get IRQ %d !\n", iface->irq);
rc = -ENODEV; rc = -ENODEV;
goto out_error_req_irq; goto out_error;
} }
/* Set TWI internal clock as 10MHz */ /* Set TWI internal clock as 10MHz */
...@@ -695,7 +687,7 @@ static int i2c_bfin_twi_probe(struct platform_device *pdev) ...@@ -695,7 +687,7 @@ static int i2c_bfin_twi_probe(struct platform_device *pdev)
rc = i2c_add_numbered_adapter(p_adap); rc = i2c_add_numbered_adapter(p_adap);
if (rc < 0) { if (rc < 0) {
dev_err(&pdev->dev, "Can't add i2c adapter!\n"); dev_err(&pdev->dev, "Can't add i2c adapter!\n");
goto out_error_add_adapter; goto out_error;
} }
platform_set_drvdata(pdev, iface); platform_set_drvdata(pdev, iface);
...@@ -705,17 +697,8 @@ static int i2c_bfin_twi_probe(struct platform_device *pdev) ...@@ -705,17 +697,8 @@ static int i2c_bfin_twi_probe(struct platform_device *pdev)
return 0; return 0;
out_error_add_adapter: out_error:
free_irq(iface->irq, iface);
out_error_req_irq:
out_error_no_irq:
peripheral_free_list(dev_get_platdata(&pdev->dev)); 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; return rc;
} }
...@@ -724,10 +707,7 @@ static int i2c_bfin_twi_remove(struct platform_device *pdev) ...@@ -724,10 +707,7 @@ static int i2c_bfin_twi_remove(struct platform_device *pdev)
struct bfin_twi_iface *iface = platform_get_drvdata(pdev); struct bfin_twi_iface *iface = platform_get_drvdata(pdev);
i2c_del_adapter(&(iface->adap)); i2c_del_adapter(&(iface->adap));
free_irq(iface->irq, iface);
peripheral_free_list(dev_get_platdata(&pdev->dev)); peripheral_free_list(dev_get_platdata(&pdev->dev));
iounmap(iface->regs_base);
kfree(iface);
return 0; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册