[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251022200408.63027-3-sander@svanheule.net>
Date: Wed, 22 Oct 2025 22:04:08 +0200
From: Sander Vanheule <sander@...nheule.net>
To: Mark Brown <broonie@...nel.org>,
linux-kernel@...r.kernel.org
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
"Rafael J . Wysocki" <rafael@...nel.org>,
Danilo Krummrich <dakr@...nel.org>,
Sander Vanheule <sander@...nheule.net>
Subject: [PATCH v4 2/2] 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@...nheule.net>
---
I've decided to use dev_warn() with __test_and_set_bit() to avoid log
flooding from e.g. regmap_update_bits() deciding not to write an updated
value. This way the warning is only issued once per invalid register,
which will hopefully be a bit more obvious than a single log entry from
a dev_warn_once().
Changes since v3:
- New patch: emit a warning for the flat cache on suspicious registers
---
drivers/base/regmap/regcache-flat.c | 21 ++++++++-------------
1 file changed, 8 insertions(+), 13 deletions(-)
diff --git a/drivers/base/regmap/regcache-flat.c b/drivers/base/regmap/regcache-flat.c
index 52ce125a74e1..8802713e0cc6 100644
--- a/drivers/base/regmap/regcache-flat.c
+++ b/drivers/base/regmap/regcache-flat.c
@@ -90,18 +90,13 @@ static int regcache_flat_read(struct regmap *map,
struct regcache_flat_data *cache = map->cache;
unsigned int index = regcache_flat_get_index(map, reg);
- *value = cache->data[index];
-
- return 0;
-}
-
-static int regcache_flat_write(struct regmap *map, unsigned int reg,
- unsigned int value)
-{
- struct regcache_flat_data *cache = map->cache;
- unsigned int index = regcache_flat_get_index(map, reg);
+ /* legacy behavior: ignore validity, but warn the user once per reg */
+ if (unlikely(!__test_and_set_bit(index, cache->valid)))
+ dev_warn(map->dev,
+ "using zero-initialized flat cache, "
+ "this may cause unexpected behavior");
- cache->data[index] = value;
+ *value = cache->data[index];
return 0;
}
@@ -120,7 +115,7 @@ static int regcache_flat_sparse_read(struct regmap *map,
return 0;
}
-static int regcache_flat_sparse_write(struct regmap *map, unsigned int reg,
+static int regcache_flat_write(struct regmap *map, unsigned int reg,
unsigned int value)
{
struct regcache_flat_data *cache = map->cache;
@@ -159,6 +154,6 @@ struct regcache_ops regcache_flat_sparse_ops = {
.init = regcache_flat_init,
.exit = regcache_flat_exit,
.read = regcache_flat_sparse_read,
- .write = regcache_flat_sparse_write,
+ .write = regcache_flat_write,
.drop = regcache_flat_drop,
};
--
2.51.0
Powered by blists - more mailing lists