* [PATCH] i2c: bfin: turn to Resource-managed API in probe function
@ 2014-03-10 10:03 Sonic Zhang
[not found] ` <1394445784-4653-1-git-send-email-sonic.adi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
0 siblings, 1 reply; 4+ messages in thread
From: Sonic Zhang @ 2014-03-10 10:03 UTC (permalink / raw)
To: Wolfram Sang, linux-i2c-u79uwXL29TY76Z2rM5mHXA
Cc: adi-buildroot-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, Sonic Zhang
From: Sonic Zhang <sonic.zhang-OyLXuOCK7orQT0dZR+AlfA@public.gmane.org>
No need to free managed resources any more.
Signed-off-by: Sonic Zhang <sonic.zhang-OyLXuOCK7orQT0dZR+AlfA@public.gmane.org>
---
drivers/i2c/busses/i2c-bfin-twi.c | 40 +++++++++++++--------------------------
1 file changed, 13 insertions(+), 27 deletions(-)
diff --git a/drivers/i2c/busses/i2c-bfin-twi.c b/drivers/i2c/busses/i2c-bfin-twi.c
index 3b9bd9a..a5630c6 100644
--- a/drivers/i2c/busses/i2c-bfin-twi.c
+++ b/drivers/i2c/busses/i2c-bfin-twi.c
@@ -633,11 +633,11 @@ 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));
@@ -646,22 +646,19 @@ static int i2c_bfin_twi_probe(struct platform_device *pdev)
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;
+ return -ENOENT;
}
- 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((void *)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;
@@ -679,15 +676,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 */
@@ -709,7 +706,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);
@@ -719,17 +716,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;
}
@@ -740,8 +728,6 @@ static int i2c_bfin_twi_remove(struct platform_device *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;
}
--
1.8.2.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] i2c: bfin: turn to Resource-managed API in probe function
[not found] ` <1394445784-4653-1-git-send-email-sonic.adi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2014-03-25 8:42 ` Sonic Zhang
2014-05-21 8:05 ` Wolfram Sang
1 sibling, 0 replies; 4+ messages in thread
From: Sonic Zhang @ 2014-03-25 8:42 UTC (permalink / raw)
To: Wolfram Sang, linux-i2c-u79uwXL29TY76Z2rM5mHXA
Cc: adi-buildroot-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, Sonic Zhang
PING
On Mon, Mar 10, 2014 at 6:03 PM, Sonic Zhang <sonic.adi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> From: Sonic Zhang <sonic.zhang-OyLXuOCK7orQT0dZR+AlfA@public.gmane.org>
>
> No need to free managed resources any more.
>
> Signed-off-by: Sonic Zhang <sonic.zhang-OyLXuOCK7orQT0dZR+AlfA@public.gmane.org>
> ---
> drivers/i2c/busses/i2c-bfin-twi.c | 40 +++++++++++++--------------------------
> 1 file changed, 13 insertions(+), 27 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-bfin-twi.c b/drivers/i2c/busses/i2c-bfin-twi.c
> index 3b9bd9a..a5630c6 100644
> --- a/drivers/i2c/busses/i2c-bfin-twi.c
> +++ b/drivers/i2c/busses/i2c-bfin-twi.c
> @@ -633,11 +633,11 @@ 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));
> @@ -646,22 +646,19 @@ static int i2c_bfin_twi_probe(struct platform_device *pdev)
> 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;
> + return -ENOENT;
> }
>
> - 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((void *)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;
> @@ -679,15 +676,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 */
> @@ -709,7 +706,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);
> @@ -719,17 +716,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;
> }
>
> @@ -740,8 +728,6 @@ static int i2c_bfin_twi_remove(struct platform_device *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;
> }
> --
> 1.8.2.3
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
> the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] i2c: bfin: turn to Resource-managed API in probe function
[not found] ` <1394445784-4653-1-git-send-email-sonic.adi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-03-25 8:42 ` Sonic Zhang
@ 2014-05-21 8:05 ` Wolfram Sang
2014-05-22 9:12 ` Sonic Zhang
1 sibling, 1 reply; 4+ messages in thread
From: Wolfram Sang @ 2014-05-21 8:05 UTC (permalink / raw)
To: Sonic Zhang
Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA,
adi-buildroot-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, Sonic Zhang
[-- Attachment #1: Type: text/plain, Size: 1078 bytes --]
> @@ -646,22 +646,19 @@ static int i2c_bfin_twi_probe(struct platform_device *pdev)
> 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;
> + return -ENOENT;
You don't need to check the resource. devm_ioremap_resource will do it.
> - 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((void *)iface->regs_base);
Do we need the casts?
> @@ -740,8 +728,6 @@ static int i2c_bfin_twi_remove(struct platform_device *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);
You missed to remove the free irq.
Have you actually tried unloading the module?
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] i2c: bfin: turn to Resource-managed API in probe function
2014-05-21 8:05 ` Wolfram Sang
@ 2014-05-22 9:12 ` Sonic Zhang
0 siblings, 0 replies; 4+ messages in thread
From: Sonic Zhang @ 2014-05-22 9:12 UTC (permalink / raw)
To: Wolfram Sang
Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA,
adi-buildroot-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, Sonic Zhang
Hi Wolfram,
On Wed, May 21, 2014 at 4:05 PM, Wolfram Sang <wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org> wrote:
>
>> @@ -646,22 +646,19 @@ static int i2c_bfin_twi_probe(struct platform_device *pdev)
>> 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;
>> + return -ENOENT;
>
> You don't need to check the resource. devm_ioremap_resource will do it.
OK
>
>> - 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((void *)iface->regs_base);
>
> Do we need the casts?
No. I will remove the cast.
>
>> @@ -740,8 +728,6 @@ static int i2c_bfin_twi_remove(struct platform_device *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);
>
> You missed to remove the free irq.
>
> Have you actually tried unloading the module?
>
Ok. The free_irq should be removed.
I will send a new patch.
Thank you.
Sonic
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-05-22 9:12 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-10 10:03 [PATCH] i2c: bfin: turn to Resource-managed API in probe function Sonic Zhang
[not found] ` <1394445784-4653-1-git-send-email-sonic.adi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-03-25 8:42 ` Sonic Zhang
2014-05-21 8:05 ` Wolfram Sang
2014-05-22 9:12 ` Sonic Zhang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).