linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] i2c: simtec: Convert to use devm_* APIs
@ 2016-04-12  8:30 Axel Lin
  2016-04-12 21:48 ` Wolfram Sang
  0 siblings, 1 reply; 4+ messages in thread
From: Axel Lin @ 2016-04-12  8:30 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: Ben Dooks, linux-i2c

Use devm_* APIs to simplify the code a bit.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
 drivers/i2c/busses/i2c-simtec.c | 52 +++++------------------------------------
 1 file changed, 6 insertions(+), 46 deletions(-)

diff --git a/drivers/i2c/busses/i2c-simtec.c b/drivers/i2c/busses/i2c-simtec.c
index b4685bb..46b88d5 100644
--- a/drivers/i2c/busses/i2c-simtec.c
+++ b/drivers/i2c/busses/i2c-simtec.c
@@ -25,7 +25,6 @@
 #include <linux/i2c-algo-bit.h>
 
 struct simtec_i2c_data {
-	struct resource		*ioarea;
 	void __iomem		*reg;
 	struct i2c_adapter	 adap;
 	struct i2c_algo_bit_data bit;
@@ -69,37 +68,18 @@ static int simtec_i2c_probe(struct platform_device *dev)
 {
 	struct simtec_i2c_data *pd;
 	struct resource *res;
-	int size;
-	int ret;
 
-	pd = kzalloc(sizeof(struct simtec_i2c_data), GFP_KERNEL);
+	pd = devm_kzalloc(&dev->dev, sizeof(struct simtec_i2c_data),
+			  GFP_KERNEL);
 	if (pd == NULL)
 		return -ENOMEM;
 
 	platform_set_drvdata(dev, pd);
 
 	res = platform_get_resource(dev, IORESOURCE_MEM, 0);
-	if (res == NULL) {
-		dev_err(&dev->dev, "cannot find IO resource\n");
-		ret = -ENOENT;
-		goto err;
-	}
-
-	size = resource_size(res);
-
-	pd->ioarea = request_mem_region(res->start, size, dev->name);
-	if (pd->ioarea == NULL) {
-		dev_err(&dev->dev, "cannot request IO\n");
-		ret = -ENXIO;
-		goto err;
-	}
-
-	pd->reg = ioremap(res->start, size);
-	if (pd->reg == NULL) {
-		dev_err(&dev->dev, "cannot map IO\n");
-		ret = -ENXIO;
-		goto err_res;
-	}
+	pd->reg = devm_ioremap_resource(&dev->dev, res);
+	if (IS_ERR(pd->reg))
+		return PTR_ERR(pd->reg);
 
 	/* setup the private data */
 
@@ -117,22 +97,7 @@ static int simtec_i2c_probe(struct platform_device *dev)
 	pd->bit.timeout = HZ;
 	pd->bit.udelay = 20;
 
-	ret = i2c_bit_add_bus(&pd->adap);
-	if (ret)
-		goto err_all;
-
-	return 0;
-
- err_all:
-	iounmap(pd->reg);
-
- err_res:
-	release_resource(pd->ioarea);
-	kfree(pd->ioarea);
-
- err:
-	kfree(pd);
-	return ret;
+	return i2c_bit_add_bus(&pd->adap);
 }
 
 static int simtec_i2c_remove(struct platform_device *dev)
@@ -141,11 +106,6 @@ static int simtec_i2c_remove(struct platform_device *dev)
 
 	i2c_del_adapter(&pd->adap);
 
-	iounmap(pd->reg);
-	release_resource(pd->ioarea);
-	kfree(pd->ioarea);
-	kfree(pd);
-
 	return 0;
 }
 
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] i2c: simtec: Convert to use devm_* APIs
  2016-04-12  8:30 [PATCH] i2c: simtec: Convert to use devm_* APIs Axel Lin
@ 2016-04-12 21:48 ` Wolfram Sang
  2016-04-13  0:43   ` Axel Lin
  0 siblings, 1 reply; 4+ messages in thread
From: Wolfram Sang @ 2016-04-12 21:48 UTC (permalink / raw)
  To: Axel Lin; +Cc: Ben Dooks, linux-i2c

[-- Attachment #1: Type: text/plain, Size: 210 bytes --]

On Tue, Apr 12, 2016 at 04:30:14PM +0800, Axel Lin wrote:
> Use devm_* APIs to simplify the code a bit.
> 
> Signed-off-by: Axel Lin <axel.lin@ingics.com>

Thanks! Were you able to test it on hardware?


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] i2c: simtec: Convert to use devm_* APIs
  2016-04-12 21:48 ` Wolfram Sang
@ 2016-04-13  0:43   ` Axel Lin
  2016-04-13  8:19     ` Wolfram Sang
  0 siblings, 1 reply; 4+ messages in thread
From: Axel Lin @ 2016-04-13  0:43 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: Ben Dooks, linux-i2c

2016-04-13 5:48 GMT+08:00 Wolfram Sang <wsa@the-dreams.de>:
> On Tue, Apr 12, 2016 at 04:30:14PM +0800, Axel Lin wrote:
>> Use devm_* APIs to simplify the code a bit.
>>
>> Signed-off-by: Axel Lin <axel.lin@ingics.com>
>
> Thanks! Were you able to test it on hardware?
>
I don't have this h/w, so I cannot test it.

Axel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] i2c: simtec: Convert to use devm_* APIs
  2016-04-13  0:43   ` Axel Lin
@ 2016-04-13  8:19     ` Wolfram Sang
  0 siblings, 0 replies; 4+ messages in thread
From: Wolfram Sang @ 2016-04-13  8:19 UTC (permalink / raw)
  To: Axel Lin; +Cc: Ben Dooks, linux-i2c

[-- Attachment #1: Type: text/plain, Size: 423 bytes --]

On Wed, Apr 13, 2016 at 08:43:49AM +0800, Axel Lin wrote:
> 2016-04-13 5:48 GMT+08:00 Wolfram Sang <wsa@the-dreams.de>:
> > On Tue, Apr 12, 2016 at 04:30:14PM +0800, Axel Lin wrote:
> >> Use devm_* APIs to simplify the code a bit.
> >>
> >> Signed-off-by: Axel Lin <axel.lin@ingics.com>
> >
> > Thanks! Were you able to test it on hardware?
> >
> I don't have this h/w, so I cannot test it.

OK, so I'll rate this as RFT.


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-04-13  8:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-12  8:30 [PATCH] i2c: simtec: Convert to use devm_* APIs Axel Lin
2016-04-12 21:48 ` Wolfram Sang
2016-04-13  0:43   ` Axel Lin
2016-04-13  8:19     ` 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).