Skip to contentSkip to conversation

irqchip: Fix some refcount leaks

PATCH Applied Miaoqian Lin 2 participants 13 messages Jun 1, 2022 – Jun 9, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover irqchip: Fix some refcount leaks

The following patchset fix some refcount leak bugs in irqchip. The cause of the bugs are missing post handling of some APIs ——of_find_node_by_phandle(),of_find_matching_node_and_match(), of_get_child_by_name().
These APIs returns node pointer with refcount incremented. and should use of_node_put() to release it when not needed anymore.

I've sent patch#1 and patch#2 separately before, I move them into one series for better management. the content of them don't change.

related link:
1. patch#1: https://lore.kernel.org/r/[email protected]/
2. patch#2: https://lore.kernel.org/r/[email protected]/

Miaoqian Lin (6):
irqchip/gic/realview: Fix refcount leak in realview_gic_of_init irqchip/apple-aic: Fix refcount leak in build_fiq_affinity irqchip/apple-aic: Fix refcount leak in aic_of_ic_init irqchip/gic-v3: Fix error handling in gic_populate_ppi_partitions irqchip/gic-v3: Fix refcount leak in gic_populate_ppi_partitions irqchip/realtek-rtl: Fix refcount leak in map_interrupts

 drivers/irqchip/irq-apple-aic.c    | 2 ++
 drivers/irqchip/irq-gic-realview.c | 1 +
 drivers/irqchip/irq-gic-v3.c       | 7 +++++--
 drivers/irqchip/irq-realtek-rtl.c  | 2 +-
 4 files changed, 9 insertions(+), 3 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/6 irqchip/gic/realview: Fix refcount leak in realview_gic_of_init

of_find_matching_node_and_match() returns a node pointer with refcount incremented, we should use of_node_put() on it when not need anymore. Add missing of_node_put() to avoid refcount leak.

Fixes 82b0a434b436 ("irqchip/gic/realview: Support more RealView DCC variants")
---
 drivers/irqchip/irq-gic-realview.c | 1 +
 1 file changed, 1 insertion(+)
drivers/irqchip/irq-gic-realview.c +1 -0
index b4c1924f0255..38fab02ffe9d 100644
@@ -57,6 +57,7 @@ realview_gic_of_init(struct device_node *node, struct device_node *parent)
 
 	/* The PB11MPCore GIC needs to be configured in the syscon */
 	map = syscon_node_to_regmap(np);
+	of_node_put(np);
 	if (!IS_ERR(map)) {
 		/* new irq mode with no DCC */
 		regmap_write(map, REALVIEW_SYS_LOCK_OFFSET,
Signature · 1 line
2.25.1
#2 lore raw

[irqchip: irq/irqchip-fixes] irqchip/gic/realview: Fix refcount leak in realview_gic_of_init

The following commit has been merged into the irq/irqchip-fixes branch of irqchip:

The following commit has been merged into the irq/irqchip-fixes branch of irqchip:

Commit-ID:     f4b98e314888cc51486421bcf6d52852452ea48b
Gitweb:        https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms/f4b98e314888cc51486421bcf6d52852452ea48b
Author:        Miaoqian Lin <[email protected]>
AuthorDate:    Wed, 01 Jun 2022 12:09:25 +04:00
Committer:     Marc Zyngier <[email protected]>
CommitterDate: Thu, 09 Jun 2022 17:36:57 +01:00

irqchip/gic/realview: Fix refcount leak in realview_gic_of_init

of_find_matching_node_and_match() returns a node pointer with refcount incremented, we should use of_node_put() on it when not need anymore. Add missing of_node_put() to avoid refcount leak.

Fixes 82b0a434b436 ("irqchip/gic/realview: Support more RealView DCC variants")
---
 drivers/irqchip/irq-gic-realview.c | 1 +
 1 file changed, 1 insertion(+)
drivers/irqchip/irq-gic-realview.c +1 -0
index b4c1924..38fab02 100644
@@ -57,6 +57,7 @@ realview_gic_of_init(struct device_node *node, struct device_node *parent)
 
 	/* The PB11MPCore GIC needs to be configured in the syscon */
 	map = syscon_node_to_regmap(np);
+	of_node_put(np);
 	if (!IS_ERR(map)) {
 		/* new irq mode with no DCC */
 		regmap_write(map, REALVIEW_SYS_LOCK_OFFSET,
#3 lore raw

PATCH 2/6 irqchip/apple-aic: Fix refcount leak in build_fiq_affinity

In reply to Miaoqian Lin

of_find_node_by_phandle() returns a node pointer with refcount incremented, we should use of_node_put() on it when not need anymore. Add missing of_node_put() to avoid refcount leak.

Fixes a5e8801202b3 ("irqchip/apple-aic: Parse FIQ affinities from device-tree")
---
 drivers/irqchip/irq-apple-aic.c | 1 +
 1 file changed, 1 insertion(+)
drivers/irqchip/irq-apple-aic.c +1 -0
index 12dd48727a15..478d0af16d9f 100644
@@ -1035,6 +1035,7 @@ static void build_fiq_affinity(struct aic_irq_chip *ic, struct device_node *aff)
 			continue;
 
 		cpu = of_cpu_node_to_id(cpu_node);
+		of_node_put(cpu_node);
 		if (WARN_ON(cpu < 0))
 			continue;
 
Signature · 1 line
2.25.1
#4 lore raw

[irqchip: irq/irqchip-fixes] irqchip/apple-aic: Fix refcount leak in build_fiq_affinity

The following commit has been merged into the irq/irqchip-fixes branch of irqchip:

The following commit has been merged into the irq/irqchip-fixes branch of irqchip:

Commit-ID:     b1ac803f47cb1615468f35cf1ccb553c52087301
Gitweb:        https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms/b1ac803f47cb1615468f35cf1ccb553c52087301
Author:        Miaoqian Lin <[email protected]>
AuthorDate:    Wed, 01 Jun 2022 12:09:26 +04:00
Committer:     Marc Zyngier <[email protected]>
CommitterDate: Thu, 09 Jun 2022 17:36:57 +01:00

irqchip/apple-aic: Fix refcount leak in build_fiq_affinity

of_find_node_by_phandle() returns a node pointer with refcount incremented, we should use of_node_put() on it when not need anymore. Add missing of_node_put() to avoid refcount leak.

Fixes a5e8801202b3 ("irqchip/apple-aic: Parse FIQ affinities from device-tree")
---
 drivers/irqchip/irq-apple-aic.c | 1 +
 1 file changed, 1 insertion(+)
drivers/irqchip/irq-apple-aic.c +1 -0
index 12dd487..478d0af 100644
@@ -1035,6 +1035,7 @@ static void build_fiq_affinity(struct aic_irq_chip *ic, struct device_node *aff)
 			continue;
 
 		cpu = of_cpu_node_to_id(cpu_node);
+		of_node_put(cpu_node);
 		if (WARN_ON(cpu < 0))
 			continue;
 
#5 lore raw

PATCH 3/6 irqchip/apple-aic: Fix refcount leak in aic_of_ic_init

In reply to Miaoqian Lin

of_get_child_by_name() returns a node pointer with refcount incremented, we should use of_node_put() on it when not need anymore. Add missing of_node_put() to avoid refcount leak.

Fixes a5e8801202b3 ("irqchip/apple-aic: Parse FIQ affinities from device-tree")
---
 drivers/irqchip/irq-apple-aic.c | 1 +
 1 file changed, 1 insertion(+)
drivers/irqchip/irq-apple-aic.c +1 -0
index 478d0af16d9f..5ac83185ff47 100644
@@ -1144,6 +1144,7 @@ static int __init aic_of_ic_init(struct device_node *node, struct device_node *p
 		for_each_child_of_node(affs, chld)
 			build_fiq_affinity(irqc, chld);
 	}
+	of_node_put(affs);
 
 	set_handle_irq(aic_handle_irq);
 	set_handle_fiq(aic_handle_fiq);
Signature · 1 line
2.25.1
#6 lore raw

[irqchip: irq/irqchip-fixes] irqchip/apple-aic: Fix refcount leak in aic_of_ic_init

The following commit has been merged into the irq/irqchip-fixes branch of irqchip:

The following commit has been merged into the irq/irqchip-fixes branch of irqchip:

Commit-ID:     3d45670fab3c25a7452721e4588cc95c51cda134
Gitweb:        https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms/3d45670fab3c25a7452721e4588cc95c51cda134
Author:        Miaoqian Lin <[email protected]>
AuthorDate:    Wed, 01 Jun 2022 12:09:27 +04:00
Committer:     Marc Zyngier <[email protected]>
CommitterDate: Thu, 09 Jun 2022 17:36:57 +01:00

irqchip/apple-aic: Fix refcount leak in aic_of_ic_init

of_get_child_by_name() returns a node pointer with refcount incremented, we should use of_node_put() on it when not need anymore. Add missing of_node_put() to avoid refcount leak.

Fixes a5e8801202b3 ("irqchip/apple-aic: Parse FIQ affinities from device-tree")
---
 drivers/irqchip/irq-apple-aic.c | 1 +
 1 file changed, 1 insertion(+)
drivers/irqchip/irq-apple-aic.c +1 -0
index 478d0af..5ac8318 100644
@@ -1144,6 +1144,7 @@ static int __init aic_of_ic_init(struct device_node *node, struct device_node *p
 		for_each_child_of_node(affs, chld)
 			build_fiq_affinity(irqc, chld);
 	}
+	of_node_put(affs);
 
 	set_handle_irq(aic_handle_irq);
 	set_handle_fiq(aic_handle_fiq);
#7 lore raw

PATCH 4/6 irqchip/gic-v3: Fix error handling in gic_populate_ppi_partitions

In reply to Miaoqian Lin

of_get_child_by_name() returns a node pointer with refcount incremented, we should use of_node_put() on it when not need anymore. When kcalloc fails, it missing of_node_put() and results in refcount leak. Fix this by goto out_put_node label.

Fixes 52085d3f2028 ("irqchip/gic-v3: Dynamically allocate PPI partition descriptors")
---
 drivers/irqchip/irq-gic-v3.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/irqchip/irq-gic-v3.c +1 -1
index 2be8dea6b6b0..1d5b4755a27e 100644
@@ -1932,7 +1932,7 @@ static void __init gic_populate_ppi_partitions(struct device_node *gic_node)
 
 	gic_data.ppi_descs = kcalloc(gic_data.ppi_nr, sizeof(*gic_data.ppi_descs), GFP_KERNEL);
 	if (!gic_data.ppi_descs)
-		return;
+		goto out_put_node;
 
 	nr_parts = of_get_child_count(parts_node);
 
Signature · 1 line
2.25.1
#8 lore raw

[irqchip: irq/irqchip-fixes] irqchip/gic-v3: Fix error handling in gic_populate_ppi_partitions

The following commit has been merged into the irq/irqchip-fixes branch of irqchip:

The following commit has been merged into the irq/irqchip-fixes branch of irqchip:

Commit-ID:     ec8401a429ffee34ccf38cebf3443f8d5ae6cb0d
Gitweb:        https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms/ec8401a429ffee34ccf38cebf3443f8d5ae6cb0d
Author:        Miaoqian Lin <[email protected]>
AuthorDate:    Wed, 01 Jun 2022 12:09:28 +04:00
Committer:     Marc Zyngier <[email protected]>
CommitterDate: Thu, 09 Jun 2022 17:36:57 +01:00

irqchip/gic-v3: Fix error handling in gic_populate_ppi_partitions

of_get_child_by_name() returns a node pointer with refcount incremented, we should use of_node_put() on it when not need anymore. When kcalloc fails, it missing of_node_put() and results in refcount leak. Fix this by goto out_put_node label.

Fixes 52085d3f2028 ("irqchip/gic-v3: Dynamically allocate PPI partition descriptors")
---
 drivers/irqchip/irq-gic-v3.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/irqchip/irq-gic-v3.c +1 -1
index 2be8dea..1d5b475 100644
@@ -1932,7 +1932,7 @@ static void __init gic_populate_ppi_partitions(struct device_node *gic_node)
 
 	gic_data.ppi_descs = kcalloc(gic_data.ppi_nr, sizeof(*gic_data.ppi_descs), GFP_KERNEL);
 	if (!gic_data.ppi_descs)
-		return;
+		goto out_put_node;
 
 	nr_parts = of_get_child_count(parts_node);
 
#9 lore raw

PATCH 5/6 irqchip/gic-v3: Fix refcount leak in gic_populate_ppi_partitions

In reply to Miaoqian Lin

of_find_node_by_phandle() returns a node pointer with refcount incremented, we should use of_node_put() on it when not need anymore. Add missing of_node_put() to avoid refcount leak.

Fixes e3825ba1af3a ("irqchip/gic-v3: Add support for partitioned PPIs")
---
 drivers/irqchip/irq-gic-v3.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/irqchip/irq-gic-v3.c +4 -1
index 1d5b4755a27e..5c1cf907ee68 100644
@@ -1973,12 +1973,15 @@ static void __init gic_populate_ppi_partitions(struct device_node *gic_node)
 				continue;
 
 			cpu = of_cpu_node_to_id(cpu_node);
-			if (WARN_ON(cpu < 0))
+			if (WARN_ON(cpu < 0)) {
+				of_node_put(cpu_node);
 				continue;
+			}
 
 			pr_cont("%pOF[%d] ", cpu_node, cpu);
 
 			cpumask_set_cpu(cpu, &part->mask);
+			of_node_put(cpu_node);
 		}
 
 		pr_cont("}\n");
Signature · 1 line
2.25.1
#10 lore raw

[irqchip: irq/irqchip-fixes] irqchip/gic-v3: Fix refcount leak in gic_populate_ppi_partitions

The following commit has been merged into the irq/irqchip-fixes branch of irqchip:

The following commit has been merged into the irq/irqchip-fixes branch of irqchip:

Commit-ID:     fa1ad9d4cc47ca2470cd904ad4519f05d7e43a2b
Gitweb:        https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms/fa1ad9d4cc47ca2470cd904ad4519f05d7e43a2b
Author:        Miaoqian Lin <[email protected]>
AuthorDate:    Wed, 01 Jun 2022 12:09:29 +04:00
Committer:     Marc Zyngier <[email protected]>
CommitterDate: Thu, 09 Jun 2022 17:36:57 +01:00

irqchip/gic-v3: Fix refcount leak in gic_populate_ppi_partitions

of_find_node_by_phandle() returns a node pointer with refcount incremented, we should use of_node_put() on it when not need anymore. Add missing of_node_put() to avoid refcount leak.

Fixes e3825ba1af3a ("irqchip/gic-v3: Add support for partitioned PPIs")
---
 drivers/irqchip/irq-gic-v3.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/irqchip/irq-gic-v3.c +4 -1
index 1d5b475..5c1cf90 100644
@@ -1973,12 +1973,15 @@ static void __init gic_populate_ppi_partitions(struct device_node *gic_node)
 				continue;
 
 			cpu = of_cpu_node_to_id(cpu_node);
-			if (WARN_ON(cpu < 0))
+			if (WARN_ON(cpu < 0)) {
+				of_node_put(cpu_node);
 				continue;
+			}
 
 			pr_cont("%pOF[%d] ", cpu_node, cpu);
 
 			cpumask_set_cpu(cpu, &part->mask);
+			of_node_put(cpu_node);
 		}
 
 		pr_cont("}\n");
#11 lore raw

PATCH 6/6 irqchip/realtek-rtl: Fix refcount leak in map_interrupts

In reply to Miaoqian Lin

of_find_node_by_phandle() returns a node pointer with refcount incremented, we should use of_node_put() on it when not need anymore. This function doesn't call of_node_put() in error path. Call of_node_put() directly after of_property_read_u32() to cover both normal path and error path.

Fixes 9f3a0f34b84a ("irqchip: Add support for Realtek RTL838x/RTL839x interrupt controller")
---
 drivers/irqchip/irq-realtek-rtl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/irqchip/irq-realtek-rtl.c +1 -1
index 50a56820c99b..56bf502d9c67 100644
@@ -134,9 +134,9 @@ static int __init map_interrupts(struct device_node *node, struct irq_domain *do
 		if (!cpu_ictl)
 			return -EINVAL;
 		ret = of_property_read_u32(cpu_ictl, "#interrupt-cells", &tmp);
+		of_node_put(cpu_ictl);
 		if (ret || tmp != 1)
 			return -EINVAL;
-		of_node_put(cpu_ictl);
 
 		cpu_int = be32_to_cpup(imap + 2);
 		if (cpu_int > 7 || cpu_int < 2)
Signature · 1 line
2.25.1
#12 lore raw

[irqchip: irq/irqchip-fixes] irqchip/realtek-rtl: Fix refcount leak in map_interrupts

The following commit has been merged into the irq/irqchip-fixes branch of irqchip:

The following commit has been merged into the irq/irqchip-fixes branch of irqchip:

Commit-ID:     eff4780f83d0ae3e5b6c02ff5d999dc4c1c5c8ce
Gitweb:        https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms/eff4780f83d0ae3e5b6c02ff5d999dc4c1c5c8ce
Author:        Miaoqian Lin <[email protected]>
AuthorDate:    Wed, 01 Jun 2022 12:09:30 +04:00
Committer:     Marc Zyngier <[email protected]>
CommitterDate: Thu, 09 Jun 2022 17:36:57 +01:00

irqchip/realtek-rtl: Fix refcount leak in map_interrupts

of_find_node_by_phandle() returns a node pointer with refcount incremented, we should use of_node_put() on it when not need anymore. This function doesn't call of_node_put() in error path. Call of_node_put() directly after of_property_read_u32() to cover both normal path and error path.

Fixes 9f3a0f34b84a ("irqchip: Add support for Realtek RTL838x/RTL839x interrupt controller")
---
 drivers/irqchip/irq-realtek-rtl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/irqchip/irq-realtek-rtl.c +1 -1
index 50a5682..56bf502 100644
@@ -134,9 +134,9 @@ static int __init map_interrupts(struct device_node *node, struct irq_domain *do
 		if (!cpu_ictl)
 			return -EINVAL;
 		ret = of_property_read_u32(cpu_ictl, "#interrupt-cells", &tmp);
+		of_node_put(cpu_ictl);
 		if (ret || tmp != 1)
 			return -EINVAL;
-		of_node_put(cpu_ictl);
 
 		cpu_int = be32_to_cpup(imap + 2);
 		if (cpu_int > 7 || cpu_int < 2)