Skip to contentSkip to conversation

irqchip/gic-v3-its: Drop ITS node reference on its_of_probe() errors

PATCH Applied Yuho Choi 3 participants 3 messages Nov 12 – Nov 17

Subsystems (2)
lore
Share & tools
lore

Yuho Choi

author
#0 lore raw

PATCH v3 1/1 irqchip/gic-v3-its: Drop ITS node reference on its_of_probe() errors

its_of_probe() walks the ITS nodes with of_find_matching_node(), which drops the reference on the previous node and returns the next one with its reference count raised. The loops are balanced when they run to the end, but the three error returns (a failed its_reset_one(), a failed its_node_init() and a failed its_probe_one()) leave with the current node still referenced.

Declare the iterator in each loop with __free(device_node), so that the reference is dropped whichever way the loop is left.

Fixes c733ebb7cb67 ("irqchip/gic-v3-its: Reset each ITS's BASERn register before probe")
Fixes 9585a495ac93 ("irqchip/gic-v3-its: Split allocation from initialisation of its_node")

---
v3:
- Keep each loop's __free(device_node) declaration on one line (Marc).
- Add Marc's Acked-by.

v2: https://lore.kernel.org/r/[email protected]
- Use __free(device_node) on the loop iterators instead of adding of_node_put() to each error return (Marc).
- Rebased on v7.4-rc1.

v1: https://lore.kernel.org/r/[email protected]

Compile-tested only (arm64 defconfig, W=1).

 drivers/irqchip/irq-gic-v3-its.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/irqchip/irq-gic-v3-its.c +2 -3
index 282e4bafb084..ddc07cda5539 100644
@@ -5572,7 +5572,6 @@ static void its_node_destroy(struct its_node *its)
 
 static int __init its_of_probe(struct device_node *node)
 {
-	struct device_node *np;
 	struct resource res;
 	int err;
 
@@ -5582,7 +5581,7 @@ static int __init its_of_probe(struct device_node *node)
 	 * reset, don't even try to go any further, as this could
 	 * result in something even worse.
 	 */
-	for (np = of_find_matching_node(node, its_device_id); np;
+	for (struct device_node *np __free(device_node) = of_find_matching_node(node, its_device_id); np;
 	     np = of_find_matching_node(np, its_device_id)) {
 		if (!of_device_is_available(np) ||
 		    !of_property_read_bool(np, "msi-controller") ||
@@ -5594,7 +5593,7 @@ static int __init its_of_probe(struct device_node *node)
 			return err;
 	}
 
-	for (np = of_find_matching_node(node, its_device_id); np;
+	for (struct device_node *np __free(device_node) = of_find_matching_node(node, its_device_id); np;
 	     np = of_find_matching_node(np, its_device_id)) {
 		struct its_node *its;
 

base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4

Signature · 1 line
2.43.0
merge bot Applied
#1 lore raw
The following commit has been merged into the irq/drivers branch of tip:

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

Commit-ID:     aab02e49f0b54a0837e58c67651c4abdad1a3208
Gitweb:        https://git.kernel.org/tip/aab02e49f0b54a0837e58c67651c4abdad1a3208
Author:        Yuho Choi <[email protected]>
AuthorDate:    Thu, 12 Nov 2026 15:49:37 -05:00
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Fri, 13 Nov 2026 15:42:23 +01:00

irqchip/gic-v3-its: Drop ITS node reference on its_of_probe() errors

its_of_probe() walks the ITS nodes with of_find_matching_node(), which drops the reference on the previous node and returns the next one with its reference count raised. The loops are balanced when they run to the end, but the three error returns (a failed its_reset_one(), a failed its_node_init() and a failed its_probe_one()) leave with the current node still referenced.

Declare the iterator in each loop with __free(device_node), so that the reference is dropped whichever way the loop is left.

Fixes c733ebb7cb67 ("irqchip/gic-v3-its: Reset each ITS's BASERn register before probe")
Fixes 9585a495ac93 ("irqchip/gic-v3-its: Split allocation from initialisation of its_node")
---
 drivers/irqchip/irq-gic-v3-its.c |  9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/irqchip/irq-gic-v3-its.c +4 -5
index 282e4ba..3cf94c2 100644
@@ -5572,7 +5572,6 @@ static void its_node_destroy(struct its_node *its)
 
 static int __init its_of_probe(struct device_node *node)
 {
-	struct device_node *np;
 	struct resource res;
 	int err;
 
@@ -5582,8 +5581,8 @@ static int __init its_of_probe(struct device_node *node)
 	 * reset, don't even try to go any further, as this could
 	 * result in something even worse.
 	 */
-	for (np = of_find_matching_node(node, its_device_id); np;
-	     np = of_find_matching_node(np, its_device_id)) {
+	for (struct device_node *np __free(device_node) = of_find_matching_node(node, its_device_id);
+	     np; np = of_find_matching_node(np, its_device_id)) {
 		if (!of_device_is_available(np) ||
 		    !of_property_read_bool(np, "msi-controller") ||
 		    of_address_to_resource(np, 0, &res))
@@ -5594,8 +5593,8 @@ static int __init its_of_probe(struct device_node *node)
 			return err;
 	}
 
-	for (np = of_find_matching_node(node, its_device_id); np;
-	     np = of_find_matching_node(np, its_device_id)) {
+	for (struct device_node *np __free(device_node) = of_find_matching_node(node, its_device_id);
+	     np; np = of_find_matching_node(np, its_device_id)) {
 		struct its_node *its;
 
 		if (!of_device_is_available(np))
#2 lore raw
In reply to Yuho Choi

Hi Yuho,

CC devicetree

Quoted 7 lines · Yuho Choi

its_of_probe() walks the ITS nodes with of_find_matching_node(), which drops the reference on the previous node and returns the next one with its reference count raised. The loops are balanced when they run to the end, but the three error returns (a failed its_reset_one(), a failed its_node_init() and a failed its_probe_one()) leave with the current node still referenced.

Quoted 8 lines

Declare the iterator in each loop with __free(device_node), so that the reference is dropped whichever way the loop is left.

Fixes c733ebb7cb67 ("irqchip/gic-v3-its: Reset each ITS's BASERn register before probe")
Fixes 9585a495ac93 ("irqchip/gic-v3-its: Split allocation from initialisation of its_node")

Thanks for your patch, which is now commit aab02e49f0b54a08 ("irqchip/gic-v3-its: Drop ITS node reference on its_of_probe() errors") in irqchip/irq/drivers.

Quoted 11 lines
drivers/irqchip/irq-gic-v3-its.c +0 -1
@@ -5572,7 +5572,6 @@ static void its_node_destroy(struct its_node *its)
 
 static int __init its_of_probe(struct device_node *node)
 {
-       struct device_node *np;
        struct resource res;
        int err;
 

drivers/irqchip/irq-gic-v3-its.c static int __init its_of_probe(struct device_node *node) · line 5585

Quoted 6 lines
drivers/irqchip/irq-gic-v3-its.c +1 -1
@@ -5582,7 +5581,7 @@ static int __init its_of_probe(struct device_node *node)
         * reset, don't even try to go any further, as this could
         * result in something even worse.
         */
-       for (np = of_find_matching_node(node, its_device_id); np;
+       for (struct device_node *np __free(device_node) = of_find_matching_node(node, its_device_id); np;
             np = of_find_matching_node(np, its_device_id)) {

So the old code was just an open-coded copy of the existing for_each_matching_node() helper.
The new code is the open-coded original for a future for_each_matching_node_scoped() helper?

drivers/irqchip/irq-gic-v3-its.c static int __init its_of_probe(struct device_node *node) · line 5597

Quoted 9 lines
drivers/irqchip/irq-gic-v3-its.c +1 -1
                if (!of_device_is_available(np) ||
                    !of_property_read_bool(np, "msi-controller") ||
@@ -5594,7 +5593,7 @@ static int __init its_of_probe(struct device_node *node)
                        return err;
        }
 
-       for (np = of_find_matching_node(node, its_device_id); np;
+       for (struct device_node *np __free(device_node) = of_find_matching_node(node, its_device_id); np;
             np = of_find_matching_node(np, its_device_id)) {

Likewise.

drivers/irqchip/irq-gic-v3-its.c static int __init its_of_probe(struct device_node *node) · line 5599

Quoted 2 lines
drivers/irqchip/irq-gic-v3-its.c +0 -0
                struct its_node *its;
 

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds