[PATCH RFC 4/4] regmap: debugfs: use the regmap scoped lock guard

From: Peng Fan (OSS)

Date: Mon Sep 21 2026 - 02:07:52 EST


From: Peng Fan <peng.fan@xxxxxxx>

Convert the open-coded map->lock()/map->unlock() users in the debugfs
cache_only and cache_bypass write handlers to the regmap scoped guard.

regmap_cache_bypass_write_file() uses guard(regmap)() since the locked
region runs to the return. regmap_cache_only_write_file() uses
scoped_guard(regmap, ...) because the subsequent regcache_sync() must
run with the lock released - it takes the regmap lock itself - so it
stays outside the guarded scope exactly as before. No functional
change.

Assisted-by: Claude:claude-opus-4.8
Signed-off-by: Peng Fan <peng.fan@xxxxxxx>
---
drivers/base/regmap/regmap-debugfs.c | 24 ++++++++++--------------
1 file changed, 10 insertions(+), 14 deletions(-)

diff --git a/drivers/base/regmap/regmap-debugfs.c b/drivers/base/regmap/regmap-debugfs.c
index 18f1c60749fe..ec207548a6bb 100644
--- a/drivers/base/regmap/regmap-debugfs.c
+++ b/drivers/base/regmap/regmap-debugfs.c
@@ -471,18 +471,16 @@ static ssize_t regmap_cache_only_write_file(struct file *file,
if (err)
return count;

- map->lock(map->lock_arg);
-
- if (new_val && !map->cache_only) {
- dev_warn(map->dev, "debugfs cache_only=Y forced\n");
- add_taint(TAINT_USER, LOCKDEP_STILL_OK);
- } else if (!new_val && map->cache_only) {
- dev_warn(map->dev, "debugfs cache_only=N forced: syncing cache\n");
- require_sync = true;
+ scoped_guard(regmap, map) {
+ if (new_val && !map->cache_only) {
+ dev_warn(map->dev, "debugfs cache_only=Y forced\n");
+ add_taint(TAINT_USER, LOCKDEP_STILL_OK);
+ } else if (!new_val && map->cache_only) {
+ dev_warn(map->dev, "debugfs cache_only=N forced: syncing cache\n");
+ require_sync = true;
+ }
+ map->cache_only = new_val;
}
- map->cache_only = new_val;
-
- map->unlock(map->lock_arg);

if (require_sync) {
err = regcache_sync(map);
@@ -513,7 +511,7 @@ static ssize_t regmap_cache_bypass_write_file(struct file *file,
if (err)
return count;

- map->lock(map->lock_arg);
+ guard(regmap)(map);

if (new_val && !map->cache_bypass) {
dev_warn(map->dev, "debugfs cache_bypass=Y forced\n");
@@ -523,8 +521,6 @@ static ssize_t regmap_cache_bypass_write_file(struct file *file,
}
map->cache_bypass = new_val;

- map->unlock(map->lock_arg);
-
return count;
}


--
2.51.0