Refactor sof_card_dai_links_create() function by replacing
'sof_ends' and 'sof_dais' structure declarations as
struct asoc_sdw_endpoint *sof_ends __free(kfree) = NULL;
struct asoc_sdw_dailink *sof_dais __free(kfree) = NULL;
Use above declarations to eliminate goto statements usage.
Suggested-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
---
sound/soc/amd/acp/acp-sdw-sof-mach.c | 33 ++++++++++------------------
1 file changed, 11 insertions(+), 22 deletions(-)
diff --git a/sound/soc/amd/acp/acp-sdw-sof-mach.c b/sound/soc/amd/acp/acp-sdw-sof-mach.c
index 3be401c72270..36e6d6db90c1 100644
--- a/sound/soc/amd/acp/acp-sdw-sof-mach.c
+++ b/sound/soc/amd/acp/acp-sdw-sof-mach.c
@@ -311,9 +311,9 @@ static int sof_card_dai_links_create(struct snd_soc_card *card)
int sdw_be_num = 0, dmic_num = 0;
struct asoc_sdw_mc_private *ctx = snd_soc_card_get_drvdata(card);
struct snd_soc_acpi_mach_params *mach_params = &mach->mach_params;
+ struct asoc_sdw_endpoint *sof_ends __free(kfree) = NULL;
+ struct asoc_sdw_dailink *sof_dais __free(kfree) = NULL;
struct snd_soc_codec_conf *codec_conf;
- struct asoc_sdw_endpoint *sof_ends;
- struct asoc_sdw_dailink *sof_dais;
struct snd_soc_dai_link *dai_links;
int num_devs = 0;
int num_ends = 0;
@@ -334,14 +334,12 @@ static int sof_card_dai_links_create(struct snd_soc_card *card)
/* One per endpoint, ie. each DAI on each codec/amp */
sof_ends = kcalloc(num_ends, sizeof(*sof_ends), GFP_KERNEL);
- if (!sof_ends) {
- ret = -ENOMEM;
- goto err_dai;
- }
+ if (!sof_ends)
+ return -ENOMEM;
ret = asoc_sdw_parse_sdw_endpoints(card, sof_dais, sof_ends, &num_devs);
if (ret < 0)
- goto err_end;
+ return ret;
sdw_be_num = ret;
@@ -352,18 +350,14 @@ static int sof_card_dai_links_create(struct snd_soc_card *card)
dev_dbg(dev, "sdw %d, dmic %d", sdw_be_num, dmic_num);
codec_conf = devm_kcalloc(dev, num_devs, sizeof(*codec_conf), GFP_KERNEL);
- if (!codec_conf) {
- ret = -ENOMEM;
- goto err_end;
- }
+ if (!codec_conf)
+ return -ENOMEM;
/* allocate BE dailinks */
num_links = sdw_be_num + dmic_num;
dai_links = devm_kcalloc(dev, num_links, sizeof(*dai_links), GFP_KERNEL);
- if (!dai_links) {
- ret = -ENOMEM;
- goto err_end;
- }
+ if (!dai_links)
+ return -ENOMEM;
card->codec_conf = codec_conf;
card->num_configs = num_devs;
@@ -375,7 +369,7 @@ static int sof_card_dai_links_create(struct snd_soc_card *card)
ret = create_sdw_dailinks(card, &dai_links, &be_id,
sof_dais, &codec_conf);
if (ret)
- goto err_end;
+ return ret;
}
/* dmic */
@@ -385,18 +379,13 @@ static int sof_card_dai_links_create(struct snd_soc_card *card)
} else {
ret = create_dmic_dailinks(card, &dai_links, &be_id);
if (ret)
- goto err_end;
+ return ret;
}
}
WARN_ON(codec_conf != card->codec_conf + card->num_configs);
WARN_ON(dai_links != card->dai_link + card->num_links);
-err_end:
- kfree(sof_ends);
-err_dai:
- kfree(sof_dais);
-
return ret;
}
--
2.34.1