From: Sander Vanheule <sander@svanheule.net>
To: Mark Brown <broonie@kernel.org>, linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J . Wysocki" <rafael@kernel.org>,
Danilo Krummrich <dakr@kernel.org>,
Sander Vanheule <sander@svanheule.net>
Subject: [PATCH v6 2/2] regmap: warn users about uninitialized flat cache
Date: Wed, 29 Oct 2025 09:12:48 +0100 [thread overview]
Message-ID: <20251029081248.52607-3-sander@svanheule.net> (raw)
In-Reply-To: <20251029081248.52607-1-sander@svanheule.net>
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>
---
Changes since v4:
- Use one line for the log message
- Use dev_warn_once() with test_bit() to avoid log flooding with offset
register spaces
Changes since v3:
- New patch: emit a warning for the flat cache on suspicious registers
---
drivers/base/regmap/regcache-flat.c | 18 ++++++------------
1 file changed, 6 insertions(+), 12 deletions(-)
diff --git a/drivers/base/regmap/regcache-flat.c b/drivers/base/regmap/regcache-flat.c
index 86f7679175b1..3b9235bb8313 100644
--- a/drivers/base/regmap/regcache-flat.c
+++ b/drivers/base/regmap/regcache-flat.c
@@ -89,6 +89,11 @@ static int regcache_flat_read(struct regmap *map,
struct regcache_flat_data *cache = map->cache;
unsigned int index = regcache_flat_get_index(map, reg);
+ /* legacy behavior: ignore validity, but warn the user */
+ if (unlikely(!test_bit(index, cache->valid)))
+ dev_warn_once(map->dev,
+ "using zero-initialized flat cache, this may cause unexpected behavior");
+
*value = cache->data[index];
return 0;
@@ -114,17 +119,6 @@ static int regcache_flat_write(struct regmap *map, unsigned int reg,
struct regcache_flat_data *cache = map->cache;
unsigned int index = regcache_flat_get_index(map, reg);
- cache->data[index] = value;
-
- return 0;
-}
-
-static int regcache_flat_sparse_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);
-
cache->data[index] = value;
__set_bit(index, cache->valid);
@@ -158,6 +152,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
next prev parent reply other threads:[~2025-10-29 8:13 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-29 8:12 [PATCH v6 0/2] regmap: Introduce validity info for " Sander Vanheule
2025-10-29 8:12 ` [PATCH v6 1/2] regmap: add flat cache with sparse validity Sander Vanheule
2025-10-29 8:12 ` Sander Vanheule [this message]
2025-10-30 11:31 ` [PATCH v6 0/2] regmap: Introduce validity info for flat cache Mark Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251029081248.52607-3-sander@svanheule.net \
--to=sander@svanheule.net \
--cc=broonie@kernel.org \
--cc=dakr@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®