public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Axel Lin <axel.lin@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: Kyungmin Park <kyungmin.park@samsung.com>,
	MyungJoo Ham <myungjoo.ham@smasung.com>,
	Liam Girdwood <lrg@ti.com>,
	Mark Brown <broonie@opensource.wolfsonmicro.com>
Subject: [PATCH] regulator: Check SET[1|2|3] GPIO settings earlier
Date: Tue, 13 Mar 2012 10:58:20 +0800	[thread overview]
Message-ID: <1331607500.11322.3.camel@phoenix> (raw)

Unused GPIO is marked as -1, we need to check if one of the gpio is set to 0
here because gpio_is_valid considers 0 as a valid gpio.

Since we need to check the GPIOs anyway, check them altogether earlier makes
the code cleaner.

Signed-off-by: Axel Lin <axel.lin@gmail.com>
---
 drivers/regulator/max8998.c |   32 +++++++-------------------------
 1 files changed, 7 insertions(+), 25 deletions(-)

diff --git a/drivers/regulator/max8998.c b/drivers/regulator/max8998.c
index 5890265..67140fa 100644
--- a/drivers/regulator/max8998.c
+++ b/drivers/regulator/max8998.c
@@ -695,6 +695,13 @@ static __devinit int max8998_pmic_probe(struct platform_device *pdev)
 		return -ENODEV;
 	}
 
+	/* Unused GPIO is marked as -1 */
+	if (!pdata->buck1_set1 || !pdata->buck1_set2 || !pdata->buck2_set3) {
+		dev_err(&pdev->dev,
+		    "MAX8998 SET1/SET2/SET3 GPIO must not be defined as 0 !\n");
+		return -EINVAL;
+	}
+
 	max8998 = kzalloc(sizeof(struct max8998_data), GFP_KERNEL);
 	if (!max8998)
 		return -ENOMEM;
@@ -716,27 +723,9 @@ static __devinit int max8998_pmic_probe(struct platform_device *pdev)
 	max8998->buck1_idx = pdata->buck1_default_idx;
 	max8998->buck2_idx = pdata->buck2_default_idx;
 
-	/* NOTE: */
-	/* For unused GPIO NOT marked as -1 (thereof equal to 0)  WARN_ON */
-	/* will be displayed */
-
 	/* Check if MAX8998 voltage selection GPIOs are defined */
 	if (gpio_is_valid(pdata->buck1_set1) &&
 	    gpio_is_valid(pdata->buck1_set2)) {
-		/* Check if SET1 is not equal to 0 */
-		if (!pdata->buck1_set1) {
-			printk(KERN_ERR "MAX8998 SET1 GPIO defined as 0 !\n");
-			WARN_ON(!pdata->buck1_set1);
-			ret = -EIO;
-			goto err_free_mem;
-		}
-		/* Check if SET2 is not equal to 0 */
-		if (!pdata->buck1_set2) {
-			printk(KERN_ERR "MAX8998 SET2 GPIO defined as 0 !\n");
-			WARN_ON(!pdata->buck1_set2);
-			ret = -EIO;
-			goto err_free_mem;
-		}
 
 		gpio_request(pdata->buck1_set1, "MAX8998 BUCK1_SET1");
 		gpio_direction_output(pdata->buck1_set1,
@@ -796,13 +785,6 @@ static __devinit int max8998_pmic_probe(struct platform_device *pdev)
 	}
 
 	if (gpio_is_valid(pdata->buck2_set3)) {
-		/* Check if SET3 is not equal to 0 */
-		if (!pdata->buck2_set3) {
-			printk(KERN_ERR "MAX8998 SET3 GPIO defined as 0 !\n");
-			WARN_ON(!pdata->buck2_set3);
-			ret = -EIO;
-			goto err_free_mem;
-		}
 		gpio_request(pdata->buck2_set3, "MAX8998 BUCK2_SET3");
 		gpio_direction_output(pdata->buck2_set3,
 				      max8998->buck2_idx & 0x1);
-- 
1.7.5.4




             reply	other threads:[~2012-03-13  2:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-13  2:58 Axel Lin [this message]
2012-03-13 23:13 ` [PATCH] regulator: Check SET[1|2|3] GPIO settings 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=1331607500.11322.3.camel@phoenix \
    --to=axel.lin@gmail.com \
    --cc=broonie@opensource.wolfsonmicro.com \
    --cc=kyungmin.park@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lrg@ti.com \
    --cc=myungjoo.ham@smasung.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