All of lore.kernel.org
 help / color / mirror / Atom feed
From: Axel Lin <axel.lin@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: Chiwoong Byun <woong.byun@samsung.com>,
	Jonghwa Lee <jonghwa3.lee@samsung.com>,
	Myungjoo Ham <myungjoo.ham@samsung.com>,
	Kyungmin Park <kyungmin.park@samsung.com>,
	Yadwinder Singh Brar <yadi.brar@samsung.com>,
	Mark Brown <broonie@opensource.wolfsonmicro.com>,
	Liam Girdwood <lrg@ti.com>
Subject: [PATCH] regulator: max77686: Check pdata->num_regulators earlier
Date: Fri, 08 Jun 2012 12:03:04 +0800	[thread overview]
Message-ID: <1339128184.8259.1.camel@phoenix> (raw)

If this driver only works when pdata->num_regulators == MAX77686_REGULATORS,
let's check it earlier.

Also remove unused num_regulators from struct max77686_data.

Signed-off-by: Axel Lin <axel.lin@gmail.com>
---
 drivers/regulator/max77686.c |   43 +++++++++++++++++++-----------------------
 1 file changed, 19 insertions(+), 24 deletions(-)

diff --git a/drivers/regulator/max77686.c b/drivers/regulator/max77686.c
index b76a038..b0c146d 100644
--- a/drivers/regulator/max77686.c
+++ b/drivers/regulator/max77686.c
@@ -65,7 +65,6 @@ enum max77686_ramp_rate {
 struct max77686_data {
 	struct device *dev;
 	struct max77686_dev *iodev;
-	int num_regulators;
 	struct regulator_dev **rdev;
 	int ramp_delay; /* in mV/us */
 };
@@ -235,6 +234,12 @@ static __devinit int max77686_pmic_probe(struct platform_device *pdev)
 
 	dev_dbg(&pdev->dev, "%s\n", __func__);
 
+	if (!pdata || pdata->num_regulators != MAX77686_REGULATORS) {
+		dev_err(&pdev->dev,
+			"Invalid initial data for regulator's initialiation\n");
+		return -EINVAL;
+	}
+
 	max77686 = devm_kzalloc(&pdev->dev, sizeof(struct max77686_data),
 				GFP_KERNEL);
 	if (!max77686)
@@ -248,8 +253,6 @@ static __devinit int max77686_pmic_probe(struct platform_device *pdev)
 	rdev = max77686->rdev;
 	max77686->dev = &pdev->dev;
 	max77686->iodev = iodev;
-	if (pdata)
-		max77686->num_regulators = pdata->num_regulators;
 	platform_set_drvdata(pdev, max77686);
 
 	max77686->ramp_delay = RAMP_RATE_NO_CTRL; /* Set 0x3 for RAMP */
@@ -263,34 +266,26 @@ static __devinit int max77686_pmic_probe(struct platform_device *pdev)
 			MAX77686_REG_BUCK4CTRL1, MAX77686_RAMP_RATE_MASK,
 			max77686->ramp_delay << 6);
 
-	if (pdata->num_regulators == MAX77686_REGULATORS) {
-		for (i = 0; i < MAX77686_REGULATORS; i++) {
-			config.dev = max77686->dev;
-			config.regmap = iodev->regmap;
-			config.driver_data = max77686;
-			config.init_data = pdata->regulators[i].initdata;
-
-			rdev[i] = regulator_register(&regulators[i], &config);
-
-			if (IS_ERR(rdev[i])) {
-				ret = PTR_ERR(rdev[i]);
-				dev_err(max77686->dev,
+	for (i = 0; i < MAX77686_REGULATORS; i++) {
+		config.dev = max77686->dev;
+		config.regmap = iodev->regmap;
+		config.driver_data = max77686;
+		config.init_data = pdata->regulators[i].initdata;
+
+		rdev[i] = regulator_register(&regulators[i], &config);
+		if (IS_ERR(rdev[i])) {
+			ret = PTR_ERR(rdev[i]);
+			dev_err(max77686->dev,
 				"regulator init failed for %d\n", i);
 				rdev[i] = NULL;
 				goto err;
-			}
 		}
-	} else {
-		dev_err(max77686->dev,
-			 "Lack of initial data for regulator's initialiation\n");
-		return -EINVAL;
 	}
+
 	return 0;
 err:
-	for (i = 0; i < MAX77686_REGULATORS; i++) {
-		if (rdev[i])
-			regulator_unregister(rdev[i]);
-	}
+	while (--i >= 0)
+		regulator_unregister(rdev[i]);
 	return ret;
 }
 
-- 
1.7.9.5




             reply	other threads:[~2012-06-08  4:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-08  4:03 Axel Lin [this message]
2012-06-11  3:44 ` [PATCH] regulator: max77686: Check pdata->num_regulators earlier Mark Brown

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=1339128184.8259.1.camel@phoenix \
    --to=axel.lin@gmail.com \
    --cc=broonie@opensource.wolfsonmicro.com \
    --cc=jonghwa3.lee@samsung.com \
    --cc=kyungmin.park@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lrg@ti.com \
    --cc=myungjoo.ham@samsung.com \
    --cc=woong.byun@samsung.com \
    --cc=yadi.brar@samsung.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 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.