Skip to content

Commit c9d6015

Browse files
wei-w-wangsean-jc
authored andcommitted
KVM: allow KVM_BUG/KVM_BUG_ON to handle 64-bit cond
Current KVM_BUG and KVM_BUG_ON assume that 'cond' passed from callers is 32-bit as it casts 'cond' to the type of int. This will be wrong if 'cond' provided by a caller is 64-bit, e.g. an error code of 0xc0000d0300000000 will be converted to 0, which is not expected. Improves the implementation by using bool in KVM_BUG and KVM_BUG_ON. 'bool' is preferred to 'int' as __ret is essentially used as a boolean and coding-stytle.rst documents that use of bool is encouraged to improve readability and is often a better option than 'int' for storing boolean values. Fixes: 0b8f117 ("KVM: Add infrastructure and macro to mark VM as bugged") Signed-off-by: Wei Wang <wei.w.wang@intel.com> Reviewed-by: Mingwei Zhang <mizhang@google.com> Reviewed-by: Sean Christopherson <seanjc@google.com> Link: https://lore.kernel.org/r/20230307135233.54684-1-wei.w.wang@intel.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 76021e9 commit c9d6015

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

include/linux/kvm_host.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ static inline void kvm_vm_bugged(struct kvm *kvm)
849849

850850
#define KVM_BUG(cond, kvm, fmt...) \
851851
({ \
852-
int __ret = (cond); \
852+
bool __ret = !!(cond); \
853853
\
854854
if (WARN_ONCE(__ret && !(kvm)->vm_bugged, fmt)) \
855855
kvm_vm_bugged(kvm); \
@@ -858,7 +858,7 @@ static inline void kvm_vm_bugged(struct kvm *kvm)
858858

859859
#define KVM_BUG_ON(cond, kvm) \
860860
({ \
861-
int __ret = (cond); \
861+
bool __ret = !!(cond); \
862862
\
863863
if (WARN_ON_ONCE(__ret && !(kvm)->vm_bugged)) \
864864
kvm_vm_bugged(kvm); \

0 commit comments

Comments
 (0)