linux-sh.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Magnus Damm <magnus.damm@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: linux-sh@vger.kernel.org, linus.walleij@linaro.org,
	grant.likely@secretlab.ca, horms@verge.net.au,
	laurent.pinchart@ideasonboard.com,
	Magnus Damm <magnus.damm@gmail.com>
Subject: [PATCH 03/03] gpio: rcar: Make use of devm functions
Date: Wed, 13 Mar 2013 11:32:33 +0000	[thread overview]
Message-ID: <20130313113233.30133.20516.sendpatchset@w520> (raw)
In-Reply-To: <20130313113203.30133.49539.sendpatchset@w520>

From: Magnus Damm <damm@opensource.se>

Update the gpio-rcar.c driver to make use of devm
functions. This simplifies the error handling and
makes the code more compact.

Signed-off-by: Magnus Damm <damm@opensource.se>
---

 drivers/gpio/gpio-rcar.c |   32 +++++++++++---------------------
 1 file changed, 11 insertions(+), 21 deletions(-)

--- 0005/drivers/gpio/gpio-rcar.c
+++ work/drivers/gpio/gpio-rcar.c	2013-03-13 19:47:17.000000000 +0900
@@ -252,7 +252,7 @@ static int gpio_rcar_probe(struct platfo
 	const char *name = dev_name(&pdev->dev);
 	int ret;
 
-	p = kzalloc(sizeof(*p), GFP_KERNEL);
+	p = devm_kzalloc(&pdev->dev, sizeof(*p), GFP_KERNEL);
 	if (!p) {
 		dev_err(&pdev->dev, "failed to allocate driver data\n");
 		ret = -ENOMEM;
@@ -273,14 +273,15 @@ static int gpio_rcar_probe(struct platfo
 	if (!io || !irq) {
 		dev_err(&pdev->dev, "missing IRQ or IOMEM\n");
 		ret = -EINVAL;
-		goto err1;
+		goto err0;
 	}
 
-	p->base = ioremap_nocache(io->start, resource_size(io));
+	p->base = devm_ioremap_nocache(&pdev->dev, io->start,
+				       resource_size(io));
 	if (!p->base) {
 		dev_err(&pdev->dev, "failed to remap I/O memory\n");
 		ret = -ENXIO;
-		goto err1;
+		goto err0;
 	}
 
 	gpio_chip = &p->gpio_chip;
@@ -310,19 +311,20 @@ static int gpio_rcar_probe(struct platfo
 	if (!p->irq_domain) {
 		ret = -ENXIO;
 		dev_err(&pdev->dev, "cannot initialize irq domain\n");
-		goto err2;
+		goto err1;
 	}
 
-	if (request_irq(irq->start, gpio_rcar_irq_handler, 0, name, p)) {
+	if (devm_request_irq(&pdev->dev, irq->start,
+			     gpio_rcar_irq_handler, 0, name, p)) {
 		dev_err(&pdev->dev, "failed to request IRQ\n");
 		ret = -ENOENT;
-		goto err3;
+		goto err1;
 	}
 
 	ret = gpiochip_add(gpio_chip);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to add GPIO controller\n");
-		goto err4;
+		goto err1;
 	}
 
 	dev_info(&pdev->dev, "driving %d GPIOs\n", p->config.number_of_pins);
@@ -337,14 +339,8 @@ static int gpio_rcar_probe(struct platfo
 
 	return 0;
 
-err4:
-	free_irq(irq->start, p);
-err3:
-	irq_domain_remove(p->irq_domain);
-err2:
-	iounmap(p->base);
 err1:
-	kfree(p);
+	irq_domain_remove(p->irq_domain);
 err0:
 	return ret;
 }
@@ -352,19 +348,13 @@ err0:
 static int gpio_rcar_remove(struct platform_device *pdev)
 {
 	struct gpio_rcar_priv *p = platform_get_drvdata(pdev);
-	struct resource *irq;
 	int ret;
 
 	ret = gpiochip_remove(&p->gpio_chip);
 	if (ret)
 		return ret;
 
-	irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
-
-	free_irq(irq->start, p);
 	irq_domain_remove(p->irq_domain);
-	iounmap(p->base);
-	kfree(p);
 	return 0;
 }
 

  parent reply	other threads:[~2013-03-13 11:32 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-13 11:32 [PATCH 00/03] gpio: Renesas R-Car GPIO driver update Magnus Damm
2013-03-13 11:32 ` [PATCH 01/03] gpio: Renesas R-Car GPIO driver V2 Magnus Damm
2013-03-13 13:14   ` Laurent Pinchart
2013-03-14  4:11     ` Magnus Damm
2013-03-13 11:32 ` [PATCH 02/03] gpio: rcar: Use IRQCHIP_SET_TYPE_MASKED Magnus Damm
2013-03-13 11:32 ` Magnus Damm [this message]
2013-03-13 12:58 ` [PATCH 00/03] gpio: Renesas R-Car GPIO driver update Laurent Pinchart
2013-03-14  4:23   ` Magnus Damm
2013-03-14 13:13     ` Laurent Pinchart
2013-03-16  8:50       ` Simon Horman
2013-03-19  3:36       ` Magnus Damm
2013-03-19 15:01         ` Laurent Pinchart
2013-03-27 12:34         ` Linus Walleij
2013-03-27 14:44           ` Magnus Damm

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=20130313113233.30133.20516.sendpatchset@w520 \
    --to=magnus.damm@gmail.com \
    --cc=grant.likely@secretlab.ca \
    --cc=horms@verge.net.au \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sh@vger.kernel.org \
    /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 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).