From patchwork Wed May 27 12:52:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pratyush Yadav X-Patchwork-Id: 246685 List-Id: U-Boot discussion From: p.yadav at ti.com (Pratyush Yadav) Date: Wed, 27 May 2020 18:22:02 +0530 Subject: [PATCH 2/8] regmap: zero out the regmap on allocation In-Reply-To: <20200527125208.24881-1-p.yadav@ti.com> References: <20200527125208.24881-1-p.yadav@ti.com> Message-ID: <20200527125208.24881-3-p.yadav@ti.com> 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 Reviewed-by: Simon Glass --- drivers/core/regmap.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c index 74225361fd..24651fb3ec 100644 --- a/drivers/core/regmap.c +++ b/drivers/core/regmap.c @@ -30,10 +30,12 @@ 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 = malloc(size); if (!map) return NULL; + memset(map, 0, size); map->range_count = count; return map;