Skip to content

Commit

Permalink
ASoC: wm0010: Fix resource leak
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Mark Brown <[email protected]>
  • Loading branch information
Dimitris Papastamos authored and broonie committed Jul 31, 2013
1 parent 5ae90d8 commit 4f8b191
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions sound/soc/codecs/wm0010.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,13 +410,24 @@ static int wm0010_firmware_load(const char *name, struct snd_soc_codec *codec)
rec->command, rec->length);
len = rec->length + 8;

xfer = kzalloc(sizeof(*xfer), GFP_KERNEL);
if (!xfer) {
dev_err(codec->dev, "Failed to allocate xfer\n");
ret = -ENOMEM;
goto abort;
}

xfer->codec = codec;
list_add_tail(&xfer->list, &xfer_list);

out = kzalloc(len, GFP_KERNEL);
if (!out) {
dev_err(codec->dev,
"Failed to allocate RX buffer\n");
ret = -ENOMEM;
goto abort1;
}
xfer->t.rx_buf = out;

img = kzalloc(len, GFP_KERNEL);
if (!img) {
Expand All @@ -425,24 +436,13 @@ static int wm0010_firmware_load(const char *name, struct snd_soc_codec *codec)
ret = -ENOMEM;
goto abort1;
}
xfer->t.tx_buf = img;

byte_swap_64((u64 *)&rec->command, img, len);

xfer = kzalloc(sizeof(*xfer), GFP_KERNEL);
if (!xfer) {
dev_err(codec->dev, "Failed to allocate xfer\n");
ret = -ENOMEM;
goto abort1;
}

xfer->codec = codec;
list_add_tail(&xfer->list, &xfer_list);

spi_message_init(&xfer->m);
xfer->m.complete = wm0010_boot_xfer_complete;
xfer->m.context = xfer;
xfer->t.tx_buf = img;
xfer->t.rx_buf = out;
xfer->t.len = len;
xfer->t.bits_per_word = 8;

Expand Down

0 comments on commit 4f8b191

Please sign in to comment.