[PATCH 3/7] regmap: Properly round cache_word_size

From: Lars-Peter Clausen
Date: Wed Nov 16 2011 - 10:29:30 EST


regcache currently only properly works with val sizes of 8 or 16. For all other
val sizes it will round them down to the next multiple of 8, which will cause
the cache to be too small. This patch fixes it by rounding the cache_word_size
up to the nearest storage size.

Signed-off-by: Lars-Peter Clausen <lars@xxxxxxxxxx>
---
drivers/base/regmap/regcache.c | 11 +++++++++--
1 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/base/regmap/regcache.c b/drivers/base/regmap/regcache.c
index d687df6..6f0dbc0 100644
--- a/drivers/base/regmap/regcache.c
+++ b/drivers/base/regmap/regcache.c
@@ -111,8 +111,15 @@ int regcache_init(struct regmap *map, const struct regmap_config *config)
map->num_reg_defaults = config->num_reg_defaults;
map->num_reg_defaults_raw = config->num_reg_defaults_raw;
map->reg_defaults_raw = config->reg_defaults_raw;
- map->cache_size_raw = (config->val_bits / 8) * config->num_reg_defaults_raw;
- map->cache_word_size = config->val_bits / 8;
+
+ if (config->val_bits <= 8)
+ map->cache_word_size = 1;
+ else if (config->val_bits <= 16)
+ map->cache_word_size = 2;
+ else
+ return -EINVAL;
+
+ map->cache_size_raw = map->cache_word_size * config->num_reg_defaults_raw;

map->cache = NULL;
map->cache_ops = cache_types[i];
--
1.7.7.1


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/