diff options
author | Pankaj Bharadiya <pankaj.laxminarayan.bharadiya@intel.com> | 2017-11-07 05:46:19 -0500 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2017-11-08 13:56:17 -0500 |
commit | f8e066521192c7debe59127d90abbe2773577e25 (patch) | |
tree | 79da77ad491a4409cba52d2a023c15cf840e0ad1 | |
parent | 0265ddd7b713bd8b68a9ec451761bcb87bbac4b3 (diff) |
ASoC: Intel: Skylake: Fix uuid_module memory leak in failure case
In the loop that adds the uuid_module to the uuid_list list, allocated
memory is not properly freed in the error path free uuid_list whenever
any of the memory allocation in the loop fails to avoid memory leak.
Signed-off-by: Pankaj Bharadiya <pankaj.laxminarayan.bharadiya@intel.com>
Signed-off-by: Guneshwor Singh <guneshwor.o.singh@intel.com>
Acked-By: Vinod Koul <vinod.koul@intel.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r-- | sound/soc/intel/skylake/skl-sst-utils.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/sound/soc/intel/skylake/skl-sst-utils.c b/sound/soc/intel/skylake/skl-sst-utils.c index 369ef7ce981c..8ff89280d9fd 100644 --- a/sound/soc/intel/skylake/skl-sst-utils.c +++ b/sound/soc/intel/skylake/skl-sst-utils.c | |||
@@ -251,6 +251,7 @@ int snd_skl_parse_uuids(struct sst_dsp *ctx, const struct firmware *fw, | |||
251 | struct uuid_module *module; | 251 | struct uuid_module *module; |
252 | struct firmware stripped_fw; | 252 | struct firmware stripped_fw; |
253 | unsigned int safe_file; | 253 | unsigned int safe_file; |
254 | int ret = 0; | ||
254 | 255 | ||
255 | /* Get the FW pointer to derive ADSP header */ | 256 | /* Get the FW pointer to derive ADSP header */ |
256 | stripped_fw.data = fw->data; | 257 | stripped_fw.data = fw->data; |
@@ -299,8 +300,10 @@ int snd_skl_parse_uuids(struct sst_dsp *ctx, const struct firmware *fw, | |||
299 | 300 | ||
300 | for (i = 0; i < num_entry; i++, mod_entry++) { | 301 | for (i = 0; i < num_entry; i++, mod_entry++) { |
301 | module = kzalloc(sizeof(*module), GFP_KERNEL); | 302 | module = kzalloc(sizeof(*module), GFP_KERNEL); |
302 | if (!module) | 303 | if (!module) { |
303 | return -ENOMEM; | 304 | ret = -ENOMEM; |
305 | goto free_uuid_list; | ||
306 | } | ||
304 | 307 | ||
305 | uuid_bin = (uuid_le *)mod_entry->uuid.id; | 308 | uuid_bin = (uuid_le *)mod_entry->uuid.id; |
306 | memcpy(&module->uuid, uuid_bin, sizeof(module->uuid)); | 309 | memcpy(&module->uuid, uuid_bin, sizeof(module->uuid)); |
@@ -311,8 +314,8 @@ int snd_skl_parse_uuids(struct sst_dsp *ctx, const struct firmware *fw, | |||
311 | size = sizeof(int) * mod_entry->instance_max_count; | 314 | size = sizeof(int) * mod_entry->instance_max_count; |
312 | module->instance_id = devm_kzalloc(ctx->dev, size, GFP_KERNEL); | 315 | module->instance_id = devm_kzalloc(ctx->dev, size, GFP_KERNEL); |
313 | if (!module->instance_id) { | 316 | if (!module->instance_id) { |
314 | kfree(module); | 317 | ret = -ENOMEM; |
315 | return -ENOMEM; | 318 | goto free_uuid_list; |
316 | } | 319 | } |
317 | 320 | ||
318 | list_add_tail(&module->list, &skl->uuid_list); | 321 | list_add_tail(&module->list, &skl->uuid_list); |
@@ -323,6 +326,10 @@ int snd_skl_parse_uuids(struct sst_dsp *ctx, const struct firmware *fw, | |||
323 | } | 326 | } |
324 | 327 | ||
325 | return 0; | 328 | return 0; |
329 | |||
330 | free_uuid_list: | ||
331 | skl_freeup_uuid_list(skl); | ||
332 | return ret; | ||
326 | } | 333 | } |
327 | 334 | ||
328 | void skl_freeup_uuid_list(struct skl_sst *ctx) | 335 | void skl_freeup_uuid_list(struct skl_sst *ctx) |