ALSA: oss: Release temporary buffers upon errors
When the parameter changes fails, we don't need to keep the old temporary buffers. Release those (and plugin instances) upon errors for reducing dead memory footprint. Since we always call it at the exit of snd_pcm_oss_changes_params_locked(), the explicit calls of snd_pcm_oss_plugin_clear() can be dropped, too. Along with it, unify the buffer-free calls to a single helper and call it from the needed places. Link: https://lore.kernel.org/r/20220318082157.29769-1-tiwai@suse.de Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
parent
a893b7fc7b
commit
8a580a2676
|
@ -837,6 +837,17 @@ static void unlock_params(struct snd_pcm_runtime *runtime)
|
|||
mutex_unlock(&runtime->oss.params_lock);
|
||||
}
|
||||
|
||||
static void snd_pcm_oss_release_buffers(struct snd_pcm_substream *substream)
|
||||
{
|
||||
struct snd_pcm_runtime *runtime = substream->runtime;
|
||||
|
||||
kvfree(runtime->oss.buffer);
|
||||
runtime->oss.buffer = NULL;
|
||||
#ifdef CONFIG_SND_PCM_OSS_PLUGINS
|
||||
snd_pcm_oss_plugin_clear(substream);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* call with params_lock held */
|
||||
static int snd_pcm_oss_change_params_locked(struct snd_pcm_substream *substream)
|
||||
{
|
||||
|
@ -967,12 +978,10 @@ static int snd_pcm_oss_change_params_locked(struct snd_pcm_substream *substream)
|
|||
snd_pcm_oss_plugin_clear(substream);
|
||||
if (!direct) {
|
||||
/* add necessary plugins */
|
||||
snd_pcm_oss_plugin_clear(substream);
|
||||
err = snd_pcm_plug_format_plugins(substream, params, sparams);
|
||||
if (err < 0) {
|
||||
pcm_dbg(substream->pcm,
|
||||
"snd_pcm_plug_format_plugins failed: %i\n", err);
|
||||
snd_pcm_oss_plugin_clear(substream);
|
||||
goto failure;
|
||||
}
|
||||
if (runtime->oss.plugin_first) {
|
||||
|
@ -981,7 +990,6 @@ static int snd_pcm_oss_change_params_locked(struct snd_pcm_substream *substream)
|
|||
if (err < 0) {
|
||||
pcm_dbg(substream->pcm,
|
||||
"snd_pcm_plugin_build_io failed: %i\n", err);
|
||||
snd_pcm_oss_plugin_clear(substream);
|
||||
goto failure;
|
||||
}
|
||||
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
|
||||
|
@ -989,10 +997,8 @@ static int snd_pcm_oss_change_params_locked(struct snd_pcm_substream *substream)
|
|||
} else {
|
||||
err = snd_pcm_plugin_insert(plugin);
|
||||
}
|
||||
if (err < 0) {
|
||||
snd_pcm_oss_plugin_clear(substream);
|
||||
if (err < 0)
|
||||
goto failure;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -1082,6 +1088,8 @@ static int snd_pcm_oss_change_params_locked(struct snd_pcm_substream *substream)
|
|||
|
||||
err = 0;
|
||||
failure:
|
||||
if (err)
|
||||
snd_pcm_oss_release_buffers(substream);
|
||||
kfree(sw_params);
|
||||
kfree(params);
|
||||
kfree(sparams);
|
||||
|
@ -2351,13 +2359,7 @@ static void snd_pcm_oss_look_for_setup(struct snd_pcm *pcm, int stream,
|
|||
|
||||
static void snd_pcm_oss_release_substream(struct snd_pcm_substream *substream)
|
||||
{
|
||||
struct snd_pcm_runtime *runtime;
|
||||
runtime = substream->runtime;
|
||||
kvfree(runtime->oss.buffer);
|
||||
runtime->oss.buffer = NULL;
|
||||
#ifdef CONFIG_SND_PCM_OSS_PLUGINS
|
||||
snd_pcm_oss_plugin_clear(substream);
|
||||
#endif
|
||||
snd_pcm_oss_release_buffers(substream);
|
||||
substream->oss.oss = 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue