Skip to content

Commit 97a3dee

Browse files
Fuad TabbaMarc Zyngier
authored andcommitted
KVM: arm64: Refactor setting the return value in kvm_vm_ioctl_enable_cap()
Initialize r = -EINVAL to get rid of the error-path initializations in kvm_vm_ioctl_enable_cap(). No functional change intended. Suggested-by: Oliver Upton <[email protected]> Signed-off-by: Fuad Tabba <[email protected]> Acked-by: Oliver Upton <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Marc Zyngier <[email protected]>
1 parent 4dc8c9d commit 97a3dee

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

arch/arm64/kvm/arm.c

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ int kvm_arch_vcpu_should_kick(struct kvm_vcpu *vcpu)
7272
int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
7373
struct kvm_enable_cap *cap)
7474
{
75-
int r;
76-
u64 new_cap;
75+
int r = -EINVAL;
7776

7877
if (cap->flags)
7978
return -EINVAL;
@@ -86,9 +85,7 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
8685
break;
8786
case KVM_CAP_ARM_MTE:
8887
mutex_lock(&kvm->lock);
89-
if (!system_supports_mte() || kvm->created_vcpus) {
90-
r = -EINVAL;
91-
} else {
88+
if (system_supports_mte() && !kvm->created_vcpus) {
9289
r = 0;
9390
set_bit(KVM_ARCH_FLAG_MTE_ENABLED, &kvm->arch.flags);
9491
}
@@ -99,25 +96,22 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
9996
set_bit(KVM_ARCH_FLAG_SYSTEM_SUSPEND_ENABLED, &kvm->arch.flags);
10097
break;
10198
case KVM_CAP_ARM_EAGER_SPLIT_CHUNK_SIZE:
102-
new_cap = cap->args[0];
103-
10499
mutex_lock(&kvm->slots_lock);
105100
/*
106101
* To keep things simple, allow changing the chunk
107102
* size only when no memory slots have been created.
108103
*/
109-
if (!kvm_are_all_memslots_empty(kvm)) {
110-
r = -EINVAL;
111-
} else if (new_cap && !kvm_is_block_size_supported(new_cap)) {
112-
r = -EINVAL;
113-
} else {
114-
r = 0;
115-
kvm->arch.mmu.split_page_chunk_size = new_cap;
104+
if (kvm_are_all_memslots_empty(kvm)) {
105+
u64 new_cap = cap->args[0];
106+
107+
if (!new_cap || kvm_is_block_size_supported(new_cap)) {
108+
r = 0;
109+
kvm->arch.mmu.split_page_chunk_size = new_cap;
110+
}
116111
}
117112
mutex_unlock(&kvm->slots_lock);
118113
break;
119114
default:
120-
r = -EINVAL;
121115
break;
122116
}
123117

0 commit comments

Comments
 (0)