Skip to content

Commit 85da24a

Browse files
BuiDucPhucbroonie
authored andcommitted
regcache: Preserve cache synchronization errors in regcache_sync()
regcache_sync() currently stores the return value from both cache synchronization and selector register rewriting in the same variable. As a result, a successful selector register rewrite can overwrite an earlier cache synchronization error, causing regcache_sync() to return success even though synchronization failed. Track the two operations with separate return variables and preserve the cache synchronization error. Errors from rewriting selector registers are returned only if cache synchronization completed successfully. Signed-off-by: bui duc phuc <phucduc.bui@gmail.com> Link: https://patch.msgid.link/20260713050312.38729-2-phucduc.bui@gmail.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 35845da commit 85da24a

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

drivers/base/regmap/regcache.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,8 @@ static int rbtree_all(const void *key, const struct rb_node *node)
401401
*/
402402
int regcache_sync(struct regmap *map)
403403
{
404-
int ret = 0;
404+
int sync_ret = 0;
405+
int selector_ret = 0;
405406
unsigned int i;
406407
const char *name;
407408
bool bypass;
@@ -426,21 +427,21 @@ int regcache_sync(struct regmap *map)
426427
/* Apply any patch first */
427428
map->cache_bypass = true;
428429
for (i = 0; i < map->patch_regs; i++) {
429-
ret = _regmap_write(map, map->patch[i].reg, map->patch[i].def);
430-
if (ret != 0) {
430+
sync_ret = _regmap_write(map, map->patch[i].reg, map->patch[i].def);
431+
if (sync_ret != 0) {
431432
dev_err(map->dev, "Failed to write %x = %x: %d\n",
432-
map->patch[i].reg, map->patch[i].def, ret);
433+
map->patch[i].reg, map->patch[i].def, sync_ret);
433434
goto out;
434435
}
435436
}
436437
map->cache_bypass = false;
437438

438439
if (map->cache_ops->sync)
439-
ret = map->cache_ops->sync(map, 0, map->max_register);
440+
sync_ret = map->cache_ops->sync(map, 0, map->max_register);
440441
else
441-
ret = regcache_default_sync(map, 0, map->max_register);
442+
sync_ret = regcache_default_sync(map, 0, map->max_register);
442443

443-
if (ret == 0)
444+
if (sync_ret == 0)
444445
map->cache_dirty = false;
445446

446447
out:
@@ -462,10 +463,10 @@ int regcache_sync(struct regmap *map)
462463
if (regcache_read(map, this->selector_reg, &i) != 0)
463464
continue;
464465

465-
ret = _regmap_write(map, this->selector_reg, i);
466-
if (ret != 0) {
466+
selector_ret = _regmap_write(map, this->selector_reg, i);
467+
if (selector_ret != 0) {
467468
dev_err(map->dev, "Failed to write %x = %x: %d\n",
468-
this->selector_reg, i, ret);
469+
this->selector_reg, i, selector_ret);
469470
break;
470471
}
471472
}
@@ -476,7 +477,7 @@ int regcache_sync(struct regmap *map)
476477

477478
trace_regcache_sync(map, name, "stop");
478479

479-
return ret;
480+
return sync_ret ? sync_ret : selector_ret;
480481
}
481482
EXPORT_SYMBOL_GPL(regcache_sync);
482483

0 commit comments

Comments
 (0)