[PATCH] KVM: selftests: Fix reg_list and VM leak in get_reg_list test
From: Tharit Tangkijwanichakul
Date: Sun Sep 06 2026 - 00:22:36 EST
Calling the test with --list or --list-filtered causes an early return
in run_test() which skips freeing the reg_list and vm.
Use a goto so that the early return joins the common exit path.
Reported-by: Gokul K <gokul02k@xxxxxxxxx>
Link: https://lore.kernel.org/all/20260808081050.408657-1-gokul02k@xxxxxxxxx/
Fixes: 17da79e009c3 ("KVM: arm64: selftests: Split get-reg-list test code")
Signed-off-by: Tharit Tangkijwanichakul <tharitt97@xxxxxxxxx>
---
Tested on a Rock 5B (RK3588). Running the test with --list and
--list-filtered now exercises the goto path added by this fix and exits
cleanly.
---
tools/testing/selftests/kvm/get-reg-list.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/kvm/get-reg-list.c b/tools/testing/selftests/kvm/get-reg-list.c
index 216f10644c1a..6eb91d5c739e 100644
--- a/tools/testing/selftests/kvm/get-reg-list.c
+++ b/tools/testing/selftests/kvm/get-reg-list.c
@@ -189,7 +189,7 @@ static void run_test(struct vcpu_reg_list *c)
print_reg(config_name(c), id);
}
putchar('\n');
- return;
+ goto free_reg_list;
}
for_each_sublist(c, s)
@@ -306,6 +306,8 @@ static void run_test(struct vcpu_reg_list *c)
pr_info("%s: PASS\n", config_name(c));
blessed_n = 0;
free(blessed_reg);
+
+free_reg_list:
free(reg_list);
kvm_vm_free(vm);
}
--
2.47.3