powerpc/mpic: Fix memory leak of mpic on error paths
PATCH v4 1/1 powerpc/mpic: Fix memory leak of mpic on error paths
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.
---
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/[email protected]/
v2->v3:
- Introduce 'err_free_mpic' unwind label to cleanly free mpic and mpic->protected.
- Link to v2: https://lore.kernel.org/all/[email protected]/
--- arch/powerpc/sysdev/mpic.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
arch/powerpc/sysdev/mpic.c +7 -4
@@ -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 ;
Signature · 1 line
2.55.0