* [PATCH] regcache: Warn if regcache_sync() is called in cache_only mode
@ 2026-07-15 5:21 phucduc.bui
2026-07-15 12:39 ` Mark Brown
0 siblings, 1 reply; 4+ messages in thread
From: phucduc.bui @ 2026-07-15 5:21 UTC (permalink / raw)
To: Mark Brown, Greg Kroah-Hartman, rafael
Cc: Danilo Krummrich, linux-kernel, driver-core, bui duc phuc
From: bui duc phuc <phucduc.bui@gmail.com>
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@gmail.com>
---
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] regcache: Warn if regcache_sync() is called in cache_only mode
2026-07-15 5:21 [PATCH] regcache: Warn if regcache_sync() is called in cache_only mode phucduc.bui
@ 2026-07-15 12:39 ` Mark Brown
2026-07-16 10:06 ` Bui Duc Phuc
0 siblings, 1 reply; 4+ messages in thread
From: Mark Brown @ 2026-07-15 12:39 UTC (permalink / raw)
To: phucduc.bui
Cc: Greg Kroah-Hartman, rafael, Danilo Krummrich, linux-kernel, driver-core
[-- Attachment #1: Type: text/plain, Size: 571 bytes --]
On Wed, Jul 15, 2026 at 12:21:00PM +0700, phucduc.bui@gmail.com wrote:
> @@ -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);
The check needs to be done under lock otherwise some other thread could
come in and put the regmap into cache only mode between the check and
when we take the lock.
We also need a similar check in regcache_sync_region().
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] regcache: Warn if regcache_sync() is called in cache_only mode
2026-07-15 12:39 ` Mark Brown
@ 2026-07-16 10:06 ` Bui Duc Phuc
2026-07-16 12:52 ` Mark Brown
0 siblings, 1 reply; 4+ messages in thread
From: Bui Duc Phuc @ 2026-07-16 10:06 UTC (permalink / raw)
To: Mark Brown
Cc: Greg Kroah-Hartman, rafael, Danilo Krummrich, linux-kernel, driver-core
Hi Mark,
Thank you for your review.
>
> The check needs to be done under lock otherwise some other thread could
> come in and put the regmap into cache only mode between the check and
> when we take the lock.
>
> We also need a similar check in regcache_sync_region().
I'll move the check under the lock for v2, and add the same check to
regcache_sync_region() as well.
On top of that, I'd like to ask about a design question:
Should regcache_sync() set map->cache_only = true again if it fails
partway through,
or should we leave it to the caller to call regcache_cache_only() themselves?
If we leave it to the caller, should we also update the function's
documentation
to make clear that after a failed sync, the state of the registers is no longer
guaranteed to match the cache, and that further register access should be
done carefully , and that calling regcache_cache_only() is recommended to
keep the device in a safe/consistent state?
Best regards,
Phuc
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] regcache: Warn if regcache_sync() is called in cache_only mode
2026-07-16 10:06 ` Bui Duc Phuc
@ 2026-07-16 12:52 ` Mark Brown
0 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2026-07-16 12:52 UTC (permalink / raw)
To: Bui Duc Phuc
Cc: Greg Kroah-Hartman, rafael, Danilo Krummrich, linux-kernel, driver-core
[-- Attachment #1: Type: text/plain, Size: 861 bytes --]
On Thu, Jul 16, 2026 at 05:06:12PM +0700, Bui Duc Phuc wrote:
> On top of that, I'd like to ask about a design question:
> Should regcache_sync() set map->cache_only = true again if it fails
> partway through,
> or should we leave it to the caller to call regcache_cache_only() themselves?
That's for the caller.
> If we leave it to the caller, should we also update the function's
> documentation
> to make clear that after a failed sync, the state of the registers is no longer
> guaranteed to match the cache, and that further register access should be
> done carefully , and that calling regcache_cache_only() is recommended to
> keep the device in a safe/consistent state?
I'd have hoped it'd be fairly obvious that the device is in an
indeterminate state after a failed sync, TBH if I/O isn't working
recovery options are going to be *super* limited.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-07-16 12:52 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-15 5:21 [PATCH] regcache: Warn if regcache_sync() is called in cache_only mode phucduc.bui
2026-07-15 12:39 ` Mark Brown
2026-07-16 10:06 ` Bui Duc Phuc
2026-07-16 12:52 ` Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome