All of lore.kernel.org
 help / color / mirror / Atom feed
From: Axel Lin <axel.lin@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: Mark Brown <broonie@opensource.wolfsonmicro.com>,
	Ian Lartey <ian@opensource.wolfsonmicro.com>,
	Dimitris Papastamos <dp@opensource.wolfsonmicro.com>,
	Samuel Ortiz <sameo@linux.intel.com>
Subject: [PATCH] mfd: wm8994: Return error when device ID mismatch is detected
Date: Wed, 22 Feb 2012 10:24:44 +0800	[thread overview]
Message-ID: <1329877484.3210.6.camel@phoenix> (raw)

We base on wm8994->type to set wm8994->supplies and wm8994->num_supplies.
But in current code, wm8994->type may be changed when device ID mismatch is
detected. If we change wm8994->type, then the wm8994->supplies and
wm8994->num_supplies settings are wrong.

Fix it by return error immediately when device ID mismatch is detected.

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

diff --git a/drivers/mfd/wm8994-core.c b/drivers/mfd/wm8994-core.c
index 1599bba..6e4612e 100644
--- a/drivers/mfd/wm8994-core.c
+++ b/drivers/mfd/wm8994-core.c
@@ -415,14 +415,17 @@ static __devinit int wm8994_device_init(struct wm8994 *wm8994, int irq)
 
 	switch (wm8994->type) {
 	case WM1811:
+		devname = "WM1811";
 		for (i = 0; i < ARRAY_SIZE(wm1811_main_supplies); i++)
 			wm8994->supplies[i].supply = wm1811_main_supplies[i];
 		break;
 	case WM8994:
+		devname = "WM8994";
 		for (i = 0; i < ARRAY_SIZE(wm8994_main_supplies); i++)
 			wm8994->supplies[i].supply = wm8994_main_supplies[i];
 		break;
 	case WM8958:
+		devname = "WM8958";
 		for (i = 0; i < ARRAY_SIZE(wm8958_main_supplies); i++)
 			wm8994->supplies[i].supply = wm8958_main_supplies[i];
 		break;
@@ -450,31 +453,10 @@ static __devinit int wm8994_device_init(struct wm8994 *wm8994, int irq)
 		dev_err(wm8994->dev, "Failed to read ID register\n");
 		goto err_enable;
 	}
-	switch (ret) {
-	case 0x1811:
-		devname = "WM1811";
-		if (wm8994->type != WM1811)
-			dev_warn(wm8994->dev, "Device registered as type %d\n",
-				 wm8994->type);
-		wm8994->type = WM1811;
-		break;
-	case 0x8994:
-		devname = "WM8994";
-		if (wm8994->type != WM8994)
-			dev_warn(wm8994->dev, "Device registered as type %d\n",
-				 wm8994->type);
-		wm8994->type = WM8994;
-		break;
-	case 0x8958:
-		devname = "WM8958";
-		if (wm8994->type != WM8958)
-			dev_warn(wm8994->dev, "Device registered as type %d\n",
-				 wm8994->type);
-		wm8994->type = WM8958;
-		break;
-	default:
-		dev_err(wm8994->dev, "Device is not a WM8994, ID is %x\n",
-			ret);
+
+	if (ret != wm8994->type) {
+		dev_err(wm8994->dev, "Device ID mismatch: expect %x but we got %x\n",
+			wm8994->type, ret);
 		ret = -EINVAL;
 		goto err_enable;
 	}
-- 
1.7.5.4




             reply	other threads:[~2012-02-22  2:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-22  2:24 Axel Lin [this message]
2012-02-22 13:45 ` [PATCH] mfd: wm8994: Return error when device ID mismatch is detected 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=1329877484.3210.6.camel@phoenix \
    --to=axel.lin@gmail.com \
    --cc=broonie@opensource.wolfsonmicro.com \
    --cc=dp@opensource.wolfsonmicro.com \
    --cc=ian@opensource.wolfsonmicro.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sameo@linux.intel.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.