[PATCH] regmap: Check for register readability before checking cache during read
From: Mark Brown
Date: Tue Jun 13 2023 - 16:07:29 EST
Ensure that we don't return a spurious cache hit for unreadable registers
(eg, with the flat cache which doesn't understand sparseness) by checking
for readability before we do a cache lookup.
Signed-off-by: Mark Brown <broonie@xxxxxxxxxx>
---
drivers/base/regmap/regmap.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index fa2d3fba6ac9..3efbe59ca1a7 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -2897,6 +2897,9 @@ static int _regmap_read(struct regmap *map, unsigned int reg,
int ret;
void *context = _regmap_map_get_context(map);
+ if (!regmap_readable(map, reg))
+ return -EIO;
+
if (!map->cache_bypass) {
ret = regcache_read(map, reg, val);
if (ret == 0)
@@ -2906,9 +2909,6 @@ static int _regmap_read(struct regmap *map, unsigned int reg,
if (map->cache_only)
return -EBUSY;
- if (!regmap_readable(map, reg))
- return -EIO;
-
ret = map->reg_read(context, reg, val);
if (ret == 0) {
if (regmap_should_log(map))
---
base-commit: 858fd168a95c5b9669aac8db6c14a9aeab446375
change-id: 20230613-b4-regmap-check-readability-before-cache-9f658338a5c1
Best regards,
--
Mark Brown <broonie@xxxxxxxxxx>