UPSTREAM: regmap: drop cache if the bus transfer error
authorElaine Zhang <zhangqing@rock-chips.com>
Thu, 18 Aug 2016 09:01:55 +0000 (17:01 +0800)
committerElaine Zhang <zhangqing@rock-chips.com>
Fri, 19 Aug 2016 08:15:06 +0000 (16:15 +0800)
regmap_write
->_regmap_raw_write
-->regcache_write first and than use map->bus->write to write i2c or spi
But if the i2c or spi transfer failed, But the cache is updated, So if I use
regmap_read will get the cache data which is not the real register value.

Change-Id: Iae06edf8a2a50d2561d351a8398bd3140904630c
Signed-off-by: Elaine Zhang <zhangqing@rock-chips.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
(cherry picked from
 git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap.git
 commit 815806e39bf6f7e7b34875d4a9609dbe76661782)

drivers/base/regmap/regmap.c

index 4ac63c0e50c7e6a446847b7a29567834d4a5b073..bb216c9d3c0904143a0dbb1960a735646de57201 100644 (file)
@@ -1372,6 +1372,8 @@ int _regmap_raw_write(struct regmap *map, unsigned int reg,
                ret = map->bus->write(map->bus_context, buf, len);
 
                kfree(buf);
+       } else if (ret != 0 && !map->cache_bypass && map->format.parse_val) {
+               regcache_drop_region(map, reg, reg + 1);
        }
 
        trace_regmap_hw_write_done(map, reg, val_len / map->format.val_bytes);