irqchip/gic-v3-its: Fix OF node reference leak
Subsystems (2)
PATCH 1/1 irqchip/gic-v3-its: Fix OF node reference leak
of_get_cpu_node() returns a referenced device node. In its_cpu_init_collection(), the node is only used to get the CPU NUMA node for the Cavium 23144 workaround, but the reference is never dropped.
Store the NUMA node locally and call of_node_put() before either continuing with collection setup or returning early for a NUMA mismatch.
--- drivers/irqchip/irq-gic-v3-its.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/irqchip/irq-gic-v3-its.c +5 -1
@@ -3291,10 +3291,14 @@ static void its_cpu_init_collection(struct its_node *its)/* avoid cross node collections and its mapping */ if (its->flags &ITS_FLAGS_WORKAROUND_CAVIUM_23144 ) {struct device_node *cpu_node; +int cpu_nid; cpu_node =of_get_cpu_node (cpu,NULL ); + cpu_nid =of_node_to_nid (cpu_node); +of_node_put (cpu_node); +if (its->numa_node !=NUMA_NO_NODE && - its->numa_node !=of_node_to_nid (cpu_node)) + its->numa_node != cpu_nid)return ; }
Signature · 1 line
2.43.0
Marc Zyngier
maintainerQuoted 25 lines · Yuho Choi
of_get_cpu_node()returns a referenced device node. Inits_cpu_init_collection(), the node is only used to get the CPU NUMA node for the Cavium 23144 workaround, but the reference is never dropped.Store the NUMA node locally and call
of_node_put()before either continuing with collection setup or returning early for a NUMA mismatch.Fixes 920181ce8469 ("irqchip/gic-v3-its: Add ability to resend MAPC on resume")Signed-off-by Yuho Choi <[email protected]>--- drivers/irqchip/irq-gic-v3-its.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/irqchip/irq-gic-v3-its.c +1
-0@@ -3291,10 +3291,14 @@ static void its_cpu_init_collection(struct its_node *its)/* avoid cross node collections and its mapping */ if (its->flags &ITS_FLAGS_WORKAROUND_CAVIUM_23144 ) {struct device_node *cpu_node; +int cpu_nid;
drivers/irqchip/irq-gic-v3-its.c static void its_cpu_init_collection(struct its_node *its) · line 3304
Quoted 10 lines
drivers/irqchip/irq-gic-v3-its.c +4
-1cpu_node =of_get_cpu_node (cpu,NULL ); + cpu_nid =of_node_to_nid (cpu_node); +of_node_put (cpu_node); +if (its->numa_node !=NUMA_NO_NODE && - its->numa_node !=of_node_to_nid (cpu_node)) + its->numa_node != cpu_nid)return ; }
Please consider using the cleanup infrastructure instead, something like the untested hack below.
Thanks,
M.
drivers/irqchip/irq-gic-v3-its.c +2 -3
@@ -3290,11 +3290,10 @@ static void its_cpu_init_collection(struct its_node *its)/* avoid cross node collections and its mapping */ if (its->flags &ITS_FLAGS_WORKAROUND_CAVIUM_23144 ) { -struct device_node *cpu_node; + struct device_node *cpu_node __free(device_node) = of_get_cpu_node(cpu, NULL); - cpu_node =of_get_cpu_node (cpu,NULL );if (its->numa_node !=NUMA_NO_NODE && - its->numa_node !=of_node_to_nid (cpu_node)) + its->numa_node !=of_node_to_nid (cpu_node))return ; }
Signature · 1 line
Jazz isn't dead. It just smells funny.
Zenghui Yu
Reviewed-byQuoted 8 lines · Marc Zyngier
Quoted 6 lines · Yuho Choi
of_get_cpu_node()returns a referenced device node. Inits_cpu_init_collection(), the node is only used to get the CPU NUMA node for the Cavium 23144 workaround, but the reference is never dropped.
Quoted 4 lines
Quoted 4 lines
Store the NUMA node locally and call
of_node_put()before either continuing with collection setup or returning early for a NUMA mismatch.Fixes 920181ce8469 ("irqchip/gic-v3-its: Add ability to resend MAPC on resume")
It looks to me that this issue was introduced in fbf8f40e1658 ("irqchip/gicv3-its: numa: Enable workaround for Cavium thunderx erratum 23144"). What am I missing?
Quoted 37 lines
Quoted 15 lines
Signed-off-by Yuho Choi <[email protected]>--- drivers/irqchip/irq-gic-v3-its.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/irqchip/irq-gic-v3-its.c +1
-0@@ -3291,10 +3291,14 @@ static void its_cpu_init_collection(struct its_node *its)/* avoid cross node collections and its mapping */ if (its->flags &ITS_FLAGS_WORKAROUND_CAVIUM_23144 ) {struct device_node *cpu_node; +int cpu_nid;drivers/irqchip/irq-gic-v3-its.c static void its_cpu_init_collection(struct its_node *its) · line 3304
Quoted 10 lines
drivers/irqchip/irq-gic-v3-its.c +4
-1cpu_node =of_get_cpu_node (cpu,NULL ); + cpu_nid =of_node_to_nid (cpu_node); +of_node_put (cpu_node); +if (its->numa_node !=NUMA_NO_NODE && - its->numa_node !=of_node_to_nid (cpu_node)) + its->numa_node != cpu_nid)return ; }Please consider using the cleanup infrastructure instead, something like the untested hack below.
drivers/irqchip/irq-gic-v3-its.c +0
-0@@ -3290,11 +3290,10 @@ static void its_cpu_init_collection(struct its_node *its)/* avoid cross node collections and its mapping */ if (its->flags &ITS_FLAGS_WORKAROUND_CAVIUM_23144 ) {
drivers/irqchip/irq-gic-v3-its.c static void its_cpu_init_collection(struct its_node *its) · line 3299
Quoted 10 lines
drivers/irqchip/irq-gic-v3-its.c +2
-3-struct device_node *cpu_node; + struct device_node *cpu_node __free(device_node) = of_get_cpu_node(cpu, NULL); - cpu_node =of_get_cpu_node (cpu,NULL );if (its->numa_node !=NUMA_NO_NODE && - its->numa_node !=of_node_to_nid (cpu_node)) + its->numa_node !=of_node_to_nid (cpu_node))return ; }
Thanks,
Zenghui
Thanks for the review!
Quoted 4 lines
It looks to me that this issue was introduced in
fbf8f40e1658("irqchip/gicv3-its: numa: Enable workaround for Cavium thunderx erratum 23144"). What am I missing?
You are right; I used the wrong Fixes tag. I will update the fix commit in v2.
Quoted 2 lines
Quoted 2 lines
Please consider using the cleanup infrastructure instead, something like the untested hack below.
Sure, I'll update this in v2 and resend it.
Thanks,
Yuho