diff mbox series

target/i386/kvm: Replace KVM_MSR_FILTER_MAX_RANGES with ARRAY_SIZE(msr_handlers)

Message ID 20250108151946.1379591-1-zhao1.liu@intel.com (mailing list archive)
State New
Headers show
Series target/i386/kvm: Replace KVM_MSR_FILTER_MAX_RANGES with ARRAY_SIZE(msr_handlers) | expand

Commit Message

Zhao Liu Jan. 8, 2025, 3:19 p.m. UTC
kvm_install_msr_filters() uses KVM_MSR_FILTER_MAX_RANGES as the bound
when traversing msr_handlers[], while other places compute the size by
ARRAY_SIZE(msr_handlers).

In fact, msr_handlers[] is an array with the fixed size
KVM_MSR_FILTER_MAX_RANGES, so there is no difference between the two
ways.

For the code consistency, use ARRAY_SIZE(msr_handlers) uniformly instead
of KVM_MSR_FILTER_MAX_RANGES.

Suggested-by: Zide Chen <zide.chen@intel.com>
Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
---
Changelog:
 * Addressed Paolo's comment [1] to choose ARRAY_SIZE(msr_handlers).

 [1]: https://lore.kernel.org/qemu-devel/5463356b-827f-4c9f-a76e-02cd580fe885@redhat.com/
---
 target/i386/kvm/kvm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
index 2f66e63b880a..7424a3f5cf48 100644
--- a/target/i386/kvm/kvm.c
+++ b/target/i386/kvm/kvm.c
@@ -5851,7 +5851,7 @@  static bool kvm_install_msr_filters(KVMState *s)
     };
     int r, i, j = 0;
 
-    for (i = 0; i < KVM_MSR_FILTER_MAX_RANGES; i++) {
+    for (i = 0; i < ARRAY_SIZE(msr_handlers); i++) {
         KVMMSRHandlers *handler = &msr_handlers[i];
         if (handler->msr) {
             struct kvm_msr_filter_range *range = &filter.ranges[j++];