irqchip: Fix some refcount leaks
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
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.
--- drivers/irqchip/irq-gic-realview.c | 1 + 1 file changed, 1 insertion(+)
drivers/irqchip/irq-gic-realview.c +1 -0
@@ -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
[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.
--- drivers/irqchip/irq-gic-realview.c | 1 + 1 file changed, 1 insertion(+)
drivers/irqchip/irq-gic-realview.c +1 -0
@@ -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,
PATCH 2/6 irqchip/apple-aic: Fix refcount leak in build_fiq_affinity
In reply to Miaoqian Linof_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.
--- drivers/irqchip/irq-apple-aic.c | 1 + 1 file changed, 1 insertion(+)
drivers/irqchip/irq-apple-aic.c +1 -0
@@ -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
[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.
--- drivers/irqchip/irq-apple-aic.c | 1 + 1 file changed, 1 insertion(+)
drivers/irqchip/irq-apple-aic.c +1 -0
@@ -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 ;
PATCH 3/6 irqchip/apple-aic: Fix refcount leak in aic_of_ic_init
In reply to Miaoqian Linof_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.
--- drivers/irqchip/irq-apple-aic.c | 1 + 1 file changed, 1 insertion(+)
drivers/irqchip/irq-apple-aic.c +1 -0
@@ -1144,6 +1144,7 @@ static int __init aic_of_ic_init(struct device_node *node, struct device_node *pfor_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
[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.
--- drivers/irqchip/irq-apple-aic.c | 1 + 1 file changed, 1 insertion(+)
drivers/irqchip/irq-apple-aic.c +1 -0
@@ -1144,6 +1144,7 @@ static int __init aic_of_ic_init(struct device_node *node, struct device_node *pfor_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);
PATCH 4/6 irqchip/gic-v3: Fix error handling in gic_populate_ppi_partitions
In reply to Miaoqian Linof_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.
--- drivers/irqchip/irq-gic-v3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/irqchip/irq-gic-v3.c +1 -1
@@ -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
[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.
--- drivers/irqchip/irq-gic-v3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/irqchip/irq-gic-v3.c +1 -1
@@ -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);
PATCH 5/6 irqchip/gic-v3: Fix refcount leak in gic_populate_ppi_partitions
In reply to Miaoqian Linof_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.
--- drivers/irqchip/irq-gic-v3.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/irqchip/irq-gic-v3.c +4 -1
@@ -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
[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.
--- drivers/irqchip/irq-gic-v3.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/irqchip/irq-gic-v3.c +4 -1
@@ -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" );
PATCH 6/6 irqchip/realtek-rtl: Fix refcount leak in map_interrupts
In reply to Miaoqian Linof_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.
--- drivers/irqchip/irq-realtek-rtl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/irqchip/irq-realtek-rtl.c +1 -1
@@ -134,9 +134,9 @@ static int __init map_interrupts(struct device_node *node, struct irq_domain *doif (!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
[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.
--- drivers/irqchip/irq-realtek-rtl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/irqchip/irq-realtek-rtl.c +1 -1
@@ -134,9 +134,9 @@ static int __init map_interrupts(struct device_node *node, struct irq_domain *doif (!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 )