Commit 522133d4 authored by Krzysztof Kozlowski's avatar Krzysztof Kozlowski Committed by Mark Brown

ASoC: dapm: Simplify snd_soc_dai_link_event_pre_pmu() with cleanup.h

Allocate the memory with scoped/cleanup.h in
snd_soc_dai_link_event_pre_pmu() to reduce error handling (less error
paths) and make the code a bit simpler.
Signed-off-by: default avatarKrzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Link: https://patch.msgid.link/20240703-asoc-cleanup-h-v1-11-71219dfd0aef@linaro.orgSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 5b3cc856
...@@ -3882,11 +3882,10 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w, ...@@ -3882,11 +3882,10 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w,
struct snd_soc_dapm_path *path; struct snd_soc_dapm_path *path;
struct snd_soc_dai *source, *sink; struct snd_soc_dai *source, *sink;
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
struct snd_pcm_hw_params *params = NULL;
const struct snd_soc_pcm_stream *config = NULL; const struct snd_soc_pcm_stream *config = NULL;
struct snd_pcm_runtime *runtime = NULL; struct snd_pcm_runtime *runtime = NULL;
unsigned int fmt; unsigned int fmt;
int ret = 0; int ret;
/* /*
* NOTE * NOTE
...@@ -3897,15 +3896,14 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w, ...@@ -3897,15 +3896,14 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w,
* stuff that increases stack usage. * stuff that increases stack usage.
* So, we use kzalloc()/kfree() for params in this function. * So, we use kzalloc()/kfree() for params in this function.
*/ */
params = kzalloc(sizeof(*params), GFP_KERNEL); struct snd_pcm_hw_params *params __free(kfree) = kzalloc(sizeof(*params),
GFP_KERNEL);
if (!params) if (!params)
return -ENOMEM; return -ENOMEM;
runtime = kzalloc(sizeof(*runtime), GFP_KERNEL); runtime = kzalloc(sizeof(*runtime), GFP_KERNEL);
if (!runtime) { if (!runtime)
ret = -ENOMEM; return -ENOMEM;
goto out;
}
substream->runtime = runtime; substream->runtime = runtime;
...@@ -3915,7 +3913,7 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w, ...@@ -3915,7 +3913,7 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w,
ret = snd_soc_dai_startup(source, substream); ret = snd_soc_dai_startup(source, substream);
if (ret < 0) if (ret < 0)
goto out; return ret;
snd_soc_dai_activate(source, substream->stream); snd_soc_dai_activate(source, substream->stream);
} }
...@@ -3926,7 +3924,7 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w, ...@@ -3926,7 +3924,7 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w,
ret = snd_soc_dai_startup(sink, substream); ret = snd_soc_dai_startup(sink, substream);
if (ret < 0) if (ret < 0)
goto out; return ret;
snd_soc_dai_activate(sink, substream->stream); snd_soc_dai_activate(sink, substream->stream);
} }
...@@ -3941,16 +3939,14 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w, ...@@ -3941,16 +3939,14 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w,
config = rtd->dai_link->c2c_params + rtd->c2c_params_select; config = rtd->dai_link->c2c_params + rtd->c2c_params_select;
if (!config) { if (!config) {
dev_err(w->dapm->dev, "ASoC: link config missing\n"); dev_err(w->dapm->dev, "ASoC: link config missing\n");
ret = -EINVAL; return -EINVAL;
goto out;
} }
/* Be a little careful as we don't want to overflow the mask array */ /* Be a little careful as we don't want to overflow the mask array */
if (!config->formats) { if (!config->formats) {
dev_warn(w->dapm->dev, "ASoC: Invalid format was specified\n"); dev_warn(w->dapm->dev, "ASoC: Invalid format was specified\n");
ret = -EINVAL; return -EINVAL;
goto out;
} }
fmt = ffs(config->formats) - 1; fmt = ffs(config->formats) - 1;
...@@ -3971,7 +3967,7 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w, ...@@ -3971,7 +3967,7 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w,
ret = snd_soc_dai_hw_params(source, substream, params); ret = snd_soc_dai_hw_params(source, substream, params);
if (ret < 0) if (ret < 0)
goto out; return ret;
dapm_update_dai_unlocked(substream, params, source); dapm_update_dai_unlocked(substream, params, source);
} }
...@@ -3982,7 +3978,7 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w, ...@@ -3982,7 +3978,7 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w,
ret = snd_soc_dai_hw_params(sink, substream, params); ret = snd_soc_dai_hw_params(sink, substream, params);
if (ret < 0) if (ret < 0)
goto out; return ret;
dapm_update_dai_unlocked(substream, params, sink); dapm_update_dai_unlocked(substream, params, sink);
} }
...@@ -3992,11 +3988,7 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w, ...@@ -3992,11 +3988,7 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w,
runtime->channels = params_channels(params); runtime->channels = params_channels(params);
runtime->rate = params_rate(params); runtime->rate = params_rate(params);
out: return 0;
/* see above NOTE */
kfree(params);
return ret;
} }
static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w, static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w,
......
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