regmap: Fix memory leak in regcache_init error path
Lars-Peter Clausen [Mon, 14 Nov 2011 09:40:17 +0000 (10:40 +0100)]
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>
(cherry picked from commit bd061c78cabc28bb64ed79f784d24918b6bdb791)

Change-Id: I3ece3442c4e1162e481c0c207b2add27a57a6676
Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Reviewed-on: http://git-master/r/87556

drivers/base/regmap/regcache.c

index a9ce8ae..5cbb443 100644 (file)
@@ -143,9 +143,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)