Skip to contentSkip to conversation

irqchip/mbigen: Simplify code logic with for_each_child_of_node_scoped()

PATCH Applied Zhang Zekun 2 participants 2 messages Aug 8, 2024 irqchip drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 irqchip/mbigen: Simplify code logic with for_each_child_of_node_scoped()

for_each_child_of_node_scoped() can put the device_node automaticlly. So, using it to make the code logic more simple and remove the device_node clean up code.

---
 drivers/irqchip/irq-mbigen.c | 24 +++++++-----------------
 1 file changed, 7 insertions(+), 17 deletions(-)
drivers/irqchip/irq-mbigen.c +7 -17
index 53cc08387588..6f69f4e5dbac 100644
@@ -234,37 +234,27 @@ static int mbigen_of_create_domain(struct platform_device *pdev,
 				   struct mbigen_device *mgn_chip)
 {
 	struct platform_device *child;
-	struct device_node *np;
 	u32 num_pins;
-	int ret = 0;
 
-	for_each_child_of_node(pdev->dev.of_node, np) {
+	for_each_child_of_node_scoped(pdev->dev.of_node, np) {
 		if (!of_property_read_bool(np, "interrupt-controller"))
 			continue;
 
 		child = of_platform_device_create(np, NULL, NULL);
-		if (!child) {
-			ret = -ENOMEM;
-			break;
-		}
+		if (!child)
+			return -ENOMEM;
 
 		if (of_property_read_u32(child->dev.of_node, "num-pins",
 					 &num_pins) < 0) {
 			dev_err(&pdev->dev, "No num-pins property\n");
-			ret = -EINVAL;
-			break;
+			return -EINVAL;
 		}
 
-		if (!mbigen_create_device_domain(&child->dev, num_pins, mgn_chip)) {
-			ret = -ENOMEM;
-			break;
-		}
+		if (!mbigen_create_device_domain(&child->dev, num_pins, mgn_chip))
+			return -ENOMEM;
 	}
 
-	if (ret)
-		of_node_put(np);
-
-	return ret;
+	return 0;
 }
 
 #ifdef CONFIG_ACPI
Signature · 1 line
2.17.1
merge bot Applied
#1 lore raw
The following commit has been merged into the irq/core branch of tip:

The following commit has been merged into the irq/core branch of tip:

Commit-ID:     76bee035c6add05841addc3f31b41cd726b912c4
Gitweb:        https://git.kernel.org/tip/76bee035c6add05841addc3f31b41cd726b912c4
Author:        Zhang Zekun <[email protected]>
AuthorDate:    Thu, 08 Aug 2024 11:15:52 +08:00
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Thu, 08 Aug 2024 17:15:01 +02:00

irqchip/mbigen: Simplify code logic with for_each_child_of_node_scoped()

for_each_child_of_node_scoped() handles the device_node automaticlly, so switching over to it removes the device node cleanups and allows to return directly from the loop.

---
 drivers/irqchip/irq-mbigen.c | 24 +++++++-----------------
 1 file changed, 7 insertions(+), 17 deletions(-)
drivers/irqchip/irq-mbigen.c +7 -17
index 093fd42..1291983 100644
@@ -222,37 +222,27 @@ static int mbigen_of_create_domain(struct platform_device *pdev,
 				   struct mbigen_device *mgn_chip)
 {
 	struct platform_device *child;
-	struct device_node *np;
 	u32 num_pins;
-	int ret = 0;
 
-	for_each_child_of_node(pdev->dev.of_node, np) {
+	for_each_child_of_node_scoped(pdev->dev.of_node, np) {
 		if (!of_property_read_bool(np, "interrupt-controller"))
 			continue;
 
 		child = of_platform_device_create(np, NULL, NULL);
-		if (!child) {
-			ret = -ENOMEM;
-			break;
-		}
+		if (!child)
+			return -ENOMEM;
 
 		if (of_property_read_u32(child->dev.of_node, "num-pins",
 					 &num_pins) < 0) {
 			dev_err(&pdev->dev, "No num-pins property\n");
-			ret = -EINVAL;
-			break;
+			return -EINVAL;
 		}
 
-		if (!mbigen_create_device_domain(&child->dev, num_pins, mgn_chip)) {
-			ret = -ENOMEM;
-			break;
-		}
+		if (!mbigen_create_device_domain(&child->dev, num_pins, mgn_chip))
+			return -ENOMEM;
 	}
 
-	if (ret)
-		of_node_put(np);
-
-	return ret;
+	return 0;
 }
 
 #ifdef CONFIG_ACPI