]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
ASoC: fixes to caching implementations
authorIan Molton <ian@mnementh.co.uk>
Sat, 17 Jan 2009 17:44:23 +0000 (17:44 +0000)
committerMark Brown <broonie@opensource.wolfsonmicro.com>
Mon, 19 Jan 2009 16:23:13 +0000 (16:23 +0000)
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>
sound/soc/codecs/ac97.c
sound/soc/codecs/ad1980.c
sound/soc/codecs/twl4030.c
sound/soc/codecs/wm8580.c
sound/soc/codecs/wm8728.c
sound/soc/codecs/wm8753.c
sound/soc/codecs/wm8990.c
sound/soc/codecs/wm9712.c
sound/soc/codecs/wm9713.c

index fb53e6511af25d0b0d0dd164a1b1de0a511f73c7..89d41277616da75e3f03508bab6f1f79c841a148 100644 (file)
@@ -123,7 +123,6 @@ bus_err:
        snd_soc_free_pcms(socdev);
 
 err:
-       kfree(socdev->codec->reg_cache);
        kfree(socdev->codec);
        socdev->codec = NULL;
        return ret;
@@ -138,7 +137,6 @@ static int ac97_soc_remove(struct platform_device *pdev)
                return 0;
 
        snd_soc_free_pcms(socdev);
-       kfree(socdev->codec->reg_cache);
        kfree(socdev->codec);
 
        return 0;
index c3c5d0eee37ac728ce3c9bd6d20e155db80bf845..faf358758e13215f78dbea021509c30b66b71c7f 100644 (file)
@@ -109,7 +109,7 @@ static unsigned int ac97_read(struct snd_soc_codec *codec,
        default:
                reg = reg >> 1;
 
-               if (reg >= (ARRAY_SIZE(ad1980_reg)))
+               if (reg >= ARRAY_SIZE(ad1980_reg))
                        return -EINVAL;
 
                return cache[reg];
@@ -123,7 +123,7 @@ static int ac97_write(struct snd_soc_codec *codec, unsigned int reg,
 
        soc_ac97_ops.write(codec->ac97, reg, val);
        reg = reg >> 1;
-       if (reg < (ARRAY_SIZE(ad1980_reg)))
+       if (reg < ARRAY_SIZE(ad1980_reg))
                cache[reg] = val;
 
        return 0;
index ddc9f37d863fdf99de849ae8038aaf12e231d231..f530c1e6d9e814955cfd380d82b5f9c3c5a9ee93 100644 (file)
@@ -125,6 +125,9 @@ static inline unsigned int twl4030_read_reg_cache(struct snd_soc_codec *codec,
 {
        u8 *cache = codec->reg_cache;
 
+       if (reg >= TWL4030_CACHEREGNUM)
+               return -EIO;
+
        return cache[reg];
 }
 
index 9b75a377453eec0270e6c6654ff3e6521ecf6d5e..3faf0e70ce1087b9af97fe93e8f1dde7f87f4598 100644 (file)
@@ -200,7 +200,7 @@ static inline unsigned int wm8580_read_reg_cache(struct snd_soc_codec *codec,
        unsigned int reg)
 {
        u16 *cache = codec->reg_cache;
-       BUG_ON(reg > ARRAY_SIZE(wm8580_reg));
+       BUG_ON(reg >= ARRAY_SIZE(wm8580_reg));
        return cache[reg];
 }
 
@@ -223,7 +223,7 @@ static int wm8580_write(struct snd_soc_codec *codec, unsigned int reg,
 {
        u8 data[2];
 
-       BUG_ON(reg > ARRAY_SIZE(wm8580_reg));
+       BUG_ON(reg >= ARRAY_SIZE(wm8580_reg));
 
        /* Registers are 9 bits wide */
        value &= 0x1ff;
index defa310bc7d9fd4e2e3f90a8834ff39bcca44028..f90dc52e975da93490af356639be8a6b8377162e 100644 (file)
@@ -47,7 +47,7 @@ static inline unsigned int wm8728_read_reg_cache(struct snd_soc_codec *codec,
        unsigned int reg)
 {
        u16 *cache = codec->reg_cache;
-       BUG_ON(reg > ARRAY_SIZE(wm8728_reg_defaults));
+       BUG_ON(reg >= ARRAY_SIZE(wm8728_reg_defaults));
        return cache[reg];
 }
 
@@ -55,7 +55,7 @@ static inline void wm8728_write_reg_cache(struct snd_soc_codec *codec,
        u16 reg, unsigned int value)
 {
        u16 *cache = codec->reg_cache;
-       BUG_ON(reg > ARRAY_SIZE(wm8728_reg_defaults));
+       BUG_ON(reg >= ARRAY_SIZE(wm8728_reg_defaults));
        cache[reg] = value;
 }
 
index 7283178e0eb52adf71eb86b46e1d4a05c27387df..5a1c1fca120f771e03ca3bb674f3d4acad69f1c7 100644 (file)
@@ -97,7 +97,7 @@ static inline unsigned int wm8753_read_reg_cache(struct snd_soc_codec *codec,
        unsigned int reg)
 {
        u16 *cache = codec->reg_cache;
-       if (reg < 1 || reg > (ARRAY_SIZE(wm8753_reg) + 1))
+       if (reg < 1 || reg >= (ARRAY_SIZE(wm8753_reg) + 1))
                return -1;
        return cache[reg - 1];
 }
@@ -109,7 +109,7 @@ static inline void wm8753_write_reg_cache(struct snd_soc_codec *codec,
        unsigned int reg, unsigned int value)
 {
        u16 *cache = codec->reg_cache;
-       if (reg < 1 || reg > 0x3f)
+       if (reg < 1 || reg >= (ARRAY_SIZE(wm8753_reg) + 1))
                return;
        cache[reg - 1] = value;
 }
index 6b2778632d5ee5d57349d199b9864b6022a5e260..f93c0955ed9d79163c6cdf2245e78681b9104b8b 100644 (file)
@@ -116,7 +116,7 @@ static inline unsigned int wm8990_read_reg_cache(struct snd_soc_codec *codec,
        unsigned int reg)
 {
        u16 *cache = codec->reg_cache;
-       BUG_ON(reg > (ARRAY_SIZE(wm8990_reg)) - 1);
+       BUG_ON(reg >= ARRAY_SIZE(wm8990_reg));
        return cache[reg];
 }
 
@@ -129,7 +129,7 @@ static inline void wm8990_write_reg_cache(struct snd_soc_codec *codec,
        u16 *cache = codec->reg_cache;
 
        /* Reset register and reserved registers are uncached */
-       if (reg == 0 || reg > ARRAY_SIZE(wm8990_reg) - 1)
+       if (reg == 0 || reg >= ARRAY_SIZE(wm8990_reg))
                return;
 
        cache[reg] = value;
index 1b0ace0f4dcafc2b64e4cf955a98fa7bb5782e6e..4dc90d67530ee430cbdfae5b440606df427ae242 100644 (file)
@@ -452,7 +452,7 @@ static unsigned int ac97_read(struct snd_soc_codec *codec,
        else {
                reg = reg >> 1;
 
-               if (reg > (ARRAY_SIZE(wm9712_reg)))
+               if (reg >= (ARRAY_SIZE(wm9712_reg)))
                        return -EIO;
 
                return cache[reg];
@@ -466,7 +466,7 @@ static int ac97_write(struct snd_soc_codec *codec, unsigned int reg,
 
        soc_ac97_ops.write(codec->ac97, reg, val);
        reg = reg >> 1;
-       if (reg <= (ARRAY_SIZE(wm9712_reg)))
+       if (reg < (ARRAY_SIZE(wm9712_reg)))
                cache[reg] = val;
 
        return 0;
index e636d8a18ed6ce5150a578adf0e42c6191afc127..0e60e16973d454815e6b97849d59f0046dad97ac 100644 (file)
@@ -620,7 +620,7 @@ static unsigned int ac97_read(struct snd_soc_codec *codec,
        else {
                reg = reg >> 1;
 
-               if (reg > (ARRAY_SIZE(wm9713_reg)))
+               if (reg >= (ARRAY_SIZE(wm9713_reg)))
                        return -EIO;
 
                return cache[reg];
@@ -634,7 +634,7 @@ static int ac97_write(struct snd_soc_codec *codec, unsigned int reg,
        if (reg < 0x7c)
                soc_ac97_ops.write(codec->ac97, reg, val);
        reg = reg >> 1;
-       if (reg <= (ARRAY_SIZE(wm9713_reg)))
+       if (reg < (ARRAY_SIZE(wm9713_reg)))
                cache[reg] = val;
 
        return 0;