From: Axel Lin <axel.lin@ingics.com>
To: Wolfram Sang <wsa@the-dreams.de>
Cc: Ben Dooks <ben@simtec.co.uk>, linux-i2c@vger.kernel.org
Subject: [PATCH] i2c: simtec: Convert to use devm_* APIs
Date: Tue, 12 Apr 2016 16:30:14 +0800 [thread overview]
Message-ID: <1460449814.28557.0.camel@ingics.com> (raw)
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
next reply other threads:[~2016-04-12 8:31 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-12 8:30 Axel Lin [this message]
2016-04-12 21:48 ` [PATCH] i2c: simtec: Convert to use devm_* APIs Wolfram Sang
2016-04-13 0:43 ` Axel Lin
2016-04-13 8:19 ` Wolfram Sang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1460449814.28557.0.camel@ingics.com \
--to=axel.lin@ingics.com \
--cc=ben@simtec.co.uk \
--cc=linux-i2c@vger.kernel.org \
--cc=wsa@the-dreams.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.