From: Isaku Yamahata Make ROL16() explicitly mask instead of the truncation by u16 cast. Sparse complains as follows for vmcs12.c and hyperv_evmcs.c. > vmcs12.c:17:9: warning: cast truncates bits from constant value > (20002 becomes 2) It is because ROL16(val, n) includes "(u16)(val) << (n)" whose type is int, not u16, due to integer promotion even with a u16 cast. The outermost u16 cast in ROL16() may truncate it. Explicitly mask it to avoid truncation by the u16 cast. Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202603061942.wdSsERnL-lkp@intel.com/ Signed-off-by: Isaku Yamahata --- arch/x86/kvm/vmx/vmcs.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/vmx/vmcs.h b/arch/x86/kvm/vmx/vmcs.h index 1f16ddeae9cb..b5b5f4870655 100644 --- a/arch/x86/kvm/vmx/vmcs.h +++ b/arch/x86/kvm/vmx/vmcs.h @@ -18,7 +18,8 @@ * wasting too much memory, while the "algorithm" is fast enough to be used to * lookup vmcs12 fields on-demand, e.g. for emulation. */ -#define ROL16(val, n) ((u16)(((u16)(val) << (n)) | ((u16)(val) >> (16 - (n))))) +#define ROL16(val, n) ((u16)((((u16)(val) << (n)) & GENMASK_U16(15, 0)) | \ + ((u16)(val) >> (16 - (n))))) #define VMCS12_IDX_TO_ENC(idx) ROL16(idx, 10) #define ENC_TO_VMCS12_IDX(enc) ROL16(enc, 6) base-commit: 5128b972fb2801ad9aca54d990a75611ab5283a9 -- 2.45.2