diff mbox

[07/21] ASoC: io: Prevent use of regmap if request fails

Message ID 1343298534-13611-8-git-send-email-lee.jones@linaro.org
State New
Headers show

Commit Message

Lee Jones July 26, 2012, 10:28 a.m. UTC
If a sound codec fails to request a regmap, the 'using_regmap' is
set as true regardless, despite there being no regmap to use. As a
repercussion, when a latter read function checks to see if we are
using regmaps, it assumes we are and attempts to. Only the kernel
oopes, because regmap_* tries to extract information from a NULL
pointer.

Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
 sound/soc/soc-io.c |   14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
diff mbox

Patch

diff --git a/sound/soc/soc-io.c b/sound/soc/soc-io.c
index 29183ef..601cb7f 100644
--- a/sound/soc/soc-io.c
+++ b/sound/soc/soc-io.c
@@ -52,10 +52,13 @@  static unsigned int hw_read(struct snd_soc_codec *codec, unsigned int reg)
 		if (codec->cache_only)
 			return -1;
 
-		ret = regmap_read(codec->control_data, reg, &val);
-		if (ret == 0)
-			return val;
-		else
+		if (codec->using_regmap) {
+			ret = regmap_read(codec->control_data, reg, &val);
+			if (ret == 0)
+				return val;
+			else
+				return -1;
+		} else
 			return -1;
 	}
 
@@ -141,11 +144,12 @@  int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec,
 
 	case SND_SOC_REGMAP:
 		/* Device has made its own regmap arrangements */
-		codec->using_regmap = true;
 		if (!codec->control_data)
 			codec->control_data = dev_get_regmap(codec->dev, NULL);
 
 		if (codec->control_data) {
+			codec->using_regmap = true;
+
 			ret = regmap_get_val_bytes(codec->control_data);
 			/* Errors are legitimate for non-integer byte
 			 * multiples */