Skip to content

Commit

Permalink
regmap: Fix memory leak in regcache_hw_init error path
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Lars-Peter Clausen authored and Mark Brown committed Nov 14, 2011
1 parent abbb18f commit 021cd61
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions drivers/base/regmap/regcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ static int regcache_hw_init(struct regmap *map)

map->reg_defaults = kmalloc(count * sizeof(struct reg_default),
GFP_KERNEL);
if (!map->reg_defaults)
return -ENOMEM;
if (!map->reg_defaults) {
ret = -ENOMEM;
goto err_free;
}

/* fill the reg_defaults */
map->num_reg_defaults = count;
Expand All @@ -77,6 +79,12 @@ static int regcache_hw_init(struct regmap *map)
}

return 0;

err_free:
if (map->cache_free)
kfree(map->reg_defaults_raw);

return ret;
}

int regcache_init(struct regmap *map)
Expand Down

0 comments on commit 021cd61

Please sign in to comment.