Commit bb617ee3 authored by Jesper Juhl's avatar Jesper Juhl Committed by Takashi Iwai

ALSA: cs46xx memory management fixes for cs46xx_dsp_spos_create()

When reading through sound/pci/cs46xx/dsp_spos.c I noticed a couple of
things in cs46xx_dsp_spos_create().

It seems to me that we don't always free the various memory buffers we
allocate and we also do some work (structure member assignment) early,
that is completely pointless if some of the memory allocations fail and
we end up just aborting the whole thing.

I don't have hardware to test, so the patch below is compile tested only,
but it makes the following changes:

- Make sure we always free all allocated memory on failures.
- Don't do pointless work assigning to structure members before we know
  all memory allocations, that may abort progress, have completed
  successfully.
- Remove some trailing whitespace.
Signed-off-by: default avatarJesper Juhl <jj@chaosbits.net>
Tested-by: default avatarOndrej Zary <linux@rainbow-software.org>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 8a8d56b2
......@@ -229,35 +229,21 @@ struct dsp_spos_instance *cs46xx_dsp_spos_create (struct snd_cs46xx * chip)
return NULL;
/* better to use vmalloc for this big table */
ins->symbol_table.nsymbols = 0;
ins->symbol_table.symbols = vmalloc(sizeof(struct dsp_symbol_entry) *
DSP_MAX_SYMBOLS);
ins->symbol_table.highest_frag_index = 0;
if (ins->symbol_table.symbols == NULL) {
ins->code.data = kmalloc(DSP_CODE_BYTE_SIZE, GFP_KERNEL);
ins->modules = kmalloc(sizeof(struct dsp_module_desc) * DSP_MAX_MODULES, GFP_KERNEL);
if (!ins->symbol_table.symbols || !ins->code.data || !ins->modules) {
cs46xx_dsp_spos_destroy(chip);
goto error;
}
ins->symbol_table.nsymbols = 0;
ins->symbol_table.highest_frag_index = 0;
ins->code.offset = 0;
ins->code.size = 0;
ins->code.data = kmalloc(DSP_CODE_BYTE_SIZE, GFP_KERNEL);
if (ins->code.data == NULL) {
cs46xx_dsp_spos_destroy(chip);
goto error;
}
ins->nscb = 0;
ins->ntask = 0;
ins->nmodules = 0;
ins->modules = kmalloc(sizeof(struct dsp_module_desc) * DSP_MAX_MODULES, GFP_KERNEL);
if (ins->modules == NULL) {
cs46xx_dsp_spos_destroy(chip);
goto error;
}
/* default SPDIF input sample rate
to 48000 khz */
......@@ -281,6 +267,9 @@ struct dsp_spos_instance *cs46xx_dsp_spos_create (struct snd_cs46xx * chip)
return ins;
error:
kfree(ins->modules);
kfree(ins->code.data);
vfree(ins->symbol_table.symbols);
kfree(ins);
return NULL;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment