public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: Evgeniy Polyakov <zbr@ioremap.net>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Ville Syrjala <syrjala@sci.fi>, Daniel Mack <zonque@gmail.com>,
	Matt Ranostay <mranostay@gmail.com>,
	panto@antoniou-consulting.com, koen@dominion.thruhere.net
Subject: [PATCH 5/5] W1: w1-gpio - switch to using managed resources (devm)
Date: Sun, 24 Feb 2013 22:59:37 -0800	[thread overview]
Message-ID: <1361775577-4578-5-git-send-email-dmitry.torokhov@gmail.com> (raw)
In-Reply-To: <1361775577-4578-1-git-send-email-dmitry.torokhov@gmail.com>

This simplifies error unwinding and device teardown.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/w1/masters/w1-gpio.c | 32 +++++++++++---------------------
 1 file changed, 11 insertions(+), 21 deletions(-)

diff --git a/drivers/w1/masters/w1-gpio.c b/drivers/w1/masters/w1-gpio.c
index 465ce52..464b1a8 100644
--- a/drivers/w1/masters/w1-gpio.c
+++ b/drivers/w1/masters/w1-gpio.c
@@ -111,25 +111,27 @@ static int w1_gpio_probe(struct platform_device *pdev)
 		return err;
 	}
 
-	master = kzalloc(sizeof(struct w1_bus_master), GFP_KERNEL);
+	master = devm_kzalloc(&pdev->dev,
+			      sizeof(struct w1_bus_master), GFP_KERNEL);
 	if (!master) {
 		dev_err(&pdev->dev, "Out of memory\n");
 		return -ENOMEM;
 	}
 
-	err = gpio_request(pdata->pin, "w1");
+	err = devm_gpio_request(&pdev->dev, pdata->pin, "w1");
 	if (err) {
 		dev_err(&pdev->dev, "gpio_request (pin) failed\n");
-		goto free_master;
+		return err;
 	}
 
 	if (gpio_is_valid(pdata->ext_pullup_enable_pin)) {
-		err = gpio_request_one(pdata->ext_pullup_enable_pin,
-				       GPIOF_INIT_LOW, "w1 pullup");
+		err = devm_gpio_request_one(&pdev->dev,
+					    pdata->ext_pullup_enable_pin,
+					    GPIOF_INIT_LOW, "w1 pullup");
 		if (err < 0) {
-			dev_err(&pdev->dev, "gpio_request_one "
-					"(ext_pullup_enable_pin) failed\n");
-			goto free_gpio;
+			dev_err(&pdev->dev,
+				"gpio_request_one (ext_pullup_enable_pin) failed\n");
+			return err;
 		}
 	}
 
@@ -147,7 +149,7 @@ static int w1_gpio_probe(struct platform_device *pdev)
 	err = w1_add_master_device(master);
 	if (err) {
 		dev_err(&pdev->dev, "w1_add_master device failed\n");
-		goto free_gpio_ext_pu;
+		return err;
 	}
 
 	if (pdata->enable_external_pullup)
@@ -159,16 +161,6 @@ static int w1_gpio_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, master);
 
 	return 0;
-
- free_gpio_ext_pu:
-	if (gpio_is_valid(pdata->ext_pullup_enable_pin))
-		gpio_free(pdata->ext_pullup_enable_pin);
- free_gpio:
-	gpio_free(pdata->pin);
- free_master:
-	kfree(master);
-
-	return err;
 }
 
 static int w1_gpio_remove(struct platform_device *pdev)
@@ -183,8 +175,6 @@ static int w1_gpio_remove(struct platform_device *pdev)
 		gpio_set_value(pdata->ext_pullup_enable_pin, 0);
 
 	w1_remove_master_device(master);
-	gpio_free(pdata->pin);
-	kfree(master);
 
 	return 0;
 }
-- 
1.7.11.7


  parent reply	other threads:[~2013-02-25  6:59 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-23  7:58 [PATCH 1/5] W1: w1-gpio - fix incorrect __init/__exit markups Dmitry Torokhov
2013-02-23  7:58 ` [PATCH 2/5] W1: w1-gpio - switch to using dev_pm_ops Dmitry Torokhov
2013-02-23  7:58 ` [PATCH 3/5] W1: w1-gpio - guard DT IDs with CONFIG_OF Dmitry Torokhov
2013-02-23  7:58 ` [PATCH 4/5] W1: w1-gpio - rework handling of platform data Dmitry Torokhov
2013-02-23 16:55   ` Ville Syrjälä
2013-02-23 20:06     ` Dmitry Torokhov
2013-02-23  7:58 ` [PATCH 5/5] W1: w1-gpio - switch to using managed resources (devm) Dmitry Torokhov
2013-02-25  6:59 ` [PATCH v2 1/5] W1: w1-gpio - fix incorrect __init/__exit markups Dmitry Torokhov
2013-02-25  6:59   ` [PATCH 2/5] W1: w1-gpio - switch to using dev_pm_ops Dmitry Torokhov
2013-02-25  6:59   ` [PATCH 3/5] W1: w1-gpio - guard DT IDs with CONFIG_OF Dmitry Torokhov
2013-03-12 23:23     ` Greg Kroah-Hartman
2013-02-25  6:59   ` [PATCH 4/5] W1: w1-gpio - rework handling of platform data Dmitry Torokhov
2013-02-25  6:59   ` Dmitry Torokhov [this message]
2013-03-12 23:23   ` [PATCH v2 1/5] W1: w1-gpio - fix incorrect __init/__exit markups Greg Kroah-Hartman

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=1361775577-4578-5-git-send-email-dmitry.torokhov@gmail.com \
    --to=dmitry.torokhov@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=koen@dominion.thruhere.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mranostay@gmail.com \
    --cc=panto@antoniou-consulting.com \
    --cc=syrjala@sci.fi \
    --cc=zbr@ioremap.net \
    --cc=zonque@gmail.com \
    /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