[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220311055056.57265-23-seanjc@google.com>
Date: Fri, 11 Mar 2022 05:49:33 +0000
From: Sean Christopherson <seanjc@...gle.com>
To: linux-kernel@...r.kernel.org
Cc: Sean Christopherson <seanjc@...gle.com>
Subject: [RFC PATCH 022/105] KVM: selftests: Multiplex return code and fd in __kvm_create_device()
Signed-off-by: Sean Christopherson <seanjc@...gle.com>
---
tools/testing/selftests/kvm/aarch64/vgic_init.c | 6 +++---
.../selftests/kvm/include/kvm_util_base.h | 2 +-
tools/testing/selftests/kvm/lib/kvm_util.c | 16 +++++++---------
3 files changed, 11 insertions(+), 13 deletions(-)
diff --git a/tools/testing/selftests/kvm/aarch64/vgic_init.c b/tools/testing/selftests/kvm/aarch64/vgic_init.c
index 18d1d0335108..1015f6fc352c 100644
--- a/tools/testing/selftests/kvm/aarch64/vgic_init.c
+++ b/tools/testing/selftests/kvm/aarch64/vgic_init.c
@@ -642,8 +642,8 @@ static void test_v3_its_region(void)
int test_kvm_device(uint32_t gic_dev_type)
{
struct vm_gic v;
- int ret, fd;
uint32_t other;
+ int ret;
v.vm = vm_create_default_with_vcpus(NR_VCPUS, 0, 0, guest_code, NULL);
@@ -657,8 +657,8 @@ int test_kvm_device(uint32_t gic_dev_type)
return ret;
v.gic_fd = kvm_create_device(v.vm, gic_dev_type);
- ret = __kvm_create_device(v.vm, gic_dev_type, &fd);
- TEST_ASSERT(ret && errno == EEXIST, "create GIC device twice");
+ ret = __kvm_create_device(v.vm, gic_dev_type);
+ TEST_ASSERT(ret < 0 && errno == EEXIST, "create GIC device twice");
/* try to create the other gic_dev_type */
other = VGIC_DEV_IS_V2(gic_dev_type) ? KVM_DEV_TYPE_ARM_VGIC_V3
diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/testing/selftests/kvm/include/kvm_util_base.h
index 081ba04e5df3..df1202bacc04 100644
--- a/tools/testing/selftests/kvm/include/kvm_util_base.h
+++ b/tools/testing/selftests/kvm/include/kvm_util_base.h
@@ -480,7 +480,7 @@ void vcpu_args_set(struct kvm_vm *vm, uint32_t vcpuid, unsigned int num, ...);
int _kvm_device_check_attr(int dev_fd, uint32_t group, uint64_t attr);
int kvm_device_check_attr(int dev_fd, uint32_t group, uint64_t attr);
int __kvm_test_create_device(struct kvm_vm *vm, uint64_t type);
-int __kvm_create_device(struct kvm_vm *vm, uint64_t type, int *fd);
+int __kvm_create_device(struct kvm_vm *vm, uint64_t type);
int kvm_create_device(struct kvm_vm *vm, uint64_t type);
int _kvm_device_access(int dev_fd, uint32_t group, uint64_t attr,
void *val, bool write);
diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
index f0a08de67f0f..e10894cc2bc1 100644
--- a/tools/testing/selftests/kvm/lib/kvm_util.c
+++ b/tools/testing/selftests/kvm/lib/kvm_util.c
@@ -1610,27 +1610,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;
+ int fd = __kvm_create_device(vm, type);
- ret = __kvm_create_device(vm, type, &fd);
-
- 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;
}
--
2.35.1.723.g4982287a31-goog
Powered by blists - more mailing lists