[PATCH] regcache: Warn if regcache_sync() is called in cache_only mode
From: phucduc . bui
Date: Wed Jul 15 2026 - 01:23:54 EST
From: bui duc phuc <phucduc.bui@xxxxxxxxx>
Calling regcache_sync() while cache_only is enabled is invalid API
usage, since writes are intentionally kept in the cache and cannot
be synchronized to hardware.
Document that callers must disable cache_only before calling
regcache_sync(), and reject incorrect usage with a WARN_ON() and
-EINVAL.
Signed-off-by: bui duc phuc <phucduc.bui@xxxxxxxxx>
---
drivers/base/regmap/regcache.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/base/regmap/regcache.c b/drivers/base/regmap/regcache.c
index 96cdae25b9c4..d786cc8bf4d8 100644
--- a/drivers/base/regmap/regcache.c
+++ b/drivers/base/regmap/regcache.c
@@ -397,6 +397,10 @@ static int rbtree_all(const void *key, const struct rb_node *node)
* volatile. In general drivers can choose not to use the provided
* syncing functionality if they so require.
*
+ * This pushes cached changes made while cache_only (e.g. suspend) down
+ * to hardware. The caller must clear cache_only first, or writes will
+ * only update the cache.
+ *
* Return a negative value on failure, 0 on success.
*/
int regcache_sync(struct regmap *map)
@@ -411,6 +415,9 @@ int regcache_sync(struct regmap *map)
if (WARN_ON(map->cache_type == REGCACHE_NONE))
return -EINVAL;
+ if (WARN_ON(map->cache_only))
+ return -EINVAL;
+
BUG_ON(!map->cache_ops);
map->lock(map->lock_arg);
--
2.43.0