All of lore.kernel.org
 help / color / mirror / Atom feed
From: Axel Lin <axel.lin@ingics.com>
To: Wolfram Sang <wsa@the-dreams.de>
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>,
	Liviu Dudau <liviu.dudau@arm.com>,
	Sudeep Holla <sudeep.holla@arm.com>,
	Pawel Moll <pawel.moll@arm.com>,
	linux-i2c@vger.kernel.org
Subject: [RESEND][PATCH 2/2] i2c: versatile: Convert to use resource managed devm_* APIs
Date: Sat, 09 Jul 2016 13:32:23 +0800	[thread overview]
Message-ID: <1468042343.21863.3.camel@ingics.com> (raw)
In-Reply-To: <1468042283.21863.2.camel@ingics.com>

Use devm_* APIs to simplify the code a bit.
This patch also fixes the memory leak when unload the module.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
Resend with CC VE maintainers.
 drivers/i2c/busses/i2c-versatile.c | 46 +++++++++++---------------------------
 1 file changed, 13 insertions(+), 33 deletions(-)

diff --git a/drivers/i2c/busses/i2c-versatile.c b/drivers/i2c/busses/i2c-versatile.c
index 240637f..c73d2d2 100644
--- a/drivers/i2c/busses/i2c-versatile.c
+++ b/drivers/i2c/busses/i2c-versatile.c
@@ -70,28 +70,14 @@ static int i2c_versatile_probe(struct platform_device *dev)
 	struct resource *r;
 	int ret;
 
+	i2c = devm_kzalloc(&dev->dev, sizeof(struct i2c_versatile), GFP_KERNEL);
+	if (!i2c)
+		return -ENOMEM;
+
 	r = platform_get_resource(dev, IORESOURCE_MEM, 0);
-	if (!r) {
-		ret = -EINVAL;
-		goto err_out;
-	}
-
-	if (!request_mem_region(r->start, resource_size(r), "versatile-i2c")) {
-		ret = -EBUSY;
-		goto err_out;
-	}
-
-	i2c = kzalloc(sizeof(struct i2c_versatile), GFP_KERNEL);
-	if (!i2c) {
-		ret = -ENOMEM;
-		goto err_release;
-	}
-
-	i2c->base = ioremap(r->start, resource_size(r));
-	if (!i2c->base) {
-		ret = -ENOMEM;
-		goto err_free;
-	}
+	i2c->base = devm_ioremap_resource(&dev->dev, r);
+	if (IS_ERR(i2c->base))
+		return PTR_ERR(i2c->base);
 
 	writel(SCL | SDA, i2c->base + I2C_CONTROLS);
 
@@ -105,18 +91,12 @@ static int i2c_versatile_probe(struct platform_device *dev)
 
 	i2c->adap.nr = dev->id;
 	ret = i2c_bit_add_numbered_bus(&i2c->adap);
-	if (ret >= 0) {
-		platform_set_drvdata(dev, i2c);
-		return 0;
-	}
-
-	iounmap(i2c->base);
- err_free:
-	kfree(i2c);
- err_release:
-	release_mem_region(r->start, resource_size(r));
- err_out:
-	return ret;
+	if (ret < 0)
+		return ret;
+
+	platform_set_drvdata(dev, i2c);
+
+	return 0;
 }
 
 static int i2c_versatile_remove(struct platform_device *dev)
-- 
2.5.0

  reply	other threads:[~2016-07-09  5:32 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-09  5:31 [RESEND][PATCH 1/2] i2c: versatile: Allow compile test build Axel Lin
2016-07-09  5:32 ` Axel Lin [this message]
2016-07-14 12:23   ` [RESEND][PATCH 2/2] i2c: versatile: Convert to use resource managed devm_* APIs Wolfram Sang
2016-07-11  8:44 ` [RESEND][PATCH 1/2] i2c: versatile: Allow compile test build Liviu Dudau
2016-07-14 10:51   ` Sudeep Holla
2016-07-14 12:08     ` Wolfram Sang
2016-07-14 12:33       ` Sudeep Holla
2016-07-14 12:23 ` 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=1468042343.21863.3.camel@ingics.com \
    --to=axel.lin@ingics.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=liviu.dudau@arm.com \
    --cc=lorenzo.pieralisi@arm.com \
    --cc=pawel.moll@arm.com \
    --cc=sudeep.holla@arm.com \
    --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.