diff mbox series

ASoC: simple-card: Use scoped of_node_put() to simplify code logic

Message ID 20240822115831.20000-1-zhangzekun11@huawei.com (mailing list archive)
State New, archived
Headers show
Series ASoC: simple-card: Use scoped of_node_put() to simplify code logic | expand

Commit Message

zhangzekun (A) Aug. 22, 2024, 11:58 a.m. UTC
Use scope based of_node_put() to simplify the code logic, and we don't
need to call of_node_put(). This can simplify code logic a bit.

Signed-off-by: Zhang Zekun <zhangzekun11@huawei.com>
---
 sound/soc/generic/simple-card.c | 28 +++++++++-------------------
 1 file changed, 9 insertions(+), 19 deletions(-)
diff mbox series

Patch

diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c
index d2588f1ea54e..60a09ee5b159 100644
--- a/sound/soc/generic/simple-card.c
+++ b/sound/soc/generic/simple-card.c
@@ -375,8 +375,8 @@  static int __simple_for_each_link(struct simple_util_priv *priv,
 {
 	struct device *dev = simple_priv_to_dev(priv);
 	struct device_node *top = dev->of_node;
-	struct device_node *node;
-	struct device_node *add_devs;
+	struct device_node *node __free(device_node) = NULL;
+	struct device_node *add_devs __free(device_node) = NULL;
 	uintptr_t dpcm_selectable = (uintptr_t)of_device_get_match_data(dev);
 	bool is_top = 0;
 	int ret = 0;
@@ -393,9 +393,8 @@  static int __simple_for_each_link(struct simple_util_priv *priv,
 	/* loop for all dai-link */
 	do {
 		struct simple_util_data adata;
-		struct device_node *codec;
-		struct device_node *plat;
-		struct device_node *np;
+		struct device_node *codec __free(device_node) = NULL;
+		struct device_node *plat __free(device_node) = NULL;
 		int num = of_get_child_count(node);
 
 		/* Skip additional-devs node */
@@ -409,7 +408,7 @@  static int __simple_for_each_link(struct simple_util_priv *priv,
 					     PREFIX "codec" : "codec");
 		if (!codec) {
 			ret = -ENODEV;
-			goto error;
+			return ret;
 		}
 		/* get platform */
 		plat = of_get_child_by_name(node, is_top ?
@@ -417,14 +416,14 @@  static int __simple_for_each_link(struct simple_util_priv *priv,
 
 		/* get convert-xxx property */
 		memset(&adata, 0, sizeof(adata));
-		for_each_child_of_node(node, np) {
+		for_each_child_of_node_scoped(node, np) {
 			if (np == add_devs)
 				continue;
 			simple_parse_convert(dev, np, &adata);
 		}
 
 		/* loop for all CPU/Codec node */
-		for_each_child_of_node(node, np) {
+		for_each_child_of_node_scoped(node, np) {
 			if (plat == np || add_devs == np)
 				continue;
 			/*
@@ -454,22 +453,13 @@  static int __simple_for_each_link(struct simple_util_priv *priv,
 					ret = func_noml(priv, np, codec, li, is_top);
 			}
 
-			if (ret < 0) {
-				of_node_put(codec);
-				of_node_put(plat);
-				of_node_put(np);
-				goto error;
-			}
+			if (ret < 0)
+				return ret;
 		}
 
-		of_node_put(codec);
-		of_node_put(plat);
 		node = of_get_next_child(top, node);
 	} while (!is_top && node);
 
- error:
-	of_node_put(add_devs);
-	of_node_put(node);
 	return ret;
 }