ASoC: fix ak4104 register array access
authorDaniel Mack <daniel@caiaq.de>
Fri, 26 Feb 2010 06:36:54 +0000 (14:36 +0800)
committerGreg Kroah-Hartman <gregkh@suse.de>
Mon, 15 Mar 2010 15:49:52 +0000 (08:49 -0700)
commit e555317c083fda01f516d2153589e82514e20e70 upstream.

Don't touch the variable 'reg' to construct the value for the actual SPI
transport. This variable is again used to access the driver's register
cache, and so random memory is overwritten.
Compute the value in-place instead.

Signed-off-by: Daniel Mack <daniel@caiaq.de>
Acked-by: Liam Girdwood <lrg@slimlogic.co.uk>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
sound/soc/codecs/ak4104.c

index 4d47bc4f74284764ec24434167371d3245009df8..10c7550393ba93be17886d637aec0ad7aaacc362 100644 (file)
@@ -90,12 +90,10 @@ static int ak4104_spi_write(struct snd_soc_codec *codec, unsigned int reg,
        if (reg >= codec->reg_cache_size)
                return -EINVAL;
 
-       reg &= AK4104_REG_MASK;
-       reg |= AK4104_WRITE;
-
        /* only write to the hardware if value has changed */
        if (cache[reg] != value) {
-               u8 tmp[2] = { reg, value };
+               u8 tmp[2] = { (reg & AK4104_REG_MASK) | AK4104_WRITE, value };
+
                if (spi_write(spi, tmp, sizeof(tmp))) {
                        dev_err(&spi->dev, "SPI write failed\n");
                        return -EIO;