arch/x86/kvm/lapic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Change the data type of the local variable this_tsc_khz to u32 because
virtual_tsc_khz is also declared as u32.
Since do_div() casts the divisor to u32 anyway, changing the data type
of this_tsc_khz to u32 also removes the following Coccinelle/coccicheck
warning reported by do_div.cocci:
WARNING: do_div() does a 64-by-32 division, please consider using div64_ul instead
Compile-tested only.
Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
---
arch/x86/kvm/lapic.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index a7172ba59ad2..40ff955c1859 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -1946,7 +1946,7 @@ static void start_sw_tscdeadline(struct kvm_lapic *apic)
u64 ns = 0;
ktime_t expire;
struct kvm_vcpu *vcpu = apic->vcpu;
- unsigned long this_tsc_khz = vcpu->arch.virtual_tsc_khz;
+ u32 this_tsc_khz = vcpu->arch.virtual_tsc_khz;
unsigned long flags;
ktime_t now;
--
2.45.2
On Wed, 14 Aug 2024 22:33:46 +0200, Thorsten Blum wrote:
> Change the data type of the local variable this_tsc_khz to u32 because
> virtual_tsc_khz is also declared as u32.
>
> Since do_div() casts the divisor to u32 anyway, changing the data type
> of this_tsc_khz to u32 also removes the following Coccinelle/coccicheck
> warning reported by do_div.cocci:
>
> [...]
Applied to kvm-x86 misc, thanks!
[1/1] KVM: x86: Optimize local variable in start_sw_tscdeadline()
https://github.com/kvm-x86/linux/commit/1448d4a935ab
--
https://github.com/kvm-x86/linux/tree/next
On Wed, Aug 14, 2024, Thorsten Blum wrote: > Change the data type of the local variable this_tsc_khz to u32 because > virtual_tsc_khz is also declared as u32. Heh, thought this looked familiar[*]. I'll plan on applying this for 6.12. [*] https://lore.kernel.org/all/ZT_WBanoip8zhxis@google.com > Since do_div() casts the divisor to u32 anyway, changing the data type > of this_tsc_khz to u32 also removes the following Coccinelle/coccicheck > warning reported by do_div.cocci: > > WARNING: do_div() does a 64-by-32 division, please consider using div64_ul instead > > Compile-tested only. > > Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com> > --- > arch/x86/kvm/lapic.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c > index a7172ba59ad2..40ff955c1859 100644 > --- a/arch/x86/kvm/lapic.c > +++ b/arch/x86/kvm/lapic.c > @@ -1946,7 +1946,7 @@ static void start_sw_tscdeadline(struct kvm_lapic *apic) > u64 ns = 0; > ktime_t expire; > struct kvm_vcpu *vcpu = apic->vcpu; > - unsigned long this_tsc_khz = vcpu->arch.virtual_tsc_khz; > + u32 this_tsc_khz = vcpu->arch.virtual_tsc_khz; > unsigned long flags; > ktime_t now; > > -- > 2.45.2 >
© 2016 - 2026 Red Hat, Inc.