]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ASoC: dapm: Simplify snd_soc_dai_link_event_pre_pmu() with cleanup.h
authorKrzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Wed, 3 Jul 2024 12:11:05 +0000 (14:11 +0200)
committerMark Brown <broonie@kernel.org>
Mon, 8 Jul 2024 11:50:03 +0000 (12:50 +0100)
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 <krzysztof.kozlowski@linaro.org>
Link: https://patch.msgid.link/20240703-asoc-cleanup-h-v1-11-71219dfd0aef@linaro.org
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/soc-dapm.c

index 4b322bb634b64d985e2e5fe393e11c081ccbf3df..37dccd9c1ba01fb77bfa8518b68b18f0db417bd1 100644 (file)
@@ -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_dai *source, *sink;
        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;
        struct snd_pcm_runtime *runtime = NULL;
        unsigned int fmt;
-       int ret = 0;
+       int ret;
 
        /*
         * NOTE
@@ -3897,15 +3896,14 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w,
         * stuff that increases stack usage.
         * 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)
                return -ENOMEM;
 
        runtime = kzalloc(sizeof(*runtime), GFP_KERNEL);
-       if (!runtime) {
-               ret = -ENOMEM;
-               goto out;
-       }
+       if (!runtime)
+               return -ENOMEM;
 
        substream->runtime = runtime;
 
@@ -3915,7 +3913,7 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w,
 
                ret = snd_soc_dai_startup(source, substream);
                if (ret < 0)
-                       goto out;
+                       return ret;
 
                snd_soc_dai_activate(source, substream->stream);
        }
@@ -3926,7 +3924,7 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w,
 
                ret = snd_soc_dai_startup(sink, substream);
                if (ret < 0)
-                       goto out;
+                       return ret;
 
                snd_soc_dai_activate(sink, substream->stream);
        }
@@ -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;
        if (!config) {
                dev_err(w->dapm->dev, "ASoC: link config missing\n");
-               ret = -EINVAL;
-               goto out;
+               return -EINVAL;
        }
 
        /* Be a little careful as we don't want to overflow the mask array */
        if (!config->formats) {
                dev_warn(w->dapm->dev, "ASoC: Invalid format was specified\n");
 
-               ret = -EINVAL;
-               goto out;
+               return -EINVAL;
        }
 
        fmt = ffs(config->formats) - 1;
@@ -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);
                if (ret < 0)
-                       goto out;
+                       return ret;
 
                dapm_update_dai_unlocked(substream, params, source);
        }
@@ -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);
                if (ret < 0)
-                       goto out;
+                       return ret;
 
                dapm_update_dai_unlocked(substream, params, sink);
        }
@@ -3992,11 +3988,7 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w,
        runtime->channels = params_channels(params);
        runtime->rate = params_rate(params);
 
-out:
-       /* see above NOTE */
-       kfree(params);
-
-       return ret;
+       return 0;
 }
 
 static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w,