Skip to content

Commit e062bdf

Browse files
svanheulebroonie
authored andcommitted
regmap: warn users about uninitialized flat cache
The standard flat cache did not contain any validity info, so the cache was always considered to be entirely valid. Multiple mechanisms exist to initialize the cache on regmap init (defaults, raw defaults, HW init), but not all drivers are using one of these. As a result, their implementation might currently depend on the zero-initialized cache or contain other workarounds. When reading an uninitialized value from the flat cache, warn the user, but maintain the current behavior. This will allow developers to switch to a sparse (flat) cache independently. Signed-off-by: Sander Vanheule <sander@svanheule.net> Link: https://patch.msgid.link/20251029081248.52607-3-sander@svanheule.net Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 9c7f726 commit e062bdf

1 file changed

Lines changed: 6 additions & 12 deletions

File tree

drivers/base/regmap/regcache-flat.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ static int regcache_flat_read(struct regmap *map,
8989
struct regcache_flat_data *cache = map->cache;
9090
unsigned int index = regcache_flat_get_index(map, reg);
9191

92+
/* legacy behavior: ignore validity, but warn the user */
93+
if (unlikely(!test_bit(index, cache->valid)))
94+
dev_warn_once(map->dev,
95+
"using zero-initialized flat cache, this may cause unexpected behavior");
96+
9297
*value = cache->data[index];
9398

9499
return 0;
@@ -114,17 +119,6 @@ static int regcache_flat_write(struct regmap *map, unsigned int reg,
114119
struct regcache_flat_data *cache = map->cache;
115120
unsigned int index = regcache_flat_get_index(map, reg);
116121

117-
cache->data[index] = value;
118-
119-
return 0;
120-
}
121-
122-
static int regcache_flat_sparse_write(struct regmap *map, unsigned int reg,
123-
unsigned int value)
124-
{
125-
struct regcache_flat_data *cache = map->cache;
126-
unsigned int index = regcache_flat_get_index(map, reg);
127-
128122
cache->data[index] = value;
129123
__set_bit(index, cache->valid);
130124

@@ -158,6 +152,6 @@ struct regcache_ops regcache_flat_sparse_ops = {
158152
.init = regcache_flat_init,
159153
.exit = regcache_flat_exit,
160154
.read = regcache_flat_sparse_read,
161-
.write = regcache_flat_sparse_write,
155+
.write = regcache_flat_write,
162156
.drop = regcache_flat_drop,
163157
};

0 commit comments

Comments
 (0)