Re: [PATCH RFC 12/15] arm_mpam: Fix get_cpumask_from_cache() to clear mask on error
From: Yin Li
Date: Thu Sep 03 2026 - 06:03:11 EST
On 9/3/2026 12:03 AM, Andre Przywara wrote:
Hi,
On 8/11/26 15:30, Yin Li wrote:
If mpam_get_cpumask_from_cache_id() fails, the affinity mask may have
been partially filled before the error occurred. The caller has no way
to distinguish a partial mask from a valid one, so it may misuse the
incomplete result.
But it returns an error, in which case any caller should ignore what's in the affinity pointer?
I am not sure that clearing the mask in necessarily the right solution.
Either we leave it untouched (which might be tricky), or we check that the callers restore or discard the affinity mask when the function returns an error.
Did this trigger any real problem, or was it some bored^Woverzealous AI review tool pointing that out?
Hi Andre,
Thanks for the review, and for the honest question.
This came out of internal review with AI-assisted checking — it didn't
trigger a real problem, just the observation that the mask could be left
partially filled on the error path.
You're right that a caller should ignore the affinity contents when the
function returns an error, so clearing the mask isn't strictly necessary. I'll drop it.
Cheers,
Andre
Clear the affinity mask before returning the error so the caller always
receives either a fully valid mask or an empty one.
Co-developed-by: Huang Yiwei <huang.yiwei@xxxxxxxxxxxxxxxx>
Signed-off-by: Huang Yiwei <huang.yiwei@xxxxxxxxxxxxxxxx>
Signed-off-by: Yin Li <yin.li@xxxxxxxxxxxxxxxx>
---
drivers/resctrl/mpam_devices.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/ mpam_devices.c
index eac3bc695fd1..d8856864e89a 100644
--- a/drivers/resctrl/mpam_devices.c
+++ b/drivers/resctrl/mpam_devices.c
@@ -243,7 +243,12 @@ static int get_cpumask_from_cache(struct device_node *cache,
return -ENOENT;
}
- return mpam_get_cpumask_from_cache_id(cache_id, cache_level, affinity);
+ err = mpam_get_cpumask_from_cache_id(cache_id, cache_level, affinity);
+ if (err)
+ /* Don't leave a partially-filled mask for the caller to misuse */
+ cpumask_clear(affinity);
+
+ return err;
}
static int mpam_dt_count_msc(void)
--
Thx and BRs,
Yin