regmap: zero out the regmap on allocation
authorPratyush Yadav <p.yadav@ti.com>
Thu, 24 Sep 2020 04:34:11 +0000 (10:04 +0530)
committerTom Rini <trini@konsulko.com>
Wed, 30 Sep 2020 15:55:22 +0000 (11:55 -0400)
Some fields will be introduced in the regmap structure that should be
set to 0 by default. So, once we allocate a regmap, make sure it is
zeroed out to avoid unexpected defaults for those values.

Signed-off-by: Pratyush Yadav <p.yadav@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
drivers/core/regmap.c

index 7422536..809f584 100644 (file)
@@ -30,8 +30,9 @@ DECLARE_GLOBAL_DATA_PTR;
 static struct regmap *regmap_alloc(int count)
 {
        struct regmap *map;
+       size_t size = sizeof(*map) + sizeof(map->ranges[0]) * count;
 
-       map = malloc(sizeof(*map) + sizeof(map->ranges[0]) * count);
+       map = calloc(1, size);
        if (!map)
                return NULL;
        map->range_count = count;