diff options
author | Dimitris Papastamos <dp@opensource.wolfsonmicro.com> | 2013-07-31 08:28:52 -0400 |
---|---|---|
committer | Mark Brown <broonie@linaro.org> | 2013-07-31 09:50:34 -0400 |
commit | 4f8b19143d74e1c3360b21640065765a12bafb1b (patch) | |
tree | 79b6f89da72d486951f90404f62af1e2fbbf1611 /sound | |
parent | 5ae90d8e467e625e447000cb4335c4db973b1095 (diff) |
ASoC: wm0010: Fix resource leak
If kzalloc() fails for `img' then we are going to leak the memory
for `out'. We are freeing the memory of all the tx/rx transfers
but the tx/rx buf pointers will be NULL if we drop out earlier.
Signed-off-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
Diffstat (limited to 'sound')
-rw-r--r-- | sound/soc/codecs/wm0010.c | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/sound/soc/codecs/wm0010.c b/sound/soc/codecs/wm0010.c index f5e835662cdc..10adc4145d46 100644 --- a/sound/soc/codecs/wm0010.c +++ b/sound/soc/codecs/wm0010.c | |||
@@ -410,6 +410,16 @@ static int wm0010_firmware_load(const char *name, struct snd_soc_codec *codec) | |||
410 | rec->command, rec->length); | 410 | rec->command, rec->length); |
411 | len = rec->length + 8; | 411 | len = rec->length + 8; |
412 | 412 | ||
413 | xfer = kzalloc(sizeof(*xfer), GFP_KERNEL); | ||
414 | if (!xfer) { | ||
415 | dev_err(codec->dev, "Failed to allocate xfer\n"); | ||
416 | ret = -ENOMEM; | ||
417 | goto abort; | ||
418 | } | ||
419 | |||
420 | xfer->codec = codec; | ||
421 | list_add_tail(&xfer->list, &xfer_list); | ||
422 | |||
413 | out = kzalloc(len, GFP_KERNEL); | 423 | out = kzalloc(len, GFP_KERNEL); |
414 | if (!out) { | 424 | if (!out) { |
415 | dev_err(codec->dev, | 425 | dev_err(codec->dev, |
@@ -417,6 +427,7 @@ static int wm0010_firmware_load(const char *name, struct snd_soc_codec *codec) | |||
417 | ret = -ENOMEM; | 427 | ret = -ENOMEM; |
418 | goto abort1; | 428 | goto abort1; |
419 | } | 429 | } |
430 | xfer->t.rx_buf = out; | ||
420 | 431 | ||
421 | img = kzalloc(len, GFP_KERNEL); | 432 | img = kzalloc(len, GFP_KERNEL); |
422 | if (!img) { | 433 | if (!img) { |
@@ -425,24 +436,13 @@ static int wm0010_firmware_load(const char *name, struct snd_soc_codec *codec) | |||
425 | ret = -ENOMEM; | 436 | ret = -ENOMEM; |
426 | goto abort1; | 437 | goto abort1; |
427 | } | 438 | } |
439 | xfer->t.tx_buf = img; | ||
428 | 440 | ||
429 | byte_swap_64((u64 *)&rec->command, img, len); | 441 | byte_swap_64((u64 *)&rec->command, img, len); |
430 | 442 | ||
431 | xfer = kzalloc(sizeof(*xfer), GFP_KERNEL); | ||
432 | if (!xfer) { | ||
433 | dev_err(codec->dev, "Failed to allocate xfer\n"); | ||
434 | ret = -ENOMEM; | ||
435 | goto abort1; | ||
436 | } | ||
437 | |||
438 | xfer->codec = codec; | ||
439 | list_add_tail(&xfer->list, &xfer_list); | ||
440 | |||
441 | spi_message_init(&xfer->m); | 443 | spi_message_init(&xfer->m); |
442 | xfer->m.complete = wm0010_boot_xfer_complete; | 444 | xfer->m.complete = wm0010_boot_xfer_complete; |
443 | xfer->m.context = xfer; | 445 | xfer->m.context = xfer; |
444 | xfer->t.tx_buf = img; | ||
445 | xfer->t.rx_buf = out; | ||
446 | xfer->t.len = len; | 446 | xfer->t.len = len; |
447 | xfer->t.bits_per_word = 8; | 447 | xfer->t.bits_per_word = 8; |
448 | 448 | ||