mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
regcache: extract __regcache_sync() to deduplicate sync dispatch
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> Link: https://patch.msgid.link/20261002-regmap-lock-2nd-v2-2-e172b0501c52@nxp.com Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
parent
81556a7aec
commit
7ca8aa98e2
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user