regmap: cache: Do not panic for REGCACHE_NONE regmap
Subsystems (2)
PATCH 1/2 regmap: cache: Do not panic for REGCACHE_NONE regmap
Most regcache operations do check for REGCACHE_NONE, before ensuring doing BUG_ON(!map->cache_ops). The missing regcache_sync* functions panic on REGCACHE_NONE regmaps instead. Add an early return for non-cached ones.
--- drivers/base/regmap/regcache.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/base/regmap/regcache.c +6 -0
@@ -349,6 +349,9 @@ int regcache_sync(struct regmap *map)const char *name;bool bypass; +if (map->cache_type ==REGCACHE_NONE ) +return 0 ; +BUG_ON (!map->cache_ops); map->lock (map->lock_arg);
@@ -418,6 +421,9 @@ int regcache_sync_region(struct regmap *map, unsigned int min,const char *name;bool bypass; +if (map->cache_type ==REGCACHE_NONE ) +return 0 ; +BUG_ON (!map->cache_ops); map->lock (map->lock_arg);
Signature · 1 line
2.34.1
PATCH 2/2 regmap: cache: Fix return value
checkpatch.pl warned:
WARNING: ENOSYS means 'invalid syscall nr' and nothing else Align the return value to regcache_drop_region().
---
This warning popped up while initially returning ENOSYS in patch 1.
But I'm wondering if returning 0 for regcache_write is correct or not. This might be a follow-up patch though.
drivers/base/regmap/regcache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/regmap/regcache.c +1 -1
@@ -242,7 +242,7 @@ int regcache_read(struct regmap *map,int ret;if (map->cache_type ==REGCACHE_NONE ) -return -ENOSYS ; +return -EINVAL ;BUG_ON (!map->cache_ops);
Signature · 1 line
2.34.1
Mark Brown
maintainerQuoted 4 lines · Alexander Stein
Most regcache operations do check for
REGCACHE_NONE, before ensuring doingBUG_ON(!map->cache_ops). The missing regcache_sync* functions panic onREGCACHE_NONEregmaps instead. Add an early return for non-cached ones.
Why would we be trying to do a regcache_sync() on a device with no cache?
Hi Mark,
Am Freitag, 10. März 2023, 14:02:13 CET schrieb Mark Brown:
Quoted 10 lines
* PGP Signed by an unknown key
Quoted 4 lines · Alexander Stein
Most regcache operations do check for
REGCACHE_NONE, before ensuring doingBUG_ON(!map->cache_ops). The missing regcache_sync* functions panic onREGCACHE_NONEregmaps instead. Add an early return for non-cached ones.Why would we be trying to do a
regcache_sync()on a device with no cache?
Indeed, that makes no sense. That's indicating a bug in a driver, but why do we need to panic the kernel in this case?
On the other hand the same question applies to other regcache related functions currently checking for non-cached maps. There is no common behaviour:
panic:
* regcache_sync
* regcache_sync_region
returning -EINVAL:
* regcache_drop_region
returning -ENOSYS:
* regcache_read
returning success (0):
* regcache_write
early return (void return value):
* regcache_exit
Given all these possibilities I have no idea what's the right thing to do.
Best regards,
Alexander
Signature · 4 lines
TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany Amtsgericht München, HRB 105018 Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider http://www.tq-group.com/
Mark Brown
maintainerQuoted 7 lines · Alexander Stein
Am Freitag, 10. März 2023, 14:02:13 CET schrieb Mark Brown:
Quoted 2 lines
Why would we be trying to do a
regcache_sync()on a device with no cache?Indeed, that makes no sense. That's indicating a bug in a driver, but why do we need to panic the kernel in this case?
You're trying to change this to silently ignore the call which isn't going to make anything happy.
Quoted 7 lines
On the other hand the same question applies to other regcache related functions currently checking for non-cached maps. There is no common behaviour:
panic:
*regcache_sync
*regcache_sync_region
These are only ever triggered from a client driver, nothing in regmap will ever sync the regmap without being explicitly asked to.
Quoted 8 lines
returning
-ENOSYS:
*regcache_readreturning success (0):
*regcache_writeearly return (void return value):
*regcache_exit
These are all called transparently as part of the regmap core regardless of if there is a cache, users never directly read or write values to the cache.