[PATCH 2/4] fs/resctrl: Free mon_data structures on rdt_get_tree() failure
From: Tony Luck
Date: Fri May 08 2026 - 14:21:58 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.
mon_get_kn_priv() and mon_put_kn_priv() moved so defined before used.
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>
---
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 a6376a3fc4c3..0db1a92aefbe 100644
--- a/fs/resctrl/rdtgroup.c
+++ b/fs/resctrl/rdtgroup.c
@@ -3067,8 +3067,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