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

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

drivers/base/regmap/regcache.c

index dbff7a1..a9ce8ae 100644 (file)
@@ -60,8 +60,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;
@@ -76,6 +78,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)