regmap: validate regmap_raw_read/write val_len
Stephen Warren [Fri, 6 Apr 2012 21:16:03 +0000 (15:16 -0600)]
val_len should be a multiple of val_bytes. If it's not, error out early.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
(cherry picked from commit 851960ba7cb38a6a108d102e4c8b0ab702972e22)

Change-Id: Ic17d4bd832b5ea3e426d00ff5d0ae342b8abba45
Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Reviewed-on: http://git-master/r/96507
Reviewed-by: Simone Willett <swillett@nvidia.com>
Tested-by: Simone Willett <swillett@nvidia.com>

drivers/base/regmap/regmap.c

index 86eabd2..8388560 100644 (file)
@@ -622,6 +622,9 @@ int regmap_raw_write(struct regmap *map, unsigned int reg,
 {
        int ret;
 
+       if (val_len % map->format.val_bytes)
+               return -EINVAL;
+
        map->lock(map);
 
        ret = _regmap_raw_write(map, reg, val, val_len);
@@ -780,6 +783,9 @@ int regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
        unsigned int v;
        int ret, i;
 
+       if (val_len % map->format.val_bytes)
+               return -EINVAL;
+
        map->lock(map);
 
        if (regmap_volatile_range(map, reg, val_count) || map->cache_bypass ||