mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ben Horgan <ben.horgan@arm.com>
To: Sang-Hoon Choi <csh0052@gmail.com>, James Morse <james.morse@arm.com>
Cc: Reinette Chatre <reinette.chatre@intel.com>,
	Fenghua Yu <fenghuay@nvidia.com>,
	linux-kernel@vger.kernel.org, Changyul Lee <lcy8047@gmail.com>
Subject: Re: [PATCH] arm_mpam: return allocation errors as error pointers
Date: Mon, 26 Oct 2026 14:41:58 +0000	[thread overview]
Message-ID: <d92a1d48-6833-47a1-ab10-9d3b98543de1@arm.com> (raw)
In-Reply-To: <179075213853.3.16001626385793291460.idr-bug-33@gmail.com>

Hi Sang-Hoon,

On 30/09/2026 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.
> 
> 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@gmail.com>
> 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
> Assisted-by: Sang-Hoon Choi <csh0052@gmail.com>
> Signed-off-by: Sang-Hoon Choi <csh0052@gmail.com>
> ---
> 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;

This seems like a good place to use the cleanup.h helpers, __free(kfree) and then pass on the
pointer with return_ptr(ret).

Thanks,

Ben

>  }
>  


      parent reply	other threads:[~2026-10-26 14:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-30  7:08 Sang-Hoon Choi
2026-10-09 17:18 ` Ben Horgan
2026-10-26 14:41 ` Ben Horgan [this message]

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=d92a1d48-6833-47a1-ab10-9d3b98543de1@arm.com \
    --to=ben.horgan@arm.com \
    --cc=csh0052@gmail.com \
    --cc=fenghuay@nvidia.com \
    --cc=james.morse@arm.com \
    --cc=lcy8047@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=reinette.chatre@intel.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

all inboxes | Powered by JetHome®