Skip to content

Commit 984a4af

Browse files
lopsided98broonie
authored andcommitted
regmap: prevent noinc writes from clobbering cache
Currently, noinc writes are cached as if they were standard incrementing writes, overwriting unrelated register values in the cache. Instead, we want to cache the last value written to the register, as is done in the accelerated noinc handler (regmap_noinc_readwrite). Fixes: cdf6b11 ("regmap: Add regmap_noinc_write API") Signed-off-by: Ben Wolsieffer <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 6a2e332 commit 984a4af

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

drivers/base/regmap/regmap.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,17 +1620,19 @@ static int _regmap_raw_write_impl(struct regmap *map, unsigned int reg,
16201620
}
16211621

16221622
if (!map->cache_bypass && map->format.parse_val) {
1623-
unsigned int ival;
1623+
unsigned int ival, offset;
16241624
int val_bytes = map->format.val_bytes;
1625-
for (i = 0; i < val_len / val_bytes; i++) {
1626-
ival = map->format.parse_val(val + (i * val_bytes));
1627-
ret = regcache_write(map,
1628-
reg + regmap_get_offset(map, i),
1629-
ival);
1625+
1626+
/* Cache the last written value for noinc writes */
1627+
i = noinc ? val_len - val_bytes : 0;
1628+
for (; i < val_len; i += val_bytes) {
1629+
ival = map->format.parse_val(val + i);
1630+
offset = noinc ? 0 : regmap_get_offset(map, i / val_bytes);
1631+
ret = regcache_write(map, reg + offset, ival);
16301632
if (ret) {
16311633
dev_err(map->dev,
16321634
"Error in caching of register: %x ret: %d\n",
1633-
reg + regmap_get_offset(map, i), ret);
1635+
reg + offset, ret);
16341636
return ret;
16351637
}
16361638
}

0 commit comments

Comments
 (0)