From: Jyoti Gupta <jyoti@linux.ibm.com>
To: linuxppc-dev@lists.ozlabs.org
Cc: maddy@linux.ibm.com, npiggin@gmail.com, chleroy@kernel.org,
ritesh.list@gmail.com, sshegde@linux.ibm.com,
Sourabh Jain <sourabhjain@linux.ibm.com>,
"Mukesh Kumar Chaurasiya (IBM)" <mkchauras@gmail.com>,
Amit Machhiwal <amachhiw@linux.ibm.com>
Subject: [PATCH v4] powerpc/mpic: Fix memory leak of mpic on error paths
Date: Thu, 19 Nov 2026 13:31:18 +0530 [thread overview]
Message-ID: <20261119080118.48688-1-jyoti@linux.ibm.com> (raw)
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")
Suggested-by: Sourabh Jain <sourabhjain@linux.ibm.com>
Signed-off-by: Jyoti Gupta <jyoti@linux.ibm.com>
Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
Reviewed-by: Mukesh Kumar Chaurasiya (IBM) <mkchauras@gmail.com>
Reviewed-by: Amit Machhiwal <amachhiw@linux.ibm.com>
---
Changelog:
v3->v4:
- Retain the FIXME comment about the leaked MPIC mappings (they are not
fixed for !CONFIG_PPC_DCR / !MPIC_USES_DCR), per Ritesh's feedback.
- Added Suggested-by tag.
- Collect Reviewed-by tags from Ritesh, Mukesh and Amit.
- Link to v3: https://lore.kernel.org/all/20261006065945.391637-1-jyoti@linux.ibm.com/
v2->v3:
- Introduce 'err_free_mpic' unwind label to cleanly free mpic and mpic->protected.
- Link to v2: https://lore.kernel.org/all/20260930180919.335930-1-jyoti@linux.ibm.com/
---
arch/powerpc/sysdev/mpic.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/arch/powerpc/sysdev/mpic.c b/arch/powerpc/sysdev/mpic.c
index 257886ec3f70..ab33992a8698 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_free_mpic;
}
}
@@ -1489,11 +1489,11 @@ struct mpic * __init mpic_alloc(struct device_node *node,
&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.
+ * FIXME: The code leaks the MPIC mappings here; this is very unlikely
+ * to fail but it ought to be fixed anyways.
*/
if (mpic->irqhost == NULL)
- return NULL;
+ goto err_free_mpic;
/* Display version */
switch (greg_feature & MPIC_GREG_FEATURE_VERSION_MASK) {
@@ -1526,6 +1526,9 @@ struct mpic * __init mpic_alloc(struct device_node *node,
return mpic;
+err_free_mpic:
+ bitmap_free(mpic->protected);
+ kfree(mpic);
err_of_node_put:
of_node_put(node);
return NULL;
--
2.55.0
next reply other threads:[~2026-11-19 8:02 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 8:01 Jyoti Gupta [this message]
2026-11-30 12:26 ` [PATCH v4] powerpc/mpic: Fix memory leak of mpic on error paths Madhavan Srinivasan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261119080118.48688-1-jyoti@linux.ibm.com \
--to=jyoti@linux.ibm.com \
--cc=amachhiw@linux.ibm.com \
--cc=chleroy@kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=maddy@linux.ibm.com \
--cc=mkchauras@gmail.com \
--cc=npiggin@gmail.com \
--cc=ritesh.list@gmail.com \
--cc=sourabhjain@linux.ibm.com \
--cc=sshegde@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox