Re: [PATCH] arm_mpam: return allocation errors as error pointers
From: Ben Horgan
Date: Fri Oct 09 2026 - 13:20:58 EST
Hi Sang-Hoon,
On 9/30/26 08:08, Sang-Hoon Choi wrote:
> resctrl_arch_mon_ctx_alloc() stores the result of monitor allocation in
> an allocated int. If monitor allocation fails, it still returns that pointer.
> Callers check IS_ERR(), so they treat the failed allocation as a valid
> monitor context and pass the error value on as a monitor index.
>
> For example, if the wait for a free monitor ends because a signal is
> pending, the stored result is still -ENOSPC. Other allocation errors
> also reach the same return path.
Thanks for report and fix. Is this addressing a hypothetical problem or
have you seen resctrl_arch_mon_ctx_alloc() fail?
>
> Free the temporary allocation and return ERR_PTR(err) for negative
> results. Leave successful indices and USE_PRE_ALLOCATED unchanged.
>
> Fixes: 2a3c79c61539 ("arm_mpam: resctrl: Allow resctrl to allocate monitors")
> Reported-by: Changyul Lee <lcy8047@xxxxxxxxx>
> Link: https://github.com/lcy8047/radix-tree-bug-temp/blob/main/bug_list/idr-ida-xarray/wrong-id-value/IDR-BUG-33-mpam-monitor-id.md
I don't see anything at this link. This line can just go.
> Assisted-by: Sang-Hoon Choi <csh0052@xxxxxxxxx>
Should this be?
Assisted-by: LLM
Thanks,
Ben
> Signed-off-by: Sang-Hoon Choi <csh0052@xxxxxxxxx>
> ---
> Compile-tested on arm64 with allmodconfig and W=1 against mainline
> 6f8319e3e9a44dd537d17f41565a8453c560a581. No hardware runtime test was
> performed.
>
> drivers/resctrl/mpam_resctrl.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c
> index 9d223057953a..945be7465ad3 100644
> --- a/drivers/resctrl/mpam_resctrl.c
> +++ b/drivers/resctrl/mpam_resctrl.c
> @@ -413,6 +413,13 @@ void *resctrl_arch_mon_ctx_alloc(struct rdt_resource *r,
> } while (*ret == -ENOSPC && !signal_pending(current));
> finish_wait(&resctrl_mon_ctx_waiters, &wait);
>
> + if (*ret < 0) {
> + int err = *ret;
> +
> + kfree(ret);
> + return ERR_PTR(err);
> + }
> +
> return ret;
> }
>