diff mbox series

[v1,5/8] ASoC: loongson: Simplify of_node_put() reference

Message ID 56a7aed94441f09ab28bb55a3e3955ce1da8f0f7.1725844530.git.zhoubinbin@loongson.cn (mailing list archive)
State New, archived
Headers show
Series ASoC: loongson: Simplify code formatting | expand

Commit Message

Binbin Zhou Sept. 9, 2024, 7:19 a.m. UTC
There are multiple references to of_node_put() in
loongson_card_parse_of(). We can merge them into one place to improve
code readability.

Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
---
 sound/soc/loongson/loongson_card.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)
diff mbox series

Patch

diff --git a/sound/soc/loongson/loongson_card.c b/sound/soc/loongson/loongson_card.c
index 3dd82caaae3b..4033cd7f09f6 100644
--- a/sound/soc/loongson/loongson_card.c
+++ b/sound/soc/loongson/loongson_card.c
@@ -114,45 +114,42 @@  static int loongson_card_parse_acpi(struct loongson_card_data *data)
 
 static int loongson_card_parse_of(struct loongson_card_data *data)
 {
-	struct device_node *cpu, *codec;
 	struct snd_soc_card *card = &data->snd_card;
+	struct device_node *cpu, *codec;
 	struct device *dev = card->dev;
-	int ret, i;
+	int ret = 0, i;
 
 	cpu = of_get_child_by_name(dev->of_node, "cpu");
 	if (!cpu) {
 		dev_err(dev, "platform property missing or invalid\n");
 		return -EINVAL;
 	}
+
 	codec = of_get_child_by_name(dev->of_node, "codec");
 	if (!codec) {
 		dev_err(dev, "audio-codec property missing or invalid\n");
-		of_node_put(cpu);
-		return -EINVAL;
+		ret = -EINVAL;
+		goto cpu_put;
 	}
 
 	for (i = 0; i < card->num_links; i++) {
 		ret = snd_soc_of_get_dlc(cpu, NULL, loongson_dai_links[i].cpus, 0);
 		if (ret < 0) {
 			dev_err(dev, "getting cpu dlc error (%d)\n", ret);
-			goto err;
+			goto codec_put;
 		}
 
 		ret = snd_soc_of_get_dlc(codec, NULL, loongson_dai_links[i].codecs, 0);
 		if (ret < 0) {
 			dev_err(dev, "getting codec dlc error (%d)\n", ret);
-			goto err;
+			goto codec_put;
 		}
 	}
 
-	of_node_put(cpu);
+codec_put:
 	of_node_put(codec);
-
-	return 0;
-
-err:
+cpu_put:
 	of_node_put(cpu);
-	of_node_put(codec);
 	return ret;
 }