diff options
author | Lars-Peter Clausen <lars@metafoo.de> | 2011-11-14 04:40:16 -0500 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2011-11-14 16:46:09 -0500 |
commit | 021cd616decb4e8a4b31f1f8c466a847e8c04e67 (patch) | |
tree | 94d59c03e8fd9b89148b76cf3cc18eda2ef05d87 | |
parent | abbb18fb4ad7472ee2e1351f0ca12bce64cac143 (diff) |
regmap: Fix memory leak in regcache_hw_init error path
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>
-rw-r--r-- | drivers/base/regmap/regcache.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/drivers/base/regmap/regcache.c b/drivers/base/regmap/regcache.c index 6ab9f0384d82..79446262812c 100644 --- a/drivers/base/regmap/regcache.c +++ b/drivers/base/regmap/regcache.c | |||
@@ -61,8 +61,10 @@ static int regcache_hw_init(struct regmap *map) | |||
61 | 61 | ||
62 | map->reg_defaults = kmalloc(count * sizeof(struct reg_default), | 62 | map->reg_defaults = kmalloc(count * sizeof(struct reg_default), |
63 | GFP_KERNEL); | 63 | GFP_KERNEL); |
64 | if (!map->reg_defaults) | 64 | if (!map->reg_defaults) { |
65 | return -ENOMEM; | 65 | ret = -ENOMEM; |
66 | goto err_free; | ||
67 | } | ||
66 | 68 | ||
67 | /* fill the reg_defaults */ | 69 | /* fill the reg_defaults */ |
68 | map->num_reg_defaults = count; | 70 | map->num_reg_defaults = count; |
@@ -77,6 +79,12 @@ static int regcache_hw_init(struct regmap *map) | |||
77 | } | 79 | } |
78 | 80 | ||
79 | return 0; | 81 | return 0; |
82 | |||
83 | err_free: | ||
84 | if (map->cache_free) | ||
85 | kfree(map->reg_defaults_raw); | ||
86 | |||
87 | return ret; | ||
80 | } | 88 | } |
81 | 89 | ||
82 | int regcache_init(struct regmap *map) | 90 | int regcache_init(struct regmap *map) |