linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: linux-iio@vger.kernel.org
Cc: Jonathan Cameron <jic23@kernel.org>
Subject: [PATCH 6/7] staging:iio:adc:max1363 cleanup regulator handling.
Date: Sat, 13 Oct 2012 10:34:50 +0100	[thread overview]
Message-ID: <1350120891-28593-7-git-send-email-jic23@kernel.org> (raw)
In-Reply-To: <1350120891-28593-1-git-send-email-jic23@kernel.org>

For historical reasons the regulator handling was a little clunky. This
patch brings it inline with a more standard ordering wrt to allocation
of the iio_device.

Signed-off-by: Jonathan Cameron <jic23@kernel.org>
---
 drivers/staging/iio/adc/max1363.c | 44 +++++++++++++++++++--------------------
 1 file changed, 22 insertions(+), 22 deletions(-)

diff --git a/drivers/staging/iio/adc/max1363.c b/drivers/staging/iio/adc/max1363.c
index 2f8d433..1e84b5b 100644
--- a/drivers/staging/iio/adc/max1363.c
+++ b/drivers/staging/iio/adc/max1363.c
@@ -1531,28 +1531,29 @@ static int __devinit max1363_probe(struct i2c_client *client,
 	int ret;
 	struct max1363_state *st;
 	struct iio_dev *indio_dev;
-	struct regulator *reg;
-
-	reg = regulator_get(&client->dev, "vcc");
-	if (IS_ERR(reg)) {
-		ret = PTR_ERR(reg);
-		goto error_out;
-	}
-
-	ret = regulator_enable(reg);
-	if (ret)
-		goto error_put_reg;
 
 	indio_dev = iio_device_alloc(sizeof(struct max1363_state));
 	if (indio_dev == NULL) {
 		ret = -ENOMEM;
-		goto error_disable_reg;
+		goto error_out;
 	}
+
 	ret = iio_map_array_register(indio_dev, client->dev.platform_data);
 	if (ret < 0)
 		goto error_free_device;
+
 	st = iio_priv(indio_dev);
-	st->reg = reg;
+
+	st->reg = regulator_get(&client->dev, "vcc");
+	if (IS_ERR(st->reg)) {
+		ret = PTR_ERR(st->reg);
+		goto error_unregister_map;
+	}
+
+	ret = regulator_enable(st->reg);
+	if (ret)
+		goto error_put_reg;
+
 	/* this is only used for device removal purposes */
 	i2c_set_clientdata(client, indio_dev);
 
@@ -1561,7 +1562,7 @@ static int __devinit max1363_probe(struct i2c_client *client,
 
 	ret = max1363_alloc_scan_masks(indio_dev);
 	if (ret)
-		goto error_unregister_map;
+		goto error_disable_reg;
 
 	/* Estabilish that the iio_dev is a child of the i2c device */
 	indio_dev->dev.parent = &client->dev;
@@ -1613,12 +1614,12 @@ error_free_available_scan_masks:
 	kfree(indio_dev->available_scan_masks);
 error_unregister_map:
 	iio_map_array_unregister(indio_dev, client->dev.platform_data);
-error_free_device:
-	iio_device_free(indio_dev);
 error_disable_reg:
-	regulator_disable(reg);
+	regulator_disable(st->reg);
 error_put_reg:
-	regulator_put(reg);
+	regulator_put(st->reg);
+error_free_device:
+	iio_device_free(indio_dev);
 error_out:
 	return ret;
 }
@@ -1627,7 +1628,6 @@ static int __devexit max1363_remove(struct i2c_client *client)
 {
 	struct iio_dev *indio_dev = i2c_get_clientdata(client);
 	struct max1363_state *st = iio_priv(indio_dev);
-	struct regulator *reg = st->reg;
 
 	iio_device_unregister(indio_dev);
 	if (client->irq)
@@ -1635,9 +1635,9 @@ static int __devexit max1363_remove(struct i2c_client *client)
 	iio_buffer_unregister(indio_dev);
 	max1363_buffer_cleanup(indio_dev);
 	kfree(indio_dev->available_scan_masks);
-	if (!IS_ERR(reg)) {
-		regulator_disable(reg);
-		regulator_put(reg);
+	if (!IS_ERR(st->reg)) {
+		regulator_disable(st->reg);
+		regulator_put(st->reg);
 	}
 	iio_map_array_unregister(indio_dev, client->dev.platform_data);
 	iio_device_free(indio_dev);
-- 
1.7.12.2

  parent reply	other threads:[~2012-10-13  9:34 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-13  9:34 [PATCH 0/7] iio:adc:max1363 cleanup and graduation from staging Jonathan Cameron
2012-10-13  9:34 ` [PATCH 1/7] staging:iio:adc:max1363 ring_sw->kfifo conversion Jonathan Cameron
2012-10-13  9:34 ` [PATCH 2/7] staging:iio:adc:max1363 consolidate files Jonathan Cameron
2012-10-13  9:34 ` [PATCH 3/7] staging:iio:adc:max1363 drop references to 'ring' given now using a fifo Jonathan Cameron
2012-10-13  9:34 ` [PATCH 4/7] staging:iio:adc:max1363 make docs match the contents of max1363_chip_info Jonathan Cameron
2012-10-13  9:34 ` [PATCH 5/7] staging:iio:adc:max1363 white space cleanup Jonathan Cameron
2012-10-13  9:34 ` Jonathan Cameron [this message]
2012-10-13  9:34 ` [PATCH 7/7] iio:adc:max1363 move from staging Jonathan Cameron

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=1350120891-28593-7-git-send-email-jic23@kernel.org \
    --to=jic23@kernel.org \
    --cc=linux-iio@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).