Messages in this thread | | | Date | Tue, 2 Aug 2022 09:04:10 +0800 | From | kernel test robot <> | Subject | arch/x86/kernel/fpu/xstate.c:1117:7: warning: Local variable 'mask' shadows outer variable [shadowVariable] |
| |
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master head: 9de1f9c8ca5100a02a2e271bdbde36202e251b4b commit: 522e92743b35351bda1b6a9136560f833a9c2490 x86/fpu: Deduplicate copy_uabi_from_user/kernel_to_xstate() date: 1 year, 1 month ago compiler: gcc-11 (Debian 11.3.0-3) 11.3.0 reproduce (cppcheck warning): # apt-get install cppcheck git checkout 522e92743b35351bda1b6a9136560f833a9c2490 cppcheck --quiet --enable=style,performance,portability --template=gcc FILE
If you fix the issue, kindly add following tag where applicable Reported-by: kernel test robot <lkp@intel.com>
cppcheck warnings: (new ones prefixed by >>) >> arch/x86/kernel/fpu/xstate.c:1117:7: warning: Local variable 'mask' shadows outer variable [shadowVariable] u64 mask = ((u64)1 << i); ^ arch/x86/kernel/fpu/xstate.c:1086:6: note: Shadowed declaration u64 mask; ^ arch/x86/kernel/fpu/xstate.c:1117:7: note: Shadow variable u64 mask = ((u64)1 << i); ^
cppcheck possible warnings: (new ones prefixed by >>, may not real problems)
>> drivers/thermal/intel/therm_throt.c:323:12: warning: Using pointer that is a temporary. [danglingTemporaryLifetime] state = &pstate->core_throttle; ^ drivers/thermal/intel/therm_throt.c:318:33: note: Address of variable taken here. struct thermal_state *pstate = &per_cpu(thermal_state, this_cpu); ^ drivers/thermal/intel/therm_throt.c:323:12: note: Address of variable taken here. state = &pstate->core_throttle; ^ drivers/thermal/intel/therm_throt.c:318:41: note: Temporary created here. struct thermal_state *pstate = &per_cpu(thermal_state, this_cpu); ^ drivers/thermal/intel/therm_throt.c:323:12: note: Using pointer that is a temporary. state = &pstate->core_throttle; ^ drivers/thermal/intel/therm_throt.c:323:13: warning: Using pointer that is a temporary. [danglingTemporaryLifetime] state = &pstate->core_throttle; ^ drivers/thermal/intel/therm_throt.c:318:33: note: Address of variable taken here. struct thermal_state *pstate = &per_cpu(thermal_state, this_cpu); ^ drivers/thermal/intel/therm_throt.c:318:41: note: Temporary created here. struct thermal_state *pstate = &per_cpu(thermal_state, this_cpu); ^ drivers/thermal/intel/therm_throt.c:323:13: note: Using pointer that is a temporary. state = &pstate->core_throttle; ^ drivers/thermal/intel/therm_throt.c:325:12: warning: Using pointer that is a temporary. [danglingTemporaryLifetime] state = &pstate->core_power_limit; ^ drivers/thermal/intel/therm_throt.c:318:33: note: Address of variable taken here. struct thermal_state *pstate = &per_cpu(thermal_state, this_cpu); ^ drivers/thermal/intel/therm_throt.c:325:12: note: Address of variable taken here. state = &pstate->core_power_limit; ^ drivers/thermal/intel/therm_throt.c:318:41: note: Temporary created here. struct thermal_state *pstate = &per_cpu(thermal_state, this_cpu); ^ drivers/thermal/intel/therm_throt.c:325:12: note: Using pointer that is a temporary. state = &pstate->core_power_limit; ^ drivers/thermal/intel/therm_throt.c:325:13: warning: Using pointer that is a temporary. [danglingTemporaryLifetime] state = &pstate->core_power_limit; ^ drivers/thermal/intel/therm_throt.c:318:33: note: Address of variable taken here. struct thermal_state *pstate = &per_cpu(thermal_state, this_cpu); ^ drivers/thermal/intel/therm_throt.c:318:41: note: Temporary created here. struct thermal_state *pstate = &per_cpu(thermal_state, this_cpu); ^ drivers/thermal/intel/therm_throt.c:325:13: note: Using pointer that is a temporary. state = &pstate->core_power_limit; ^ drivers/thermal/intel/therm_throt.c:330:12: warning: Using pointer that is a temporary. [danglingTemporaryLifetime] state = &pstate->package_throttle; ^ drivers/thermal/intel/therm_throt.c:318:33: note: Address of variable taken here. struct thermal_state *pstate = &per_cpu(thermal_state, this_cpu); ^ drivers/thermal/intel/therm_throt.c:330:12: note: Address of variable taken here. state = &pstate->package_throttle; ^ drivers/thermal/intel/therm_throt.c:318:41: note: Temporary created here. struct thermal_state *pstate = &per_cpu(thermal_state, this_cpu); ^ drivers/thermal/intel/therm_throt.c:330:12: note: Using pointer that is a temporary. state = &pstate->package_throttle; ^ drivers/thermal/intel/therm_throt.c:330:13: warning: Using pointer that is a temporary. [danglingTemporaryLifetime] state = &pstate->package_throttle; ^ drivers/thermal/intel/therm_throt.c:318:33: note: Address of variable taken here. struct thermal_state *pstate = &per_cpu(thermal_state, this_cpu); ^ drivers/thermal/intel/therm_throt.c:318:41: note: Temporary created here. struct thermal_state *pstate = &per_cpu(thermal_state, this_cpu); ^ drivers/thermal/intel/therm_throt.c:330:13: note: Using pointer that is a temporary. state = &pstate->package_throttle; ^ drivers/thermal/intel/therm_throt.c:332:12: warning: Using pointer that is a temporary. [danglingTemporaryLifetime] state = &pstate->package_power_limit; ^ drivers/thermal/intel/therm_throt.c:318:33: note: Address of variable taken here. struct thermal_state *pstate = &per_cpu(thermal_state, this_cpu); ^ drivers/thermal/intel/therm_throt.c:332:12: note: Address of variable taken here. state = &pstate->package_power_limit; ^ drivers/thermal/intel/therm_throt.c:318:41: note: Temporary created here. struct thermal_state *pstate = &per_cpu(thermal_state, this_cpu); ^ drivers/thermal/intel/therm_throt.c:332:12: note: Using pointer that is a temporary. state = &pstate->package_power_limit; ^ drivers/thermal/intel/therm_throt.c:332:13: warning: Using pointer that is a temporary. [danglingTemporaryLifetime] state = &pstate->package_power_limit; ^ drivers/thermal/intel/therm_throt.c:318:33: note: Address of variable taken here. struct thermal_state *pstate = &per_cpu(thermal_state, this_cpu); --
vim +/mask +1117 arch/x86/kernel/fpu/xstate.c
947f4947cf00ea Thomas Gleixner 2021-06-23 1079 522e92743b3535 Thomas Gleixner 2021-06-23 1080 522e92743b3535 Thomas Gleixner 2021-06-23 1081 static int copy_uabi_to_xstate(struct xregs_state *xsave, const void *kbuf, 522e92743b3535 Thomas Gleixner 2021-06-23 1082 const void __user *ubuf) 79fecc2b7506f2 Ingo Molnar 2017-09-23 1083 { 79fecc2b7506f2 Ingo Molnar 2017-09-23 1084 unsigned int offset, size; 80d8ae86b36791 Eric Biggers 2017-09-24 1085 struct xstate_header hdr; 522e92743b3535 Thomas Gleixner 2021-06-23 1086 u64 mask; 522e92743b3535 Thomas Gleixner 2021-06-23 1087 int i; 79fecc2b7506f2 Ingo Molnar 2017-09-23 1088 79fecc2b7506f2 Ingo Molnar 2017-09-23 1089 offset = offsetof(struct xregs_state, header); 522e92743b3535 Thomas Gleixner 2021-06-23 1090 if (copy_from_buffer(&hdr, offset, sizeof(hdr), kbuf, ubuf)) 522e92743b3535 Thomas Gleixner 2021-06-23 1091 return -EFAULT; 79fecc2b7506f2 Ingo Molnar 2017-09-23 1092 5274e6c172c472 Fenghua Yu 2020-05-12 1093 if (validate_user_xstate_header(&hdr)) 79fecc2b7506f2 Ingo Molnar 2017-09-23 1094 return -EINVAL; 79fecc2b7506f2 Ingo Molnar 2017-09-23 1095 522e92743b3535 Thomas Gleixner 2021-06-23 1096 /* Validate MXCSR when any of the related features is in use */ 522e92743b3535 Thomas Gleixner 2021-06-23 1097 mask = XFEATURE_MASK_FP | XFEATURE_MASK_SSE | XFEATURE_MASK_YMM; 522e92743b3535 Thomas Gleixner 2021-06-23 1098 if (hdr.xfeatures & mask) { 522e92743b3535 Thomas Gleixner 2021-06-23 1099 u32 mxcsr[2]; 522e92743b3535 Thomas Gleixner 2021-06-23 1100 522e92743b3535 Thomas Gleixner 2021-06-23 1101 offset = offsetof(struct fxregs_state, mxcsr); 522e92743b3535 Thomas Gleixner 2021-06-23 1102 if (copy_from_buffer(mxcsr, offset, sizeof(mxcsr), kbuf, ubuf)) 522e92743b3535 Thomas Gleixner 2021-06-23 1103 return -EFAULT; 522e92743b3535 Thomas Gleixner 2021-06-23 1104 522e92743b3535 Thomas Gleixner 2021-06-23 1105 /* Reserved bits in MXCSR must be zero. */ 522e92743b3535 Thomas Gleixner 2021-06-23 1106 if (mxcsr[0] & ~mxcsr_feature_mask) 947f4947cf00ea Thomas Gleixner 2021-06-23 1107 return -EINVAL; 947f4947cf00ea Thomas Gleixner 2021-06-23 1108 522e92743b3535 Thomas Gleixner 2021-06-23 1109 /* SSE and YMM require MXCSR even when FP is not in use. */ 522e92743b3535 Thomas Gleixner 2021-06-23 1110 if (!(hdr.xfeatures & XFEATURE_MASK_FP)) { 522e92743b3535 Thomas Gleixner 2021-06-23 1111 xsave->i387.mxcsr = mxcsr[0]; 522e92743b3535 Thomas Gleixner 2021-06-23 1112 xsave->i387.mxcsr_mask = mxcsr[1]; 522e92743b3535 Thomas Gleixner 2021-06-23 1113 } 522e92743b3535 Thomas Gleixner 2021-06-23 1114 } 522e92743b3535 Thomas Gleixner 2021-06-23 1115 79fecc2b7506f2 Ingo Molnar 2017-09-23 1116 for (i = 0; i < XFEATURE_MAX; i++) { 79fecc2b7506f2 Ingo Molnar 2017-09-23 @1117 u64 mask = ((u64)1 << i); 79fecc2b7506f2 Ingo Molnar 2017-09-23 1118 b89eda482d7849 Eric Biggers 2017-09-24 1119 if (hdr.xfeatures & mask) { 07baeb04f37c95 Sebastian Andrzej Siewior 2019-04-03 1120 void *dst = __raw_xsave_addr(xsave, i); 79fecc2b7506f2 Ingo Molnar 2017-09-23 1121 79fecc2b7506f2 Ingo Molnar 2017-09-23 1122 offset = xstate_offsets[i]; 79fecc2b7506f2 Ingo Molnar 2017-09-23 1123 size = xstate_sizes[i]; 79fecc2b7506f2 Ingo Molnar 2017-09-23 1124 522e92743b3535 Thomas Gleixner 2021-06-23 1125 if (copy_from_buffer(dst, offset, size, kbuf, ubuf)) 522e92743b3535 Thomas Gleixner 2021-06-23 1126 return -EFAULT; 79fecc2b7506f2 Ingo Molnar 2017-09-23 1127 } 79fecc2b7506f2 Ingo Molnar 2017-09-23 1128 } 79fecc2b7506f2 Ingo Molnar 2017-09-23 1129 79fecc2b7506f2 Ingo Molnar 2017-09-23 1130 /* 79fecc2b7506f2 Ingo Molnar 2017-09-23 1131 * The state that came in from userspace was user-state only. 79fecc2b7506f2 Ingo Molnar 2017-09-23 1132 * Mask all the user states out of 'xfeatures': 79fecc2b7506f2 Ingo Molnar 2017-09-23 1133 */ 8ab22804efefea Fenghua Yu 2020-05-12 1134 xsave->header.xfeatures &= XFEATURE_MASK_SUPERVISOR_ALL; 79fecc2b7506f2 Ingo Molnar 2017-09-23 1135 79fecc2b7506f2 Ingo Molnar 2017-09-23 1136 /* 79fecc2b7506f2 Ingo Molnar 2017-09-23 1137 * Add back in the features that came in from userspace: 79fecc2b7506f2 Ingo Molnar 2017-09-23 1138 */ b89eda482d7849 Eric Biggers 2017-09-24 1139 xsave->header.xfeatures |= hdr.xfeatures; 79fecc2b7506f2 Ingo Molnar 2017-09-23 1140 79fecc2b7506f2 Ingo Molnar 2017-09-23 1141 return 0; 79fecc2b7506f2 Ingo Molnar 2017-09-23 1142 } 79fecc2b7506f2 Ingo Molnar 2017-09-23 1143
:::::: The code at line 1117 was first introduced by commit :::::: 79fecc2b7506f29fb91becc65e8788e5ae7eba9f x86/fpu: Split copy_user_to_xstate() into copy_kernel_to_xstate() & copy_user_to_xstate()
:::::: TO: Ingo Molnar <mingo@kernel.org> :::::: CC: Ingo Molnar <mingo@kernel.org>
-- 0-DAY CI Kernel Test Service https://01.org/lkp
| |