* [PATCH RFC v3 2/3] i2c: pxa: convert to devm_* API
@ 2013-05-23 12:00 Libo Chen
[not found] ` <1369310408-10348-1-git-send-email-libo.chen-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
0 siblings, 1 reply; 5+ messages in thread
From: Libo Chen @ 2013-05-23 12:00 UTC (permalink / raw)
To: wsa; +Cc: guz.fnst, sonic.zhang, linux-i2c, linux-kernel, lizefan,
libo.chen
when i2c malloc faild, we should not try to call release_mem_region.
aovid this, convert them to devm_* API.
Signed-off-by: Libo Chen <libo.chen@huawei.com>
---
drivers/i2c/busses/i2c-pxa.c | 63 ++++++++++--------------------------------
1 files changed, 15 insertions(+), 48 deletions(-)
diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
index ea6d45d..7b10102 100644
--- a/drivers/i2c/busses/i2c-pxa.c
+++ b/drivers/i2c/busses/i2c-pxa.c
@@ -1091,10 +1091,9 @@ static int i2c_pxa_probe(struct platform_device *dev)
struct resource *res = NULL;
int ret, irq;
- i2c = kzalloc(sizeof(struct pxa_i2c), GFP_KERNEL);
+ i2c = devm_kzalloc(&dev->dev, sizeof(struct pxa_i2c), GFP_KERNEL);
if (!i2c) {
- ret = -ENOMEM;
- goto emalloc;
+ return -ENOMEM;
}
/* Default adapter num to device id; i2c_pxa_probe_dt can override. */
@@ -1104,19 +1103,11 @@ static int i2c_pxa_probe(struct platform_device *dev)
if (ret > 0)
ret = i2c_pxa_probe_pdata(dev, i2c, &i2c_type);
if (ret < 0)
- goto eclk;
+ return ret;
- res = platform_get_resource(dev, IORESOURCE_MEM, 0);
irq = platform_get_irq(dev, 0);
- if (res == NULL || irq < 0) {
- ret = -ENODEV;
- goto eclk;
- }
-
- if (!request_mem_region(res->start, resource_size(res), res->name)) {
- ret = -ENOMEM;
- goto eclk;
- }
+ if (irq < 0)
+ return -ENODEV;
i2c->adap.owner = THIS_MODULE;
i2c->adap.retries = 5;
@@ -1126,17 +1117,15 @@ static int i2c_pxa_probe(struct platform_device *dev)
strlcpy(i2c->adap.name, "pxa_i2c-i2c", sizeof(i2c->adap.name));
- i2c->clk = clk_get(&dev->dev, NULL);
+ i2c->clk = devm_clk_get(&dev->dev, NULL);
if (IS_ERR(i2c->clk)) {
- ret = PTR_ERR(i2c->clk);
- goto eclk;
+ return PTR_ERR(i2c->clk);
}
- i2c->reg_base = ioremap(res->start, resource_size(res));
- if (!i2c->reg_base) {
- ret = -EIO;
- goto eremap;
- }
+ res = platform_get_resource(dev, IORESOURCE_MEM, 0);
+ i2c->reg_base = devm_ioremap_resource(&dev->dev, res);
+ if (IS_ERR(i2c->reg_base))
+ return PTR_ERR(i2c->reg_bas);
i2c->reg_ibmr = i2c->reg_base + pxa_reg_layout[i2c_type].ibmr;
i2c->reg_idbr = i2c->reg_base + pxa_reg_layout[i2c_type].idbr;
@@ -1166,10 +1155,10 @@ static int i2c_pxa_probe(struct platform_device *dev)
i2c->adap.algo = &i2c_pxa_pio_algorithm;
} else {
i2c->adap.algo = &i2c_pxa_algorithm;
- ret = request_irq(irq, i2c_pxa_handler, IRQF_SHARED,
- dev_name(&dev->dev), i2c);
+ ret = devm_request_irq(&dev->dev, irq, i2c_pxa_handler,
+ IRQF_SHARED, dev_name(&dev->dev), i2c);
if (ret)
- goto ereqirq;
+ return ret;
}
i2c_pxa_reset(i2c);
@@ -1183,7 +1172,7 @@ static int i2c_pxa_probe(struct platform_device *dev)
ret = i2c_add_numbered_adapter(&i2c->adap);
if (ret < 0) {
printk(KERN_INFO "I2C: Failed to add bus\n");
- goto eadapt;
+ return ret;
}
of_i2c_register_devices(&i2c->adap);
@@ -1198,19 +1187,6 @@ static int i2c_pxa_probe(struct platform_device *dev)
#endif
return 0;
-eadapt:
- if (!i2c->use_pio)
- free_irq(irq, i2c);
-ereqirq:
- clk_disable(i2c->clk);
- iounmap(i2c->reg_base);
-eremap:
- clk_put(i2c->clk);
-eclk:
- kfree(i2c);
-emalloc:
- release_mem_region(res->start, resource_size(res));
- return ret;
}
static int i2c_pxa_remove(struct platform_device *dev)
@@ -1218,15 +1194,6 @@ static int i2c_pxa_remove(struct platform_device *dev)
struct pxa_i2c *i2c = platform_get_drvdata(dev);
i2c_del_adapter(&i2c->adap);
- if (!i2c->use_pio)
- free_irq(i2c->irq, i2c);
-
- clk_disable(i2c->clk);
- clk_put(i2c->clk);
-
- iounmap(i2c->reg_base);
- release_mem_region(i2c->iobase, i2c->iosize);
- kfree(i2c);
return 0;
}
--
1.7.1
^ permalink raw reply related [flat|nested] 5+ messages in thread[parent not found: <1369310408-10348-1-git-send-email-libo.chen-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>]
* Re: [PATCH RFC v3 2/3] i2c: pxa: convert to devm_* API [not found] ` <1369310408-10348-1-git-send-email-libo.chen-hv44wF8Li93QT0dZR+AlfA@public.gmane.org> @ 2013-05-24 3:35 ` Gu Zheng [not found] ` <519EDFFC.5020308-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org> 2013-06-12 10:02 ` Wolfram Sang 1 sibling, 1 reply; 5+ messages in thread From: Gu Zheng @ 2013-05-24 3:35 UTC (permalink / raw) To: Libo Chen Cc: wsa-z923LK4zBo2bacvFa/9K2g, sonic.zhang-OyLXuOCK7orQT0dZR+AlfA, linux-i2c-u79uwXL29TY76Z2rM5mHXA, linux-kernel-u79uwXL29TY76Z2rM5mHXA, lizefan-hv44wF8Li93QT0dZR+AlfA Hi Libo, I think you can merge patch 1/3 and 2/3, they do the same thing that using devm_* API to simplify and make the code clean, and the additional goal is it also can fix a bug. Besides, maybe you need to change the title and make it clear and self-described. Thanks, Gu On 05/23/2013 08:00 PM, Libo Chen wrote: > when i2c malloc faild, we should not try to call release_mem_region. > aovid this, convert them to devm_* API. > > Signed-off-by: Libo Chen <libo.chen-hv44wF8Li93QT0dZR+AlfA@public.gmane.org> > --- > drivers/i2c/busses/i2c-pxa.c | 63 ++++++++++-------------------------------- > 1 files changed, 15 insertions(+), 48 deletions(-) > > diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c > index ea6d45d..7b10102 100644 > --- a/drivers/i2c/busses/i2c-pxa.c > +++ b/drivers/i2c/busses/i2c-pxa.c > @@ -1091,10 +1091,9 @@ static int i2c_pxa_probe(struct platform_device *dev) > struct resource *res = NULL; > int ret, irq; > > - i2c = kzalloc(sizeof(struct pxa_i2c), GFP_KERNEL); > + i2c = devm_kzalloc(&dev->dev, sizeof(struct pxa_i2c), GFP_KERNEL); > if (!i2c) { > - ret = -ENOMEM; > - goto emalloc; > + return -ENOMEM; > } The {} pair is no longer needed. > > /* Default adapter num to device id; i2c_pxa_probe_dt can override. */ > @@ -1104,19 +1103,11 @@ static int i2c_pxa_probe(struct platform_device *dev) > if (ret > 0) > ret = i2c_pxa_probe_pdata(dev, i2c, &i2c_type); > if (ret < 0) > - goto eclk; > + return ret; > > - res = platform_get_resource(dev, IORESOURCE_MEM, 0); > irq = platform_get_irq(dev, 0); > - if (res == NULL || irq < 0) { > - ret = -ENODEV; > - goto eclk; > - } > - > - if (!request_mem_region(res->start, resource_size(res), res->name)) { > - ret = -ENOMEM; > - goto eclk; > - } > + if (irq < 0) > + return -ENODEV; > > i2c->adap.owner = THIS_MODULE; > i2c->adap.retries = 5; > @@ -1126,17 +1117,15 @@ static int i2c_pxa_probe(struct platform_device *dev) > > strlcpy(i2c->adap.name, "pxa_i2c-i2c", sizeof(i2c->adap.name)); > > - i2c->clk = clk_get(&dev->dev, NULL); > + i2c->clk = devm_clk_get(&dev->dev, NULL); > if (IS_ERR(i2c->clk)) { > - ret = PTR_ERR(i2c->clk); > - goto eclk; > + return PTR_ERR(i2c->clk); > } the same. > > - i2c->reg_base = ioremap(res->start, resource_size(res)); > - if (!i2c->reg_base) { > - ret = -EIO; > - goto eremap; > - } > + res = platform_get_resource(dev, IORESOURCE_MEM, 0); > + i2c->reg_base = devm_ioremap_resource(&dev->dev, res); > + if (IS_ERR(i2c->reg_base)) > + return PTR_ERR(i2c->reg_bas); > > i2c->reg_ibmr = i2c->reg_base + pxa_reg_layout[i2c_type].ibmr; > i2c->reg_idbr = i2c->reg_base + pxa_reg_layout[i2c_type].idbr; > @@ -1166,10 +1155,10 @@ static int i2c_pxa_probe(struct platform_device *dev) > i2c->adap.algo = &i2c_pxa_pio_algorithm; > } else { > i2c->adap.algo = &i2c_pxa_algorithm; > - ret = request_irq(irq, i2c_pxa_handler, IRQF_SHARED, > - dev_name(&dev->dev), i2c); > + ret = devm_request_irq(&dev->dev, irq, i2c_pxa_handler, > + IRQF_SHARED, dev_name(&dev->dev), i2c); > if (ret) > - goto ereqirq; > + return ret; > } > > i2c_pxa_reset(i2c); > @@ -1183,7 +1172,7 @@ static int i2c_pxa_probe(struct platform_device *dev) > ret = i2c_add_numbered_adapter(&i2c->adap); > if (ret < 0) { > printk(KERN_INFO "I2C: Failed to add bus\n"); > - goto eadapt; > + return ret; > } > of_i2c_register_devices(&i2c->adap); > > @@ -1198,19 +1187,6 @@ static int i2c_pxa_probe(struct platform_device *dev) > #endif > return 0; > > -eadapt: > - if (!i2c->use_pio) > - free_irq(irq, i2c); > -ereqirq: > - clk_disable(i2c->clk); > - iounmap(i2c->reg_base); > -eremap: > - clk_put(i2c->clk); > -eclk: > - kfree(i2c); > -emalloc: > - release_mem_region(res->start, resource_size(res)); > - return ret; > } > > static int i2c_pxa_remove(struct platform_device *dev) > @@ -1218,15 +1194,6 @@ static int i2c_pxa_remove(struct platform_device *dev) > struct pxa_i2c *i2c = platform_get_drvdata(dev); > > i2c_del_adapter(&i2c->adap); > - if (!i2c->use_pio) > - free_irq(i2c->irq, i2c); > - > - clk_disable(i2c->clk); > - clk_put(i2c->clk); > - > - iounmap(i2c->reg_base); > - release_mem_region(i2c->iobase, i2c->iosize); > - kfree(i2c); > > return 0; > } ^ permalink raw reply [flat|nested] 5+ messages in thread
[parent not found: <519EDFFC.5020308-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>]
* Re: [PATCH RFC v3 2/3] i2c: pxa: convert to devm_* API [not found] ` <519EDFFC.5020308-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org> @ 2013-05-24 3:42 ` Li Zefan 2013-05-24 3:51 ` Libo Chen 1 sibling, 0 replies; 5+ messages in thread From: Li Zefan @ 2013-05-24 3:42 UTC (permalink / raw) To: Gu Zheng Cc: Libo Chen, wsa-z923LK4zBo2bacvFa/9K2g, sonic.zhang-OyLXuOCK7orQT0dZR+AlfA, linux-i2c-u79uwXL29TY76Z2rM5mHXA, linux-kernel-u79uwXL29TY76Z2rM5mHXA On 2013/5/24 11:35, Gu Zheng wrote: > Hi Libo, > I think you can merge patch 1/3 and 2/3, they do the same thing that using devm_* API to simplify > and make the code clean, and the additional goal is it also can fix a bug. nope. they should be separated. > Besides, maybe you need to > change the title and make it clear and self-described. > ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH RFC v3 2/3] i2c: pxa: convert to devm_* API [not found] ` <519EDFFC.5020308-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org> 2013-05-24 3:42 ` Li Zefan @ 2013-05-24 3:51 ` Libo Chen 1 sibling, 0 replies; 5+ messages in thread From: Libo Chen @ 2013-05-24 3:51 UTC (permalink / raw) To: Gu Zheng Cc: Libo Chen, wsa-z923LK4zBo2bacvFa/9K2g, sonic.zhang-OyLXuOCK7orQT0dZR+AlfA, linux-i2c-u79uwXL29TY76Z2rM5mHXA, linux-kernel-u79uwXL29TY76Z2rM5mHXA, lizefan-hv44wF8Li93QT0dZR+AlfA On 2013/5/24 11:35, Gu Zheng wrote: > Hi Libo, > I think you can merge patch 1/3 and 2/3, they e thdo the saming that using devm_* API to simplify > and make the code clean, and the additional goal is it also can fix a bug. Besides, maybe you need to > change the title and make it clear and self-described. > > Thanks, > Gu thanks for your suggestion. But, I had referenced other guy`s patch title, they usually do like this, so I think it is enough. Regards, Libo ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH RFC v3 2/3] i2c: pxa: convert to devm_* API [not found] ` <1369310408-10348-1-git-send-email-libo.chen-hv44wF8Li93QT0dZR+AlfA@public.gmane.org> 2013-05-24 3:35 ` Gu Zheng @ 2013-06-12 10:02 ` Wolfram Sang 1 sibling, 0 replies; 5+ messages in thread From: Wolfram Sang @ 2013-06-12 10:02 UTC (permalink / raw) To: Libo Chen Cc: guz.fnst-BthXqXjhjHXQFUHtdCDX3A, sonic.zhang-OyLXuOCK7orQT0dZR+AlfA, linux-i2c-u79uwXL29TY76Z2rM5mHXA, linux-kernel-u79uwXL29TY76Z2rM5mHXA, lizefan-hv44wF8Li93QT0dZR+AlfA [-- Attachment #1: Type: text/plain, Size: 1356 bytes --] On Thu, May 23, 2013 at 08:00:08PM +0800, Libo Chen wrote: > when i2c malloc faild, we should not try to call release_mem_region. > aovid this, convert them to devm_* API. > > Signed-off-by: Libo Chen <libo.chen-hv44wF8Li93QT0dZR+AlfA@public.gmane.org> First, you did it right. This patch should not be combined with 1/3. It is not a trivial cleanup, so I prefer to keep them seperated. BTW did you test these patches on real hardware? > @@ -1198,19 +1187,6 @@ static int i2c_pxa_probe(struct platform_device *dev) > #endif > return 0; > > -eadapt: > - if (!i2c->use_pio) > - free_irq(irq, i2c); > -ereqirq: > - clk_disable(i2c->clk); > - iounmap(i2c->reg_base); > -eremap: > - clk_put(i2c->clk); > -eclk: > - kfree(i2c); > -emalloc: > - release_mem_region(res->start, resource_size(res)); > - return ret; > } > > static int i2c_pxa_remove(struct platform_device *dev) > @@ -1218,15 +1194,6 @@ static int i2c_pxa_remove(struct platform_device *dev) > struct pxa_i2c *i2c = platform_get_drvdata(dev); > > i2c_del_adapter(&i2c->adap); > - if (!i2c->use_pio) > - free_irq(i2c->irq, i2c); > - > - clk_disable(i2c->clk); > - clk_put(i2c->clk); > - > - iounmap(i2c->reg_base); > - release_mem_region(i2c->iobase, i2c->iosize); > - kfree(i2c); You remove too much. Who disables the clock now? [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 836 bytes --] ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-06-12 10:02 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-23 12:00 [PATCH RFC v3 2/3] i2c: pxa: convert to devm_* API Libo Chen
[not found] ` <1369310408-10348-1-git-send-email-libo.chen-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2013-05-24 3:35 ` Gu Zheng
[not found] ` <519EDFFC.5020308-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
2013-05-24 3:42 ` Li Zefan
2013-05-24 3:51 ` Libo Chen
2013-06-12 10:02 ` Wolfram Sang
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).