KVM Archive mirror
 help / color / mirror / Atom feed
From: Kunwu Chan <chentao@kylinos.cn>
To: seanjc@google.com, kunwu.chan@hotmail.com, pbonzini@redhat.com,
	shuah@kernel.org
Cc: kvm@vger.kernel.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org, Kunwu Chan <chentao@kylinos.cn>
Subject: [PATCH] KVM: selftests: Add 'malloc' failure check in test_vmx_nested_state
Date: Tue, 23 Apr 2024 15:39:52 +0800	[thread overview]
Message-ID: <20240423073952.2001989-1-chentao@kylinos.cn> (raw)

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


             reply	other threads:[~2024-04-23  7:40 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-23  7:39 Kunwu Chan [this message]
2024-04-23  8:49 ` [PATCH] KVM: selftests: Add 'malloc' failure check in test_vmx_nested_state 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240423073952.2001989-1-chentao@kylinos.cn \
    --to=chentao@kylinos.cn \
    --cc=kunwu.chan@hotmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).