Skip to content

Commit

Permalink
ASoC: fixes to caching implementations
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Ian Molton authored and Mark Brown committed Jan 19, 2009
1 parent 28796ea commit 91432e9
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 16 deletions.
2 changes: 0 additions & 2 deletions sound/soc/codecs/ac97.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ static int ac97_soc_probe(struct platform_device *pdev)
snd_soc_free_pcms(socdev);

err:
kfree(socdev->codec->reg_cache);
kfree(socdev->codec);
socdev->codec = NULL;
return ret;
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions sound/soc/codecs/ad1980.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions sound/soc/codecs/twl4030.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

Expand Down
4 changes: 2 additions & 2 deletions sound/soc/codecs/wm8580.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions sound/soc/codecs/wm8728.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ 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];
}

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;
}

Expand Down
4 changes: 2 additions & 2 deletions sound/soc/codecs/wm8753.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand All @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions sound/soc/codecs/wm8990.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions sound/soc/codecs/wm9712.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions sound/soc/codecs/wm9713.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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;
Expand Down

0 comments on commit 91432e9

Please sign in to comment.