diff mbox series

[v3,2/9] regmap: zero out the regmap on allocation

Message ID 20200924043418.5355-3-p.yadav@ti.com
State Accepted
Commit 97d8a6970a3da5856633f2a705f0687fca4af9a5
Delegated to: Tom Rini
Headers show
Series regmap: Add managed API, regmap fields, regmap config | expand

Commit Message

Pratyush Yadav Sept. 24, 2020, 4:34 a.m. UTC
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>
---

Notes:
    No changes in v3.

 drivers/core/regmap.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Tom Rini Oct. 1, 2020, 2:08 p.m. UTC | #1
On Thu, Sep 24, 2020 at 10:04:11AM +0530, Pratyush Yadav wrote:

> 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>

Applied to u-boot/next, thanks!
diff mbox series

Patch

diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c
index 74225361fd..809f58489f 100644
--- a/drivers/core/regmap.c
+++ b/drivers/core/regmap.c
@@ -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;