All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] powerpc/mpic: Fix memory leak of mpic on error paths
@ 2026-09-30 18:09 Jyoti Gupta
  2026-09-30 18:50 ` Amit Machhiwal
  2026-10-03  9:32 ` Mukesh Kumar Chaurasiya
  0 siblings, 2 replies; 6+ messages in thread
From: Jyoti Gupta @ 2026-09-30 18:09 UTC (permalink / raw)
  To: linuxppc-dev
  Cc: maddy, mpe, npiggin, chleroy, ritesh.list, sshegde, sourabhjain,
	amachhiw, mkchauras

mpic_alloc() allocates struct mpic (and optionally the protected
sources bitmap) but does not free them when mpic_setup_error_int() or
irq_domain_create_linear() fails, leaking the memory.

Free the bitmap and the mpic in the common error path before dropping the
device node reference.

Fixes: 996983b75ceb ("powerpc/mpic: Search for open-pic device-tree node if NULL")
Signed-off-by: Jyoti Gupta <jyoti@linux.ibm.com>
---
 arch/powerpc/sysdev/mpic.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/sysdev/mpic.c b/arch/powerpc/sysdev/mpic.c
index 257886ec3f70..b21a880777cc 100644
--- a/arch/powerpc/sysdev/mpic.c
+++ b/arch/powerpc/sysdev/mpic.c
@@ -1389,7 +1389,7 @@ struct mpic * __init mpic_alloc(struct device_node *node,
 		if (fsl_version >= 0x401) {
 			ret = mpic_setup_error_int(mpic, intvec_top - 13);
 			if (ret)
-				return NULL;
+				goto err_of_node_put;
 		}
 
 	}
@@ -1488,12 +1488,8 @@ struct mpic * __init mpic_alloc(struct device_node *node,
 						 intvec_top,
 						 &mpic_host_ops, mpic);
 
-	/*
-	 * FIXME: The code leaks the MPIC object and mappings here; this
-	 * is very unlikely to fail but it ought to be fixed anyways.
-	 */
 	if (mpic->irqhost == NULL)
-		return NULL;
+		goto err_of_node_put;
 
 	/* Display version */
 	switch (greg_feature & MPIC_GREG_FEATURE_VERSION_MASK) {
@@ -1527,6 +1523,9 @@ struct mpic * __init mpic_alloc(struct device_node *node,
 	return mpic;
 
 err_of_node_put:
+	if (mpic)
+		bitmap_free(mpic->protected);
+	kfree(mpic);
 	of_node_put(node);
 	return NULL;
 }
-- 
2.55.0



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

end of thread, other threads:[~2026-10-05 15:19 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-30 18:09 [PATCH v2] powerpc/mpic: Fix memory leak of mpic on error paths Jyoti Gupta
2026-09-30 18:50 ` Amit Machhiwal
2026-10-01 11:59   ` Jyoti Gupta
2026-10-05  7:44     ` Amit Machhiwal
2026-10-05 15:18       ` Jyoti Gupta
2026-10-03  9:32 ` Mukesh Kumar Chaurasiya

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.