From: "Peng Fan (OSS)" <peng.fan@oss.nxp.com>
To: Mark Brown <broonie@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Danilo Krummrich <dakr@kernel.org>
Cc: linux-kernel@vger.kernel.org, driver-core@lists.linux.dev,
Peng Fan <peng.fan@nxp.com>
Subject: [PATCH v2 2/7] regcache: extract __regcache_sync() to deduplicate sync dispatch
Date: Fri, 02 Oct 2026 21:11:18 +0800 [thread overview]
Message-ID: <20261002-regmap-lock-2nd-v2-2-e172b0501c52@nxp.com> (raw)
In-Reply-To: <20261002-regmap-lock-2nd-v2-0-e172b0501c52@nxp.com>
From: Peng Fan <peng.fan@nxp.com>
regcache_sync() and regcache_sync_region() both open-code the same
pattern: check cache_dirty, then dispatch to either cache_ops->sync()
or regcache_default_sync().
Extract this into a static __regcache_sync() helper that both callers
share. The helper checks cache_dirty and returns 0 early when the
cache is clean, dispatches to the backend sync callback when present,
and falls back to regcache_default_sync() otherwise.
In regcache_sync_region(), the cache_dirty early-exit previously
skipped setting map->async. With the helper, map->async is set to
true before the call and restored to false unconditionally afterward,
so when cache_dirty is false the flag is toggled and immediately
restored - functionally equivalent.
No functional change.
Assisted-by: LLM
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
drivers/base/regmap/regcache.c | 28 +++++++++++++++-------------
1 file changed, 15 insertions(+), 13 deletions(-)
diff --git a/drivers/base/regmap/regcache.c b/drivers/base/regmap/regcache.c
index ebfa27bb6f54..b486cd826b3c 100644
--- a/drivers/base/regmap/regcache.c
+++ b/drivers/base/regmap/regcache.c
@@ -22,6 +22,8 @@ static const struct regcache_ops *cache_types[] = {
®cache_flat_ops,
};
+static int regcache_default_sync(struct regmap *map, unsigned int min, unsigned int max);
+
static int regcache_defaults_cmp(const void *a, const void *b)
{
const struct reg_default *x = a;
@@ -143,6 +145,17 @@ static void regcache_locked_exit(struct regmap *map)
map->cache_ops->exit(map);
}
+static int __regcache_sync(struct regmap *map, unsigned int min, unsigned int max)
+{
+ if (!map->cache_dirty)
+ return 0;
+
+ if (map->cache_ops->sync)
+ return map->cache_ops->sync(map, min, max);
+
+ return regcache_default_sync(map, min, max);
+}
+
int regcache_init(struct regmap *map, const struct regmap_config *config)
{
bool sort_defaults = false;
@@ -461,11 +474,7 @@ int regcache_sync(struct regmap *map)
}
map->cache_bypass = false;
- if (map->cache_ops->sync)
- sync_ret = map->cache_ops->sync(map, 0, map->max_register);
- else
- sync_ret = regcache_default_sync(map, 0, map->max_register);
-
+ sync_ret = __regcache_sync(map, 0, map->max_register);
if (sync_ret == 0)
map->cache_dirty = false;
@@ -545,17 +554,10 @@ int regcache_sync_region(struct regmap *map, unsigned int min,
trace_regcache_sync(map, name, "start region");
- if (!map->cache_dirty)
- goto out;
-
map->async = true;
- if (map->cache_ops->sync)
- ret = map->cache_ops->sync(map, min, max);
- else
- ret = regcache_default_sync(map, min, max);
+ ret = __regcache_sync(map, min, max);
-out:
/* Restore the bypass state */
map->cache_bypass = bypass;
map->async = false;
--
2.51.0
next prev parent reply other threads:[~2026-10-02 13:14 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-02 13:11 [PATCH v2 0/7] regmap: cleanups for regcache and regmap init paths Peng Fan (OSS)
2026-10-02 13:11 ` [PATCH v2 1/7] regcache: extract locked helpers to replace open-coded lock/unlock pairs Peng Fan (OSS)
2026-10-02 13:11 ` Peng Fan (OSS) [this message]
2026-10-02 13:11 ` [PATCH v2 3/7] regcache: simplify control flow and reduce nesting Peng Fan (OSS)
2026-10-02 13:11 ` [PATCH v2 4/7] regmap: use krealloc_array() in regmap_register_patch() Peng Fan (OSS)
2026-10-02 13:11 ` [PATCH v2 5/7] regmap: fix potential double-free of map->reg_defaults on cache reinit Peng Fan (OSS)
2026-10-02 13:11 ` [PATCH v2 6/7] regmap: debugfs: Use __free(kfree) in regmap_name_read_file() Peng Fan (OSS)
2026-10-02 13:11 ` [PATCH v2 7/7] regmap: debugfs: Use guard to simplify code Peng Fan (OSS)
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=20261002-regmap-lock-2nd-v2-2-e172b0501c52@nxp.com \
--to=peng.fan@oss.nxp.com \
--cc=broonie@kernel.org \
--cc=dakr@kernel.org \
--cc=driver-core@lists.linux.dev \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peng.fan@nxp.com \
--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®