Commit a55bc334 authored by Takashi Iwai's avatar Takashi Iwai

ALSA: pcm_oss: ump: Use automatic cleanup of kfree()

There are common patterns where a temporary buffer is allocated and
freed at the exit, and those can be simplified with the recent cleanup
mechanism via __free(kfree).

No functional changes, only code refactoring.
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
Link: https://lore.kernel.org/r/20240223084241.3361-5-tiwai@suse.de
parent 6c40eec5
...@@ -377,7 +377,7 @@ static int snd_pcm_hw_param_near(struct snd_pcm_substream *pcm, ...@@ -377,7 +377,7 @@ static int snd_pcm_hw_param_near(struct snd_pcm_substream *pcm,
snd_pcm_hw_param_t var, unsigned int best, snd_pcm_hw_param_t var, unsigned int best,
int *dir) int *dir)
{ {
struct snd_pcm_hw_params *save = NULL; struct snd_pcm_hw_params *save __free(kfree) = NULL;
int v; int v;
unsigned int saved_min; unsigned int saved_min;
int last = 0; int last = 0;
...@@ -404,38 +404,30 @@ static int snd_pcm_hw_param_near(struct snd_pcm_substream *pcm, ...@@ -404,38 +404,30 @@ static int snd_pcm_hw_param_near(struct snd_pcm_substream *pcm,
saved_min = min; saved_min = min;
min = snd_pcm_hw_param_min(pcm, params, var, min, &mindir); min = snd_pcm_hw_param_min(pcm, params, var, min, &mindir);
if (min >= 0) { if (min >= 0) {
struct snd_pcm_hw_params *params1; struct snd_pcm_hw_params *params1 __free(kfree) = NULL;
if (max < 0) if (max < 0)
goto _end; goto _end;
if ((unsigned int)min == saved_min && mindir == valdir) if ((unsigned int)min == saved_min && mindir == valdir)
goto _end; goto _end;
params1 = kmalloc(sizeof(*params1), GFP_KERNEL); params1 = kmalloc(sizeof(*params1), GFP_KERNEL);
if (params1 == NULL) { if (params1 == NULL)
kfree(save);
return -ENOMEM; return -ENOMEM;
}
*params1 = *save; *params1 = *save;
max = snd_pcm_hw_param_max(pcm, params1, var, max, &maxdir); max = snd_pcm_hw_param_max(pcm, params1, var, max, &maxdir);
if (max < 0) { if (max < 0)
kfree(params1);
goto _end; goto _end;
}
if (boundary_nearer(max, maxdir, best, valdir, min, mindir)) { if (boundary_nearer(max, maxdir, best, valdir, min, mindir)) {
*params = *params1; *params = *params1;
last = 1; last = 1;
} }
kfree(params1);
} else { } else {
*params = *save; *params = *save;
max = snd_pcm_hw_param_max(pcm, params, var, max, &maxdir); max = snd_pcm_hw_param_max(pcm, params, var, max, &maxdir);
if (max < 0) { if (max < 0)
kfree(save);
return max; return max;
}
last = 1; last = 1;
} }
_end: _end:
kfree(save);
if (last) if (last)
v = snd_pcm_hw_param_last(pcm, params, var, dir); v = snd_pcm_hw_param_last(pcm, params, var, dir);
else else
...@@ -789,7 +781,7 @@ static int choose_rate(struct snd_pcm_substream *substream, ...@@ -789,7 +781,7 @@ static int choose_rate(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params, unsigned int best_rate) struct snd_pcm_hw_params *params, unsigned int best_rate)
{ {
const struct snd_interval *it; const struct snd_interval *it;
struct snd_pcm_hw_params *save; struct snd_pcm_hw_params *save __free(kfree) = NULL;
unsigned int rate, prev; unsigned int rate, prev;
save = kmalloc(sizeof(*save), GFP_KERNEL); save = kmalloc(sizeof(*save), GFP_KERNEL);
...@@ -808,10 +800,8 @@ static int choose_rate(struct snd_pcm_substream *substream, ...@@ -808,10 +800,8 @@ static int choose_rate(struct snd_pcm_substream *substream,
ret = snd_pcm_hw_param_set(substream, params, ret = snd_pcm_hw_param_set(substream, params,
SNDRV_PCM_HW_PARAM_RATE, SNDRV_PCM_HW_PARAM_RATE,
rate, 0); rate, 0);
if (ret == (int)rate) { if (ret == (int)rate)
kfree(save);
return rate; return rate;
}
*params = *save; *params = *save;
} }
prev = rate; prev = rate;
...@@ -821,7 +811,6 @@ static int choose_rate(struct snd_pcm_substream *substream, ...@@ -821,7 +811,6 @@ static int choose_rate(struct snd_pcm_substream *substream,
} }
/* not found, use the nearest rate */ /* not found, use the nearest rate */
kfree(save);
return snd_pcm_hw_param_near(substream, params, SNDRV_PCM_HW_PARAM_RATE, best_rate, NULL); return snd_pcm_hw_param_near(substream, params, SNDRV_PCM_HW_PARAM_RATE, best_rate, NULL);
} }
...@@ -1847,7 +1836,7 @@ static int snd_pcm_oss_get_formats(struct snd_pcm_oss_file *pcm_oss_file) ...@@ -1847,7 +1836,7 @@ static int snd_pcm_oss_get_formats(struct snd_pcm_oss_file *pcm_oss_file)
struct snd_pcm_substream *substream; struct snd_pcm_substream *substream;
int err; int err;
int direct; int direct;
struct snd_pcm_hw_params *params; struct snd_pcm_hw_params *params __free(kfree) = NULL;
unsigned int formats = 0; unsigned int formats = 0;
const struct snd_mask *format_mask; const struct snd_mask *format_mask;
int fmt; int fmt;
...@@ -1873,7 +1862,7 @@ static int snd_pcm_oss_get_formats(struct snd_pcm_oss_file *pcm_oss_file) ...@@ -1873,7 +1862,7 @@ static int snd_pcm_oss_get_formats(struct snd_pcm_oss_file *pcm_oss_file)
_snd_pcm_hw_params_any(params); _snd_pcm_hw_params_any(params);
err = snd_pcm_hw_refine(substream, params); err = snd_pcm_hw_refine(substream, params);
if (err < 0) if (err < 0)
goto error; return err;
format_mask = hw_param_mask_c(params, SNDRV_PCM_HW_PARAM_FORMAT); format_mask = hw_param_mask_c(params, SNDRV_PCM_HW_PARAM_FORMAT);
for (fmt = 0; fmt < 32; ++fmt) { for (fmt = 0; fmt < 32; ++fmt) {
if (snd_mask_test(format_mask, fmt)) { if (snd_mask_test(format_mask, fmt)) {
...@@ -1883,9 +1872,7 @@ static int snd_pcm_oss_get_formats(struct snd_pcm_oss_file *pcm_oss_file) ...@@ -1883,9 +1872,7 @@ static int snd_pcm_oss_get_formats(struct snd_pcm_oss_file *pcm_oss_file)
} }
} }
error: return formats;
kfree(params);
return err < 0 ? err : formats;
} }
static int snd_pcm_oss_set_format(struct snd_pcm_oss_file *pcm_oss_file, int format) static int snd_pcm_oss_set_format(struct snd_pcm_oss_file *pcm_oss_file, int format)
......
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