Skip to contentSkip to conversation

regcache: Warn if regcache_sync() is called in cache_only mode

PATCH In review [email protected] 2 participants 3 messages Jul 20 – Jul 21

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 regcache: Warn if regcache_sync() is called in cache_only mode

From: bui duc phuc <[email protected]>

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.

---

Changes in v2 :
- Check cache_only under the lock.
- Update the function comment.

 drivers/base/regmap/regcache.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/base/regmap/regcache.c +10 -0
index 96cdae25b9c4..20e0641d21b2 100644
@@ -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 disable cache_only before calling this
+ * function.
+ *
  * Return a negative value on failure, 0 on success.
  */
 int regcache_sync(struct regmap *map)
@@ -414,6 +418,12 @@ int regcache_sync(struct regmap *map)
 	BUG_ON(!map->cache_ops);
 
 	map->lock(map->lock_arg);
+
+	if (WARN_ON(map->cache_only)) {
+		map->unlock(map->lock_arg);
+		return -EINVAL;
+	}
+
 	/* Remember the initial bypass state */
 	bypass = map->cache_bypass;
 	dev_dbg(map->dev, "Syncing %s cache\n",
Signature · 1 line
2.43.0
#1 lore raw

PATCH v2 2/2 regcache: Validate cache_only state in regcache_sync_region()

From: bui duc phuc <[email protected]>

Add a WARN_ON() check to ensure regcache_sync_region() is not called while cache_only is enabled.

---
 drivers/base/regmap/regcache.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/base/regmap/regcache.c +4 -0
index 20e0641d21b2..be167ee6f57c 100644
@@ -518,6 +518,10 @@ int regcache_sync_region(struct regmap *map, unsigned int min,
 
 	map->lock(map->lock_arg);
 
+	if (WARN_ON(map->cache_only)) {
+		map->unlock(map->lock_arg);
+		return -EINVAL;
+	}
 	/* Remember the initial bypass state */
 	bypass = map->cache_bypass;
 
Signature · 1 line
2.43.0
maintainer
#2 lore raw
In reply to [email protected]
Quoted 1 line · On Mon, 20 Jul 2026 10:32:37 +0700, [email protected] wrote:

regcache: Warn if regcache_sync() is called in cache_only mode

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap.git for-7.3

Thanks!

[1/2] regcache: Warn if regcache_sync() is called in cache_only mode

      https://git.kernel.org/broonie/regmap/c/86fc3483a4d6
[2/2] regcache: Validate cache_only state in regcache_sync_region()
      https://git.kernel.org/broonie/regmap/c/afc8e3ee8307

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark