Skip to content

Commit

Permalink
regmap: cache: Fix num_reg_defaults computation from reg_defaults_raw
Browse files Browse the repository at this point in the history
In 3245d46 (regmap: cache: Fall back to register by register read for
cache defaults) non-readable registers are skipped when initializing
reg_defaults, but are still included in num_reg_defaults. So there can
be uninitialized entries at the end of reg_defaults, which can cause
problems when the register cache initializes from the full array.

Fixed it by excluding non-readable registers from the count as well.

Signed-off-by: Maarten ter Huurne <maarten@treewalker.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
  • Loading branch information
Maarten ter Huurne authored and Mark Brown committed Jul 29, 2016
1 parent efeb1a3 commit b2c7f5d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions drivers/base/regmap/regcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ static int regcache_hw_init(struct regmap *map)

/* calculate the size of reg_defaults */
for (count = 0, i = 0; i < map->num_reg_defaults_raw; i++)
if (!regmap_volatile(map, i * map->reg_stride))
if (regmap_readable(map, i * map->reg_stride) &&
!regmap_volatile(map, i * map->reg_stride))
count++;

/* all registers are volatile, so just bypass */
/* all registers are unreadable or volatile, so just bypass */
if (!count) {
map->cache_bypass = true;
return 0;
Expand Down

0 comments on commit b2c7f5d

Please sign in to comment.