public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: selftests: Add 'malloc' failure check in test_vmx_nested_state
@ 2024-04-23  7:39 Kunwu Chan
  2024-04-23  8:49 ` Muhammad Usama Anjum
  2024-04-23 10:45 ` Markus Elfring
  0 siblings, 2 replies; 14+ messages in thread
From: Kunwu Chan @ 2024-04-23  7:39 UTC (permalink / raw)
  To: seanjc, kunwu.chan, pbonzini, shuah
  Cc: kvm, linux-kselftest, linux-kernel, Kunwu Chan

There is a 'malloc' call in test_vmx_nested_state function, which can
be unsuccessful. This patch will add the malloc failure checking
to avoid possible null dereference and give more information
about test fail reasons.

Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
---
 tools/testing/selftests/kvm/x86_64/vmx_set_nested_state_test.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/testing/selftests/kvm/x86_64/vmx_set_nested_state_test.c b/tools/testing/selftests/kvm/x86_64/vmx_set_nested_state_test.c
index 67a62a5a8895..18afc2000a74 100644
--- a/tools/testing/selftests/kvm/x86_64/vmx_set_nested_state_test.c
+++ b/tools/testing/selftests/kvm/x86_64/vmx_set_nested_state_test.c
@@ -91,6 +91,7 @@ void test_vmx_nested_state(struct kvm_vcpu *vcpu)
 	const int state_sz = sizeof(struct kvm_nested_state) + getpagesize();
 	struct kvm_nested_state *state =
 		(struct kvm_nested_state *)malloc(state_sz);
+	TEST_ASSERT(state, "-ENOMEM when allocating kvm state");
 
 	/* The format must be set to 0. 0 for VMX, 1 for SVM. */
 	set_default_vmx_state(state, state_sz);
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2024-05-10  8:40 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-23  7:39 [PATCH] KVM: selftests: Add 'malloc' failure check in test_vmx_nested_state Kunwu Chan
2024-04-23  8:49 ` Muhammad Usama Anjum
2024-04-23 10:45 ` Markus Elfring
2024-04-23 14:56   ` Sean Christopherson
2024-04-23 15:14     ` Andrew Jones
2024-04-23 19:15       ` Sean Christopherson
2024-04-24  2:59         ` Kunwu Chan
2024-04-24  5:41         ` Dan Carpenter
2024-04-24 14:47           ` Sean Christopherson
2024-04-24  7:50         ` Andrew Jones
2024-04-24 14:51           ` Sean Christopherson
2024-04-24 17:18             ` Oliver Upton
2024-04-25 16:25               ` Sean Christopherson
2024-05-10  8:40                 ` Kunwu Chan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox