diff options
| author | Sean Christopherson <seanjc@google.com> | 2022-02-17 12:21:33 -0800 |
|---|---|---|
| committer | Paolo Bonzini <pbonzini@redhat.com> | 2022-06-11 11:46:22 -0400 |
| commit | 279eacbefad5d163a20f8fcde2fd9362bc24f7c7 (patch) | |
| tree | 84e74b7563361b0ad79a364f62e903762fedfccf /tools/testing/selftests/kvm/lib/kvm_util.c | |
| parent | KVM: selftests: Move KVM_CREATE_DEVICE_TEST code to separate helper (diff) | |
| download | linux-279eacbefad5d163a20f8fcde2fd9362bc24f7c7.tar.gz linux-279eacbefad5d163a20f8fcde2fd9362bc24f7c7.zip | |
KVM: selftests: Multiplex return code and fd in __kvm_create_device()
Multiplex the return value and fd (on success) in __kvm_create_device()
to mimic common library helpers that return file descriptors, e.g. open().
Signed-off-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'tools/testing/selftests/kvm/lib/kvm_util.c')
| -rw-r--r-- | tools/testing/selftests/kvm/lib/kvm_util.c | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index 9c0122b0e393..17e226107b65 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -1639,27 +1639,25 @@ int __kvm_test_create_device(struct kvm_vm *vm, uint64_t type) return __vm_ioctl(vm, KVM_CREATE_DEVICE, &create_dev); } -int __kvm_create_device(struct kvm_vm *vm, uint64_t type, int *fd) +int __kvm_create_device(struct kvm_vm *vm, uint64_t type) { struct kvm_create_device create_dev = { .type = type, .fd = -1, .flags = 0, }; - int ret; + int err; - ret = __vm_ioctl(vm, KVM_CREATE_DEVICE, &create_dev); - *fd = create_dev.fd; - return ret; + err = __vm_ioctl(vm, KVM_CREATE_DEVICE, &create_dev); + TEST_ASSERT(err <= 0, "KVM_CREATE_DEVICE shouldn't return a positive value"); + return err ? : create_dev.fd; } int kvm_create_device(struct kvm_vm *vm, uint64_t type) { - int fd, ret; - - ret = __kvm_create_device(vm, type, &fd); + int fd = __kvm_create_device(vm, type); - TEST_ASSERT(!ret, "KVM_CREATE_DEVICE IOCTL failed, rc: %i errno: %i", ret, errno); + TEST_ASSERT(fd >= 0, "KVM_CREATE_DEVICE IOCTL failed, rc: %i errno: %i", fd, errno); return fd; } |
