Skip to content

Commit 522133d

Browse files
krzkbroonie
authored andcommitted
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: Krzysztof Kozlowski <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 5b3cc85 commit 522133d

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

sound/soc/soc-dapm.c

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3882,11 +3882,10 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w,
38823882
struct snd_soc_dapm_path *path;
38833883
struct snd_soc_dai *source, *sink;
38843884
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
3885-
struct snd_pcm_hw_params *params = NULL;
38863885
const struct snd_soc_pcm_stream *config = NULL;
38873886
struct snd_pcm_runtime *runtime = NULL;
38883887
unsigned int fmt;
3889-
int ret = 0;
3888+
int ret;
38903889

38913890
/*
38923891
* NOTE
@@ -3897,15 +3896,14 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w,
38973896
* stuff that increases stack usage.
38983897
* So, we use kzalloc()/kfree() for params in this function.
38993898
*/
3900-
params = kzalloc(sizeof(*params), GFP_KERNEL);
3899+
struct snd_pcm_hw_params *params __free(kfree) = kzalloc(sizeof(*params),
3900+
GFP_KERNEL);
39013901
if (!params)
39023902
return -ENOMEM;
39033903

39043904
runtime = kzalloc(sizeof(*runtime), GFP_KERNEL);
3905-
if (!runtime) {
3906-
ret = -ENOMEM;
3907-
goto out;
3908-
}
3905+
if (!runtime)
3906+
return -ENOMEM;
39093907

39103908
substream->runtime = runtime;
39113909

@@ -3915,7 +3913,7 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w,
39153913

39163914
ret = snd_soc_dai_startup(source, substream);
39173915
if (ret < 0)
3918-
goto out;
3916+
return ret;
39193917

39203918
snd_soc_dai_activate(source, substream->stream);
39213919
}
@@ -3926,7 +3924,7 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w,
39263924

39273925
ret = snd_soc_dai_startup(sink, substream);
39283926
if (ret < 0)
3929-
goto out;
3927+
return ret;
39303928

39313929
snd_soc_dai_activate(sink, substream->stream);
39323930
}
@@ -3941,16 +3939,14 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w,
39413939
config = rtd->dai_link->c2c_params + rtd->c2c_params_select;
39423940
if (!config) {
39433941
dev_err(w->dapm->dev, "ASoC: link config missing\n");
3944-
ret = -EINVAL;
3945-
goto out;
3942+
return -EINVAL;
39463943
}
39473944

39483945
/* Be a little careful as we don't want to overflow the mask array */
39493946
if (!config->formats) {
39503947
dev_warn(w->dapm->dev, "ASoC: Invalid format was specified\n");
39513948

3952-
ret = -EINVAL;
3953-
goto out;
3949+
return -EINVAL;
39543950
}
39553951

39563952
fmt = ffs(config->formats) - 1;
@@ -3971,7 +3967,7 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w,
39713967

39723968
ret = snd_soc_dai_hw_params(source, substream, params);
39733969
if (ret < 0)
3974-
goto out;
3970+
return ret;
39753971

39763972
dapm_update_dai_unlocked(substream, params, source);
39773973
}
@@ -3982,7 +3978,7 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w,
39823978

39833979
ret = snd_soc_dai_hw_params(sink, substream, params);
39843980
if (ret < 0)
3985-
goto out;
3981+
return ret;
39863982

39873983
dapm_update_dai_unlocked(substream, params, sink);
39883984
}
@@ -3992,11 +3988,7 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w,
39923988
runtime->channels = params_channels(params);
39933989
runtime->rate = params_rate(params);
39943990

3995-
out:
3996-
/* see above NOTE */
3997-
kfree(params);
3998-
3999-
return ret;
3991+
return 0;
40003992
}
40013993

40023994
static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w,

0 commit comments

Comments
 (0)