提交 bd061c78 编写于 作者: L Lars-Peter Clausen 提交者: Mark Brown

regmap: Fix memory leak in regcache_init error path

Make sure all allocated memory gets freed again in case initializing the cache
failed.
Signed-off-by: NLars-Peter Clausen <lars@metafoo.de>
Acked-by: NDimitris Papastamos <dp@opensource.wolfsonmicro.com>
Signed-off-by: NMark Brown <broonie@opensource.wolfsonmicro.com>
上级 021cd616
...@@ -144,9 +144,18 @@ int regcache_init(struct regmap *map) ...@@ -144,9 +144,18 @@ int regcache_init(struct regmap *map)
if (map->cache_ops->init) { if (map->cache_ops->init) {
dev_dbg(map->dev, "Initializing %s cache\n", dev_dbg(map->dev, "Initializing %s cache\n",
map->cache_ops->name); map->cache_ops->name);
return map->cache_ops->init(map); ret = map->cache_ops->init(map);
if (ret)
goto err_free;
} }
return 0; 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) void regcache_exit(struct regmap *map)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册