Skip to content

Commit

Permalink
KVM: Simplify error handling in __gfn_to_pfn_memslot()
Browse files Browse the repository at this point in the history
KVM_HVA_ERR_RO_BAD satisfies kvm_is_error_hva(), so there's no need to
duplicate the "if (writable)" block. Fix this by bringing all
kvm_is_error_hva() cases under one conditional.

Signed-off-by: Anish Moorthy <amoorthy@google.com>
Link: https://lore.kernel.org/r/20240215235405.368539-5-amoorthy@google.com
[sean: use ternary operator]
Signed-off-by: Sean Christopherson <seanjc@google.com>
  • Loading branch information
anlsh authored and sean-jc committed Apr 9, 2024
1 parent a3bd2f7 commit f588557
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions virt/kvm/kvm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3035,16 +3035,12 @@ kvm_pfn_t __gfn_to_pfn_memslot(const struct kvm_memory_slot *slot, gfn_t gfn,
if (hva)
*hva = addr;

if (addr == KVM_HVA_ERR_RO_BAD) {
if (writable)
*writable = false;
return KVM_PFN_ERR_RO_FAULT;
}

if (kvm_is_error_hva(addr)) {
if (writable)
*writable = false;
return KVM_PFN_NOSLOT;

return addr == KVM_HVA_ERR_RO_BAD ? KVM_PFN_ERR_RO_FAULT :
KVM_PFN_NOSLOT;
}

/* Do not map writable pfn in the readonly memslot. */
Expand Down

0 comments on commit f588557

Please sign in to comment.