[PATCH] fs/resctrl: Free mon_data structures on rdt_get_tree() failure

From: Tony Luck

Date: Thu May 07 2026 - 16:21:05 EST


If mkdir_mondata_all() succeeds but a subsequent call in rdt_get_tree()
fails, the mon_data structures allocated by mon_get_kn_priv() are
leaked. Add mon_put_kn_priv() to the out_mondata error path to free
them.

Fixes: ee4f0ec938ad ("fs/resctrl: Simplify allocation of mon_data structures")
Reported-by: Reinette Chatre <reinette.chatre@xxxxxxxxx>
Assisted-by: GitHub Copilot CLI:claude-sonnet-4.6
Signed-off-by: Tony Luck <tony.luck@xxxxxxxxx>
---

Did I really need AI to help, no. But I wanted to see if it can at least
save me from some typing. Here's the prompt I used (contains just as
much typed content as this change!)

Reinette Chatre <reinette.chatre@xxxxxxxxx> reported a problem in
rdt_get_tree(). If the mkdir_mondata_all() succeeds, the some memory
is allocated by mon_get_kn_priv(). If a subsequent call in rdt_get_tree()
fails, then a call to mon_put_kn_priv() is needed to free any mon_data
structures.

Create and apply a patch to fix this. Research a suitable Fixes: tag.
Give credit to Reinette for reporting. Add a correctly formatted
Assisted-by: tag with AI model version. Keep the commit comment
concise.

fs/resctrl/rdtgroup.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
index 5dfdaa6f9d8f..aad573b62fd7 100644
--- a/fs/resctrl/rdtgroup.c
+++ b/fs/resctrl/rdtgroup.c
@@ -2879,8 +2879,10 @@ static int rdt_get_tree(struct fs_context *fc)
out_psl:
rdt_pseudo_lock_release();
out_mondata:
- if (resctrl_arch_mon_capable())
+ if (resctrl_arch_mon_capable()) {
+ mon_put_kn_priv();
kernfs_remove(kn_mondata);
+ }
out_mongrp:
if (resctrl_arch_mon_capable()) {
rdtgroup_unassign_cntrs(&rdtgroup_default);
--
2.54.0