The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH v3] irqchip/gic-v3-its: Drop ITS node reference on its_of_probe() errors
@ 2026-11-12 20:49 Yuho Choi
  2026-11-13 14:48 ` [tip: irq/drivers] " tip-bot2 for Yuho Choi
  0 siblings, 1 reply; 2+ messages in thread
From: Yuho Choi @ 2026-11-12 20:49 UTC (permalink / raw)
  To: Marc Zyngier, Thomas Gleixner
  Cc: Jonathan Cameron, Lorenzo Pieralisi, Radu Rendec,
	linux-arm-kernel, linux-kernel, 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.

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")
Suggested-by: Marc Zyngier <maz@kernel.org>
Signed-off-by: Yuho Choi <oss.patchbox@gmail.com>
Acked-by: Marc Zyngier <maz@kernel.org>
---
v3:
- Keep each loop's __free(device_node) declaration on one line (Marc).
- Add Marc's Acked-by.

v2: https://lore.kernel.org/r/20261103201817.1259660-2-oss.patchbox@gmail.com
- 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/20260923165447.619477-1-oss.patchbox@gmail.com

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

 drivers/irqchip/irq-gic-v3-its.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
index 282e4bafb084..ddc07cda5539 100644
--- a/drivers/irqchip/irq-gic-v3-its.c
+++ b/drivers/irqchip/irq-gic-v3-its.c
@@ -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
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [tip: irq/drivers] irqchip/gic-v3-its: Drop ITS node reference on its_of_probe() errors
  2026-11-12 20:49 [PATCH v3] irqchip/gic-v3-its: Drop ITS node reference on its_of_probe() errors Yuho Choi
@ 2026-11-13 14:48 ` tip-bot2 for Yuho Choi
  0 siblings, 0 replies; 2+ messages in thread
From: tip-bot2 for Yuho Choi @ 2026-11-13 14:48 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Marc Zyngier, Yuho Choi, Thomas Gleixner, x86, linux-kernel

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 <oss.patchbox@gmail.com>
AuthorDate:    Thu, 12 Nov 2026 15:49:37 -05:00
Committer:     Thomas Gleixner <tglx@kernel.org>
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")
Suggested-by: Marc Zyngier <maz@kernel.org>
Signed-off-by: Yuho Choi <oss.patchbox@gmail.com>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Acked-by: Marc Zyngier <maz@kernel.org>
Link: https://patch.msgid.link/20261112204944.1427733-2-oss.patchbox@gmail.com
---
 drivers/irqchip/irq-gic-v3-its.c |  9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
index 282e4ba..3cf94c2 100644
--- a/drivers/irqchip/irq-gic-v3-its.c
+++ b/drivers/irqchip/irq-gic-v3-its.c
@@ -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))

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-13 14:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-12 20:49 [PATCH v3] irqchip/gic-v3-its: Drop ITS node reference on its_of_probe() errors Yuho Choi
2026-11-13 14:48 ` [tip: irq/drivers] " tip-bot2 for Yuho Choi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox