aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/codecs
diff options
context:
space:
mode:
authorIan Molton <ian@mnementh.co.uk>2009-01-17 12:44:23 -0500
committerMark Brown <broonie@opensource.wolfsonmicro.com>2009-01-19 11:23:13 -0500
commit91432e976ff1323e5dd6f52498969602953c6ee9 (patch)
treee18da7346b857e384a78ecc3368e5c65652ef1b5 /sound/soc/codecs
parent28796eaf806502b9bd86cbacf8edbc14c80c14b0 (diff)
ASoC: fixes to caching implementations
This patch takes fixes a number of bugs in the caching code used by several ASoC codec drivers. Mostly off-by-one fixes. Signed-off-by: Ian Molton <ian@mnementh.co.uk> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/codecs')
-rw-r--r--sound/soc/codecs/ac97.c2
-rw-r--r--sound/soc/codecs/ad1980.c4
-rw-r--r--sound/soc/codecs/twl4030.c3
-rw-r--r--sound/soc/codecs/wm8580.c4
-rw-r--r--sound/soc/codecs/wm8728.c4
-rw-r--r--sound/soc/codecs/wm8753.c4
-rw-r--r--sound/soc/codecs/wm8990.c4
-rw-r--r--sound/soc/codecs/wm9712.c4
-rw-r--r--sound/soc/codecs/wm9713.c4
9 files changed, 17 insertions, 16 deletions
diff --git a/sound/soc/codecs/ac97.c b/sound/soc/codecs/ac97.c
index fb53e6511af2..89d41277616d 100644
--- a/sound/soc/codecs/ac97.c
+++ b/sound/soc/codecs/ac97.c
@@ -123,7 +123,6 @@ bus_err:
123 snd_soc_free_pcms(socdev); 123 snd_soc_free_pcms(socdev);
124 124
125err: 125err:
126 kfree(socdev->codec->reg_cache);
127 kfree(socdev->codec); 126 kfree(socdev->codec);
128 socdev->codec = NULL; 127 socdev->codec = NULL;
129 return ret; 128 return ret;
@@ -138,7 +137,6 @@ static int ac97_soc_remove(struct platform_device *pdev)
138 return 0; 137 return 0;
139 138
140 snd_soc_free_pcms(socdev); 139 snd_soc_free_pcms(socdev);
141 kfree(socdev->codec->reg_cache);
142 kfree(socdev->codec); 140 kfree(socdev->codec);
143 141
144 return 0; 142 return 0;
diff --git a/sound/soc/codecs/ad1980.c b/sound/soc/codecs/ad1980.c
index c3c5d0eee37a..faf358758e13 100644
--- a/sound/soc/codecs/ad1980.c
+++ b/sound/soc/codecs/ad1980.c
@@ -109,7 +109,7 @@ static unsigned int ac97_read(struct snd_soc_codec *codec,
109 default: 109 default:
110 reg = reg >> 1; 110 reg = reg >> 1;
111 111
112 if (reg >= (ARRAY_SIZE(ad1980_reg))) 112 if (reg >= ARRAY_SIZE(ad1980_reg))
113 return -EINVAL; 113 return -EINVAL;
114 114
115 return cache[reg]; 115 return cache[reg];
@@ -123,7 +123,7 @@ static int ac97_write(struct snd_soc_codec *codec, unsigned int reg,
123 123
124 soc_ac97_ops.write(codec->ac97, reg, val); 124 soc_ac97_ops.write(codec->ac97, reg, val);
125 reg = reg >> 1; 125 reg = reg >> 1;
126 if (reg < (ARRAY_SIZE(ad1980_reg))) 126 if (reg < ARRAY_SIZE(ad1980_reg))
127 cache[reg] = val; 127 cache[reg] = val;
128 128
129 return 0; 129 return 0;
diff --git a/sound/soc/codecs/twl4030.c b/sound/soc/codecs/twl4030.c
index ddc9f37d863f..f530c1e6d9e8 100644
--- a/sound/soc/codecs/twl4030.c
+++ b/sound/soc/codecs/twl4030.c
@@ -125,6 +125,9 @@ static inline unsigned int twl4030_read_reg_cache(struct snd_soc_codec *codec,
125{ 125{
126 u8 *cache = codec->reg_cache; 126 u8 *cache = codec->reg_cache;
127 127
128 if (reg >= TWL4030_CACHEREGNUM)
129 return -EIO;
130
128 return cache[reg]; 131 return cache[reg];
129} 132}
130 133
diff --git a/sound/soc/codecs/wm8580.c b/sound/soc/codecs/wm8580.c
index 9b75a377453e..3faf0e70ce10 100644
--- a/sound/soc/codecs/wm8580.c
+++ b/sound/soc/codecs/wm8580.c
@@ -200,7 +200,7 @@ static inline unsigned int wm8580_read_reg_cache(struct snd_soc_codec *codec,
200 unsigned int reg) 200 unsigned int reg)
201{ 201{
202 u16 *cache = codec->reg_cache; 202 u16 *cache = codec->reg_cache;
203 BUG_ON(reg > ARRAY_SIZE(wm8580_reg)); 203 BUG_ON(reg >= ARRAY_SIZE(wm8580_reg));
204 return cache[reg]; 204 return cache[reg];
205} 205}
206 206
@@ -223,7 +223,7 @@ static int wm8580_write(struct snd_soc_codec *codec, unsigned int reg,
223{ 223{
224 u8 data[2]; 224 u8 data[2];
225 225
226 BUG_ON(reg > ARRAY_SIZE(wm8580_reg)); 226 BUG_ON(reg >= ARRAY_SIZE(wm8580_reg));
227 227
228 /* Registers are 9 bits wide */ 228 /* Registers are 9 bits wide */
229 value &= 0x1ff; 229 value &= 0x1ff;
diff --git a/sound/soc/codecs/wm8728.c b/sound/soc/codecs/wm8728.c
index defa310bc7d9..f90dc52e975d 100644
--- a/sound/soc/codecs/wm8728.c
+++ b/sound/soc/codecs/wm8728.c
@@ -47,7 +47,7 @@ static inline unsigned int wm8728_read_reg_cache(struct snd_soc_codec *codec,
47 unsigned int reg) 47 unsigned int reg)
48{ 48{
49 u16 *cache = codec->reg_cache; 49 u16 *cache = codec->reg_cache;
50 BUG_ON(reg > ARRAY_SIZE(wm8728_reg_defaults)); 50 BUG_ON(reg >= ARRAY_SIZE(wm8728_reg_defaults));
51 return cache[reg]; 51 return cache[reg];
52} 52}
53 53
@@ -55,7 +55,7 @@ static inline void wm8728_write_reg_cache(struct snd_soc_codec *codec,
55 u16 reg, unsigned int value) 55 u16 reg, unsigned int value)
56{ 56{
57 u16 *cache = codec->reg_cache; 57 u16 *cache = codec->reg_cache;
58 BUG_ON(reg > ARRAY_SIZE(wm8728_reg_defaults)); 58 BUG_ON(reg >= ARRAY_SIZE(wm8728_reg_defaults));
59 cache[reg] = value; 59 cache[reg] = value;
60} 60}
61 61
diff --git a/sound/soc/codecs/wm8753.c b/sound/soc/codecs/wm8753.c
index 7283178e0eb5..5a1c1fca120f 100644
--- a/sound/soc/codecs/wm8753.c
+++ b/sound/soc/codecs/wm8753.c
@@ -97,7 +97,7 @@ static inline unsigned int wm8753_read_reg_cache(struct snd_soc_codec *codec,
97 unsigned int reg) 97 unsigned int reg)
98{ 98{
99 u16 *cache = codec->reg_cache; 99 u16 *cache = codec->reg_cache;
100 if (reg < 1 || reg > (ARRAY_SIZE(wm8753_reg) + 1)) 100 if (reg < 1 || reg >= (ARRAY_SIZE(wm8753_reg) + 1))
101 return -1; 101 return -1;
102 return cache[reg - 1]; 102 return cache[reg - 1];
103} 103}
@@ -109,7 +109,7 @@ static inline void wm8753_write_reg_cache(struct snd_soc_codec *codec,
109 unsigned int reg, unsigned int value) 109 unsigned int reg, unsigned int value)
110{ 110{
111 u16 *cache = codec->reg_cache; 111 u16 *cache = codec->reg_cache;
112 if (reg < 1 || reg > 0x3f) 112 if (reg < 1 || reg >= (ARRAY_SIZE(wm8753_reg) + 1))
113 return; 113 return;
114 cache[reg - 1] = value; 114 cache[reg - 1] = value;
115} 115}
diff --git a/sound/soc/codecs/wm8990.c b/sound/soc/codecs/wm8990.c
index 6b2778632d5e..f93c0955ed9d 100644
--- a/sound/soc/codecs/wm8990.c
+++ b/sound/soc/codecs/wm8990.c
@@ -116,7 +116,7 @@ static inline unsigned int wm8990_read_reg_cache(struct snd_soc_codec *codec,
116 unsigned int reg) 116 unsigned int reg)
117{ 117{
118 u16 *cache = codec->reg_cache; 118 u16 *cache = codec->reg_cache;
119 BUG_ON(reg > (ARRAY_SIZE(wm8990_reg)) - 1); 119 BUG_ON(reg >= ARRAY_SIZE(wm8990_reg));
120 return cache[reg]; 120 return cache[reg];
121} 121}
122 122
@@ -129,7 +129,7 @@ static inline void wm8990_write_reg_cache(struct snd_soc_codec *codec,
129 u16 *cache = codec->reg_cache; 129 u16 *cache = codec->reg_cache;
130 130
131 /* Reset register and reserved registers are uncached */ 131 /* Reset register and reserved registers are uncached */
132 if (reg == 0 || reg > ARRAY_SIZE(wm8990_reg) - 1) 132 if (reg == 0 || reg >= ARRAY_SIZE(wm8990_reg))
133 return; 133 return;
134 134
135 cache[reg] = value; 135 cache[reg] = value;
diff --git a/sound/soc/codecs/wm9712.c b/sound/soc/codecs/wm9712.c
index 1b0ace0f4dca..4dc90d67530e 100644
--- a/sound/soc/codecs/wm9712.c
+++ b/sound/soc/codecs/wm9712.c
@@ -452,7 +452,7 @@ static unsigned int ac97_read(struct snd_soc_codec *codec,
452 else { 452 else {
453 reg = reg >> 1; 453 reg = reg >> 1;
454 454
455 if (reg > (ARRAY_SIZE(wm9712_reg))) 455 if (reg >= (ARRAY_SIZE(wm9712_reg)))
456 return -EIO; 456 return -EIO;
457 457
458 return cache[reg]; 458 return cache[reg];
@@ -466,7 +466,7 @@ static int ac97_write(struct snd_soc_codec *codec, unsigned int reg,
466 466
467 soc_ac97_ops.write(codec->ac97, reg, val); 467 soc_ac97_ops.write(codec->ac97, reg, val);
468 reg = reg >> 1; 468 reg = reg >> 1;
469 if (reg <= (ARRAY_SIZE(wm9712_reg))) 469 if (reg < (ARRAY_SIZE(wm9712_reg)))
470 cache[reg] = val; 470 cache[reg] = val;
471 471
472 return 0; 472 return 0;
diff --git a/sound/soc/codecs/wm9713.c b/sound/soc/codecs/wm9713.c
index e636d8a18ed6..0e60e16973d4 100644
--- a/sound/soc/codecs/wm9713.c
+++ b/sound/soc/codecs/wm9713.c
@@ -620,7 +620,7 @@ static unsigned int ac97_read(struct snd_soc_codec *codec,
620 else { 620 else {
621 reg = reg >> 1; 621 reg = reg >> 1;
622 622
623 if (reg > (ARRAY_SIZE(wm9713_reg))) 623 if (reg >= (ARRAY_SIZE(wm9713_reg)))
624 return -EIO; 624 return -EIO;
625 625
626 return cache[reg]; 626 return cache[reg];
@@ -634,7 +634,7 @@ static int ac97_write(struct snd_soc_codec *codec, unsigned int reg,
634 if (reg < 0x7c) 634 if (reg < 0x7c)
635 soc_ac97_ops.write(codec->ac97, reg, val); 635 soc_ac97_ops.write(codec->ac97, reg, val);
636 reg = reg >> 1; 636 reg = reg >> 1;
637 if (reg <= (ARRAY_SIZE(wm9713_reg))) 637 if (reg < (ARRAY_SIZE(wm9713_reg)))
638 cache[reg] = val; 638 cache[reg] = val;
639 639
640 return 0; 640 return 0;