Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] arm_mpam: Fix potential per-CPU memory leak on probe failure
@ 2026-11-24 13:58 Guangshuo Li
  2026-12-03 16:29 ` Ben Horgan
  0 siblings, 1 reply; 2+ messages in thread
From: Guangshuo Li @ 2026-11-24 13:58 UTC (permalink / raw)
  To: James Morse, Ben Horgan, Reinette Chatre, Fenghua Yu
  Cc: linux-arm-kernel, linux-kernel, stable

The PPI device IDs are allocated separately from the MSC. If subsequent
resource discovery fails, probe destroys the MSC without freeing its
per-CPU allocation.

Use devm_alloc_percpu() so the device releases the allocation when probe
fails. Its cleanup remains valid even if the MSC is freed beforehand.

This issue was found by our static analysis tool under development.

Fixes: 49aa621c4dca ("arm_mpam: Register and enable IRQs")
Cc: stable@vger.kernel.org
Reviewed-by: Fenghua Yu <fenghuay@nvidia.com>
Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
---
Changes in v2:
  - Use the arm_mpam subject prefix and describe a memory leak.
  - Add Fenghua Yu's Reviewed-by. No code changes from v1.

 drivers/resctrl/mpam_devices.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/mpam_devices.c
index 27abf60f4d67..ba341a6a59ce 100644
--- a/drivers/resctrl/mpam_devices.c
+++ b/drivers/resctrl/mpam_devices.c
@@ -2351,7 +2351,7 @@ static int __setup_ppi(struct mpam_msc *msc)
 {
 	int cpu;
 
-	msc->error_dev_id = alloc_percpu(struct mpam_msc *);
+	msc->error_dev_id = devm_alloc_percpu(&msc->pdev->dev, struct mpam_msc *);
 	if (!msc->error_dev_id)
 		return -ENOMEM;
 

base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f
-- 
2.43.0



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

* Re: [PATCH v2] arm_mpam: Fix potential per-CPU memory leak on probe failure
  2026-11-24 13:58 [PATCH v2] arm_mpam: Fix potential per-CPU memory leak on probe failure Guangshuo Li
@ 2026-12-03 16:29 ` Ben Horgan
  0 siblings, 0 replies; 2+ messages in thread
From: Ben Horgan @ 2026-12-03 16:29 UTC (permalink / raw)
  To: Guangshuo Li, James Morse, Reinette Chatre, Fenghua Yu
  Cc: linux-arm-kernel, linux-kernel, stable

Hi Guangshuo,

On 24/11/2026 13:58, Guangshuo Li wrote:
> The PPI device IDs are allocated separately from the MSC. If subsequent
> resource discovery fails, probe destroys the MSC without freeing its
> per-CPU allocation.

The device id is also leaked if the MPAM driver is torn down e.g. due to an error interrupt or an MPAM-Fb transport
failure. Your patch looks to also handle this case.

> 
> Use devm_alloc_percpu() so the device releases the allocation when probe
> fails. Its cleanup remains valid even if the MSC is freed beforehand.
> 
> This issue was found by our static analysis tool under development.

This can be below the --- rather than in the commit message.

> 
> Fixes: 49aa621c4dca ("arm_mpam: Register and enable IRQs")
> Cc: stable@vger.kernel.org

This is just a small leak that happens when MPAM is already not usable so Cc stable isn't necessary.

Thanks,

Ben

> Reviewed-by: Fenghua Yu <fenghuay@nvidia.com>
> Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
> ---
> Changes in v2:
>   - Use the arm_mpam subject prefix and describe a memory leak.
>   - Add Fenghua Yu's Reviewed-by. No code changes from v1.
> 
>  drivers/resctrl/mpam_devices.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/mpam_devices.c
> index 27abf60f4d67..ba341a6a59ce 100644
> --- a/drivers/resctrl/mpam_devices.c
> +++ b/drivers/resctrl/mpam_devices.c
> @@ -2351,7 +2351,7 @@ static int __setup_ppi(struct mpam_msc *msc)
>  {
>  	int cpu;
>  
> -	msc->error_dev_id = alloc_percpu(struct mpam_msc *);
> +	msc->error_dev_id = devm_alloc_percpu(&msc->pdev->dev, struct mpam_msc *);
>  	if (!msc->error_dev_id)
>  		return -ENOMEM;
>  
> 
> base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f



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

end of thread, other threads:[~2026-12-03 16:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 13:58 [PATCH v2] arm_mpam: Fix potential per-CPU memory leak on probe failure Guangshuo Li
2026-12-03 16:29 ` Ben Horgan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox