Skip to content

Commit 735b0e0

Browse files
ivanorlov2206sean-jc
authored andcommitted
KVM: selftests: Add 'malloc' failure check in vcpu_save_state
There is a 'malloc' call in vcpu_save_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: Ivan Orlov <ivan.orlov0322@gmail.com> Link: https://lore.kernel.org/r/20230322144528.704077-1-ivan.orlov0322@gmail.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 8264e85 commit 735b0e0

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

tools/testing/selftests/kvm/lib/x86_64/processor.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,7 @@ struct kvm_x86_state *vcpu_save_state(struct kvm_vcpu *vcpu)
970970
vcpu_run_complete_io(vcpu);
971971

972972
state = malloc(sizeof(*state) + msr_list->nmsrs * sizeof(state->msrs.entries[0]));
973+
TEST_ASSERT(state, "-ENOMEM when allocating kvm state");
973974

974975
vcpu_events_get(vcpu, &state->events);
975976
vcpu_mp_state_get(vcpu, &state->mp_state);

0 commit comments

Comments
 (0)