Archived
14
0
Fork 0

regmap: Fix memory leak in regcache_hw_init error path

Make sure reg_defaults_raw gets freed in case of an error.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Acked-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
This commit is contained in:
Lars-Peter Clausen 2011-11-14 10:40:16 +01:00 committed by Mark Brown
parent abbb18fb4a
commit 021cd616de

View file

@ -61,8 +61,10 @@ static int regcache_hw_init(struct regmap *map)
map->reg_defaults = kmalloc(count * sizeof(struct reg_default), map->reg_defaults = kmalloc(count * sizeof(struct reg_default),
GFP_KERNEL); GFP_KERNEL);
if (!map->reg_defaults) if (!map->reg_defaults) {
return -ENOMEM; ret = -ENOMEM;
goto err_free;
}
/* fill the reg_defaults */ /* fill the reg_defaults */
map->num_reg_defaults = count; map->num_reg_defaults = count;
@ -77,6 +79,12 @@ static int regcache_hw_init(struct regmap *map)
} }
return 0; return 0;
err_free:
if (map->cache_free)
kfree(map->reg_defaults_raw);
return ret;
} }
int regcache_init(struct regmap *map) int regcache_init(struct regmap *map)