KVM: x86: On Thu, Nov 04, 2021, Jim Mattson wrote: > These function names sound like predicates, and they have siblings, > *is_valid_msr(), which _are_ predicates. Moreover, there are comments > that essentially warn that these functions behave unexpectedly. > > Flip the polarity of the return values, so that they become > predicates, and convert the boolean result to a success/failure code > at the outer call site. > > Signed-off-by: Jim Mattson <jmattson@xxxxxxxxxx> > --- Reviewed-by: Sean Christopherson <seanjc@xxxxxxxxxx> > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index c1c4e2b05a63..d7def720227d 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -7328,7 +7328,9 @@ static void emulator_set_smbase(struct x86_emulate_ctxt *ctxt, u64 smbase) > static int emulator_check_pmc(struct x86_emulate_ctxt *ctxt, > u32 pmc) > { > - return kvm_pmu_is_valid_rdpmc_ecx(emul_to_vcpu(ctxt), pmc); > + if (kvm_pmu_is_valid_rdpmc_ecx(emul_to_vcpu(ctxt), pmc)) > + return 0; > + return -EINVAL; Heh, after seeing my off-the-cuff suggestion in a patch, I'd probably prefer the more usual "return 0 at the end". Either way is a-ok though, and waaaay better than kvm_pmu_is_valid_rdpmc_ecx() returning '0' on success :-) if (!kvm_pmu_is_valid_rdpmc_ecx(emul_to_vcpu(ctxt), pmc)) return -EINVAL; return 0; > } > > static int emulator_read_pmc(struct x86_emulate_ctxt *ctxt, > -- > 2.34.0.rc0.344.g81b53c2807-goog >