diff options
author | Jesper Juhl <jj@chaosbits.net> | 2010-10-29 16:54:45 -0400 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2010-11-01 05:26:23 -0400 |
commit | bb617ee3f82ba94072c8b08043d9166bbfe397a2 (patch) | |
tree | 2ad6d51e5d84fc765a3fd35b4e73f1fc37bd1def | |
parent | 8a8d56b2a2f9aa423c3d8b6b1e2792c0492059ed (diff) |
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: Jesper Juhl <jj@chaosbits.net>
Tested-by: Ondrej Zary <linux@rainbow-software.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
-rw-r--r-- | sound/pci/cs46xx/dsp_spos.c | 33 |
1 files changed, 11 insertions, 22 deletions
diff --git a/sound/pci/cs46xx/dsp_spos.c b/sound/pci/cs46xx/dsp_spos.c index 3e5ca8fb519f..e377287192aa 100644 --- a/sound/pci/cs46xx/dsp_spos.c +++ b/sound/pci/cs46xx/dsp_spos.c | |||
@@ -225,39 +225,25 @@ struct dsp_spos_instance *cs46xx_dsp_spos_create (struct snd_cs46xx * chip) | |||
225 | { | 225 | { |
226 | struct dsp_spos_instance * ins = kzalloc(sizeof(struct dsp_spos_instance), GFP_KERNEL); | 226 | struct dsp_spos_instance * ins = kzalloc(sizeof(struct dsp_spos_instance), GFP_KERNEL); |
227 | 227 | ||
228 | if (ins == NULL) | 228 | if (ins == NULL) |
229 | return NULL; | 229 | return NULL; |
230 | 230 | ||
231 | /* better to use vmalloc for this big table */ | 231 | /* better to use vmalloc for this big table */ |
232 | ins->symbol_table.nsymbols = 0; | ||
233 | ins->symbol_table.symbols = vmalloc(sizeof(struct dsp_symbol_entry) * | 232 | ins->symbol_table.symbols = vmalloc(sizeof(struct dsp_symbol_entry) * |
234 | DSP_MAX_SYMBOLS); | 233 | DSP_MAX_SYMBOLS); |
235 | ins->symbol_table.highest_frag_index = 0; | 234 | ins->code.data = kmalloc(DSP_CODE_BYTE_SIZE, GFP_KERNEL); |
236 | 235 | ins->modules = kmalloc(sizeof(struct dsp_module_desc) * DSP_MAX_MODULES, GFP_KERNEL); | |
237 | if (ins->symbol_table.symbols == NULL) { | 236 | if (!ins->symbol_table.symbols || !ins->code.data || !ins->modules) { |
238 | cs46xx_dsp_spos_destroy(chip); | 237 | cs46xx_dsp_spos_destroy(chip); |
239 | goto error; | 238 | goto error; |
240 | } | 239 | } |
241 | 240 | ins->symbol_table.nsymbols = 0; | |
241 | ins->symbol_table.highest_frag_index = 0; | ||
242 | ins->code.offset = 0; | 242 | ins->code.offset = 0; |
243 | ins->code.size = 0; | 243 | ins->code.size = 0; |
244 | ins->code.data = kmalloc(DSP_CODE_BYTE_SIZE, GFP_KERNEL); | ||
245 | |||
246 | if (ins->code.data == NULL) { | ||
247 | cs46xx_dsp_spos_destroy(chip); | ||
248 | goto error; | ||
249 | } | ||
250 | |||
251 | ins->nscb = 0; | 244 | ins->nscb = 0; |
252 | ins->ntask = 0; | 245 | ins->ntask = 0; |
253 | |||
254 | ins->nmodules = 0; | 246 | ins->nmodules = 0; |
255 | ins->modules = kmalloc(sizeof(struct dsp_module_desc) * DSP_MAX_MODULES, GFP_KERNEL); | ||
256 | |||
257 | if (ins->modules == NULL) { | ||
258 | cs46xx_dsp_spos_destroy(chip); | ||
259 | goto error; | ||
260 | } | ||
261 | 247 | ||
262 | /* default SPDIF input sample rate | 248 | /* default SPDIF input sample rate |
263 | to 48000 khz */ | 249 | to 48000 khz */ |
@@ -271,8 +257,8 @@ struct dsp_spos_instance *cs46xx_dsp_spos_create (struct snd_cs46xx * chip) | |||
271 | 257 | ||
272 | /* set left and right validity bits and | 258 | /* set left and right validity bits and |
273 | default channel status */ | 259 | default channel status */ |
274 | ins->spdif_csuv_default = | 260 | ins->spdif_csuv_default = |
275 | ins->spdif_csuv_stream = | 261 | ins->spdif_csuv_stream = |
276 | /* byte 0 */ ((unsigned int)_wrap_all_bits( (SNDRV_PCM_DEFAULT_CON_SPDIF & 0xff)) << 24) | | 262 | /* byte 0 */ ((unsigned int)_wrap_all_bits( (SNDRV_PCM_DEFAULT_CON_SPDIF & 0xff)) << 24) | |
277 | /* byte 1 */ ((unsigned int)_wrap_all_bits( ((SNDRV_PCM_DEFAULT_CON_SPDIF >> 8) & 0xff)) << 16) | | 263 | /* byte 1 */ ((unsigned int)_wrap_all_bits( ((SNDRV_PCM_DEFAULT_CON_SPDIF >> 8) & 0xff)) << 16) | |
278 | /* byte 3 */ (unsigned int)_wrap_all_bits( (SNDRV_PCM_DEFAULT_CON_SPDIF >> 24) & 0xff) | | 264 | /* byte 3 */ (unsigned int)_wrap_all_bits( (SNDRV_PCM_DEFAULT_CON_SPDIF >> 24) & 0xff) | |
@@ -281,6 +267,9 @@ struct dsp_spos_instance *cs46xx_dsp_spos_create (struct snd_cs46xx * chip) | |||
281 | return ins; | 267 | return ins; |
282 | 268 | ||
283 | error: | 269 | error: |
270 | kfree(ins->modules); | ||
271 | kfree(ins->code.data); | ||
272 | vfree(ins->symbol_table.symbols); | ||
284 | kfree(ins); | 273 | kfree(ins); |
285 | return NULL; | 274 | return NULL; |
286 | } | 275 | } |