x86: kvm: avoid -Wshadow warning in header
PATCH 1/1 x86: kvm: avoid -Wshadow warning in header
From: Arnd Bergmann <[email protected]>
There are hundreds of warnings in a W=2 build about a local variable shadowing the global 'apic' definition:
arch/x86/kvm/lapic.h:149:65: warning: declaration of 'apic' shadows a global declaration [-Wshadow]
Avoid this by renaming the local in the kvm/lapic.h header
--- arch/x86/kvm/lapic.h | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-)
arch/x86/kvm/lapic.h +19 -19
@@ -83,8 +83,8 @@ void kvm_lapic_set_base(struct kvm_vcpu *vcpu, u64 value);u64 kvm_lapic_get_base (struct kvm_vcpu *vcpu);void kvm_recalculate_apic_map (struct kvm *kvm);void kvm_apic_set_version (struct kvm_vcpu *vcpu); -int kvm_lapic_reg_write (struct kvm_lapic *apic,u32 reg,u32 val); -int kvm_lapic_reg_read (struct kvm_lapic *apic,u32 offset,int len, +int kvm_lapic_reg_write (struct kvm_lapic *lapic,u32 reg,u32 val); +int kvm_lapic_reg_read (struct kvm_lapic *lapic,u32 offset,int len,void *data);bool kvm_apic_match_dest (struct kvm_vcpu *vcpu,struct kvm_lapic *source,int shorthand,unsigned int dest,int dest_mode);
@@ -95,12 +95,12 @@ bool kvm_apic_update_irr(struct kvm_vcpu *vcpu, u32 *pir, int *max_irr);void kvm_apic_update_ppr (struct kvm_vcpu *vcpu);int kvm_apic_set_irq (struct kvm_vcpu *vcpu,struct kvm_lapic_irq *irq,struct dest_map *dest_map); -int kvm_apic_local_deliver (struct kvm_lapic *apic,int lvt_type); +int kvm_apic_local_deliver (struct kvm_lapic *lapic,int lvt_type);void kvm_apic_update_apicv (struct kvm_vcpu *vcpu);bool kvm_irq_delivery_to_apic_fast (struct kvm *kvm,struct kvm_lapic *src,struct kvm_lapic_irq *irq,int *r,struct dest_map *dest_map); -void kvm_apic_send_ipi (struct kvm_lapic *apic,u32 icr_low,u32 icr_high); +void kvm_apic_send_ipi (struct kvm_lapic *lapic,u32 icr_low,u32 icr_high);u64 kvm_get_apic_base (struct kvm_vcpu *vcpu);int kvm_set_apic_base (struct kvm_vcpu *vcpu,struct msr_data *msr_info);
@@ -147,19 +147,19 @@ static inline void kvm_lapic_set_vector(int vec, void *bitmap)set_bit (VEC_POS (vec), (bitmap) +REG_POS (vec)); } -static inline void kvm_lapic_set_irr (int vec,struct kvm_lapic *apic) +static inline void kvm_lapic_set_irr (int vec,struct kvm_lapic *lapic) { -kvm_lapic_set_vector (vec, apic->regs +APIC_IRR ); +kvm_lapic_set_vector (vec, lapic->regs +APIC_IRR );/* * irr_pending must be true if any interrupt is pending; set it after * APIC_IRR to avoid race with apic_clear_irr */ - apic->irr_pending = true; + lapic->irr_pending = true; } -static inline u32 kvm_lapic_get_reg (struct kvm_lapic *apic,int reg_off) +static inline u32 kvm_lapic_get_reg (struct kvm_lapic *lapic,int reg_off) { -return *((u32 *) (apic->regs + reg_off)); +return *((u32 *) (lapic->regs + reg_off)); }static inline void __kvm_lapic_set_reg (char *regs,int reg_off,u32 val)
@@ -167,9 +167,9 @@ static inline void __kvm_lapic_set_reg(char *regs, int reg_off, u32 val) *((u32 *) (regs + reg_off)) = val; } -static inline void kvm_lapic_set_reg (struct kvm_lapic *apic,int reg_off,u32 val) +static inline void kvm_lapic_set_reg (struct kvm_lapic *lapic,int reg_off,u32 val) { -__kvm_lapic_set_reg (apic->regs, reg_off, val); +__kvm_lapic_set_reg (lapic->regs, reg_off, val); }extern struct static_key kvm_no_apic_vcpu;
@@ -183,19 +183,19 @@ static inline bool lapic_in_kernel(struct kvm_vcpu *vcpu)extern struct static_key_deferred apic_hw_disabled; -static inline int kvm_apic_hw_enabled (struct kvm_lapic *apic) +static inline int kvm_apic_hw_enabled (struct kvm_lapic *lapic) {if (static_key_false (&apic_hw_disabled.key)) -return apic->vcpu->arch.apic_base &MSR_IA32_APICBASE_ENABLE ; +return lapic->vcpu->arch.apic_base &MSR_IA32_APICBASE_ENABLE ;return MSR_IA32_APICBASE_ENABLE ; }extern struct static_key_deferred apic_sw_disabled; -static inline bool kvm_apic_sw_enabled (struct kvm_lapic *apic) +static inline bool kvm_apic_sw_enabled (struct kvm_lapic *lapic) {if (static_key_false (&apic_sw_disabled.key)) -return apic->sw_enabled; +return lapic->sw_enabled;return true; }
@@ -209,9 +209,9 @@ static inline int kvm_lapic_enabled(struct kvm_vcpu *vcpu)return kvm_apic_present (vcpu) &&kvm_apic_sw_enabled (vcpu->arch.apic); } -static inline int apic_x2apic_mode (struct kvm_lapic *apic) +static inline int apic_x2apic_mode (struct kvm_lapic *lapic) { -return apic->vcpu->arch.apic_base &X2APIC_ENABLE ; +return lapic->vcpu->arch.apic_base &X2APIC_ENABLE ; }static inline bool kvm_vcpu_apicv_active (struct kvm_vcpu *vcpu)
@@ -258,9 +258,9 @@ static inline enum lapic_mode kvm_apic_mode(u64 apic_base) return apic_base & (MSR_IA32_APICBASE_ENABLE | X2APIC_ENABLE); } -static inline u8 kvm_xapic_id (struct kvm_lapic *apic) +static inline u8 kvm_xapic_id (struct kvm_lapic *lapic) { -return kvm_lapic_get_reg (apic,APIC_ID ) >>24 ; +return kvm_lapic_get_reg (lapic,APIC_ID ) >>24 ; }#endif
Signature · 1 line
2.27.0
Quoted 8 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
There are hundreds of warnings in a W=2 build about a local variable shadowing the global 'apic' definition:
arch/x86/kvm/lapic.h:149:65: warning: declaration of 'apic' shadows a global declaration [-Wshadow]Avoid this by renaming the local in the
kvm/lapic.hheader
Rather than change KVM, and presumably other files as well, e.g. kvm/lapic.c and apic/io_apic.c also shadow 'apic' all over the place, what about renaming the global 'apic' to something more unique? KVM aside, using such a common name for a global variable has always struck me as a bit odd/dangerous/confusing.
Quoted 7 lines · Sean Christopherson
Quoted 5 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
There are hundreds of warnings in a W=2 build about a local variable shadowing the global 'apic' definition:
Quoted 8 lines
Quoted 3 lines
arch/x86/kvm/lapic.h:149:65: warning: declaration of 'apic' shadows a global declaration [-Wshadow]Avoid this by renaming the local in the
kvm/lapic.hheaderRather than change KVM, and presumably other files as well, e.g.
kvm/lapic.candapic/io_apic.calso shadow 'apic' all over the place, what about renaming the global 'apic' to something more unique? KVM aside, using such a common name for a global variable has always struck me as a bit odd/dangerous/confusing.
Yes, good point. I'll send a new patch for it later. Any suggestion for a better name?
Arnd