Skip to content

Commit

Permalink
regmap: Fix memory leak in regcache_init error path
Browse files Browse the repository at this point in the history
Make sure all allocated memory gets freed again in case initializing the cache
failed.

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 021cd61 commit bd061c7
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion drivers/base/regmap/regcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,18 @@ int regcache_init(struct regmap *map)
if (map->cache_ops->init) {
dev_dbg(map->dev, "Initializing %s cache\n",
map->cache_ops->name);
return map->cache_ops->init(map);
ret = map->cache_ops->init(map);
if (ret)
goto err_free;
}
return 0;

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

return ret;
}

void regcache_exit(struct regmap *map)
Expand Down

0 comments on commit bd061c7

Please sign in to comment.