ALSA: emu10k1: code refactoring

Partially restructures _snd_emu10k1_audigy_init_efx() and
_snd_emu10k1_init_efx() functions.

Be noted that the cast is demanded to use '__user'. So, in these cases,
avoid patches based on the coccinelle 'drop_kmalloc_cast' semantic patch.

Signed-off-by: Geyslan G. Bem <geyslan@gmail.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
Geyslan G. Bem 2013-10-17 19:57:12 -03:00 committed by Takashi Iwai
parent a4e9a38b40
commit f1b4863a87
1 changed files with 45 additions and 31 deletions

View File

@ -1182,15 +1182,20 @@ static int _snd_emu10k1_audigy_init_efx(struct snd_emu10k1 *emu)
u32 *gpr_map; u32 *gpr_map;
mm_segment_t seg; mm_segment_t seg;
if ((icode = kzalloc(sizeof(*icode), GFP_KERNEL)) == NULL || err = -ENOMEM;
(icode->gpr_map = (u_int32_t __user *) icode = kzalloc(sizeof(*icode), GFP_KERNEL);
kcalloc(512 + 256 + 256 + 2 * 1024, sizeof(u_int32_t), if (!icode)
GFP_KERNEL)) == NULL || return err;
(controls = kcalloc(SND_EMU10K1_GPR_CONTROLS,
sizeof(*controls), GFP_KERNEL)) == NULL) { icode->gpr_map = (u_int32_t __user *) kcalloc(512 + 256 + 256 + 2 * 1024,
err = -ENOMEM; sizeof(u_int32_t), GFP_KERNEL);
goto __err; if (!icode->gpr_map)
} goto __err_gpr;
controls = kcalloc(SND_EMU10K1_GPR_CONTROLS,
sizeof(*controls), GFP_KERNEL);
if (!controls)
goto __err_ctrls;
gpr_map = (u32 __force *)icode->gpr_map; gpr_map = (u32 __force *)icode->gpr_map;
icode->tram_data_map = icode->gpr_map + 512; icode->tram_data_map = icode->gpr_map + 512;
@ -1741,12 +1746,12 @@ A_OP(icode, &ptr, iMAC0, A_GPR(var), A_GPR(var), A_GPR(vol), A_EXTIN(input))
emu->support_tlv = 0; /* clear again */ emu->support_tlv = 0; /* clear again */
snd_leave_user(seg); snd_leave_user(seg);
__err: __err:
kfree(controls); kfree(controls);
if (icode != NULL) { __err_ctrls:
kfree((void __force *)icode->gpr_map); kfree((void __force *)icode->gpr_map);
kfree(icode); __err_gpr:
} kfree(icode);
return err; return err;
} }
@ -1813,18 +1818,26 @@ static int _snd_emu10k1_init_efx(struct snd_emu10k1 *emu)
u32 *gpr_map; u32 *gpr_map;
mm_segment_t seg; mm_segment_t seg;
if ((icode = kzalloc(sizeof(*icode), GFP_KERNEL)) == NULL) err = -ENOMEM;
return -ENOMEM; icode = kzalloc(sizeof(*icode), GFP_KERNEL);
if ((icode->gpr_map = (u_int32_t __user *) if (!icode)
kcalloc(256 + 160 + 160 + 2 * 512, sizeof(u_int32_t), return err;
GFP_KERNEL)) == NULL ||
(controls = kcalloc(SND_EMU10K1_GPR_CONTROLS, icode->gpr_map = (u_int32_t __user *) kcalloc(256 + 160 + 160 + 2 * 512,
sizeof(struct snd_emu10k1_fx8010_control_gpr), sizeof(u_int32_t), GFP_KERNEL);
GFP_KERNEL)) == NULL || if (!icode->gpr_map)
(ipcm = kzalloc(sizeof(*ipcm), GFP_KERNEL)) == NULL) { goto __err_gpr;
err = -ENOMEM;
goto __err; controls = kcalloc(SND_EMU10K1_GPR_CONTROLS,
} sizeof(struct snd_emu10k1_fx8010_control_gpr),
GFP_KERNEL);
if (!controls)
goto __err_ctrls;
ipcm = kzalloc(sizeof(*ipcm), GFP_KERNEL);
if (!ipcm)
goto __err_ipcm;
gpr_map = (u32 __force *)icode->gpr_map; gpr_map = (u32 __force *)icode->gpr_map;
icode->tram_data_map = icode->gpr_map + 256; icode->tram_data_map = icode->gpr_map + 256;
@ -2363,13 +2376,14 @@ static int _snd_emu10k1_init_efx(struct snd_emu10k1 *emu)
snd_leave_user(seg); snd_leave_user(seg);
if (err >= 0) if (err >= 0)
err = snd_emu10k1_ipcm_poke(emu, ipcm); err = snd_emu10k1_ipcm_poke(emu, ipcm);
__err: __err:
kfree(ipcm); kfree(ipcm);
__err_ipcm:
kfree(controls); kfree(controls);
if (icode != NULL) { __err_ctrls:
kfree((void __force *)icode->gpr_map); kfree((void __force *)icode->gpr_map);
kfree(icode); __err_gpr:
} kfree(icode);
return err; return err;
} }