* arch/x86/kernel/fpu/xstate.c:1117:7: warning: Local variable 'mask' shadows outer variable [shadowVariable]
@ 2022-04-26 12:25 kernel test robot
2022-05-02 7:33 ` [tip: x86/fpu] x86/fpu: Cleanup variable shadowing tip-bot2 for Thomas Gleixner
0 siblings, 1 reply; 2+ messages in thread
From: kernel test robot @ 2022-04-26 12:25 UTC (permalink / raw)
To: Thomas Gleixner; +Cc: kbuild-all, linux-kernel, Borislav Petkov
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: d615b5416f8a1afeb82d13b238f8152c572d59c0
commit: 522e92743b35351bda1b6a9136560f833a9c2490 x86/fpu: Deduplicate copy_uabi_from_user/kernel_to_xstate()
date: 10 months ago
compiler: gcc-11 (Debian 11.2.0-20) 11.2.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 as appropriate
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);
^
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* [tip: x86/fpu] x86/fpu: Cleanup variable shadowing
2022-04-26 12:25 arch/x86/kernel/fpu/xstate.c:1117:7: warning: Local variable 'mask' shadows outer variable [shadowVariable] kernel test robot
@ 2022-05-02 7:33 ` tip-bot2 for Thomas Gleixner
0 siblings, 0 replies; 2+ messages in thread
From: tip-bot2 for Thomas Gleixner @ 2022-05-02 7:33 UTC (permalink / raw)
To: linux-tip-commits; +Cc: kernel test robot, Thomas Gleixner, x86, linux-kernel
The following commit has been merged into the x86/fpu branch of tip:
Commit-ID: b91c0922bf1ed15b67a6faa404bc64e3ed532ec2
Gitweb: https://git.kernel.org/tip/b91c0922bf1ed15b67a6faa404bc64e3ed532ec2
Author: Thomas Gleixner <tglx@linutronix.de>
AuthorDate: Mon, 02 May 2022 09:20:42 +02:00
Committer: Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Mon, 02 May 2022 09:28:31 +02:00
x86/fpu: Cleanup variable shadowing
Addresses: warning: Local variable 'mask' shadows outer variable
Remove extra variable declaration and switch the bit mask assignment to use
BIT_ULL() while at it.
Fixes: 522e92743b35 ("x86/fpu: Deduplicate copy_uabi_from_user/kernel_to_xstate()")
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/lkml/202204262032.jFYKit5j-lkp@intel.com
---
arch/x86/kernel/fpu/xstate.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c
index 31c12f4..81fcd04 100644
--- a/arch/x86/kernel/fpu/xstate.c
+++ b/arch/x86/kernel/fpu/xstate.c
@@ -1233,7 +1233,7 @@ static int copy_uabi_to_xstate(struct fpstate *fpstate, const void *kbuf,
}
for (i = 0; i < XFEATURE_MAX; i++) {
- u64 mask = ((u64)1 << i);
+ mask = BIT_ULL(i);
if (hdr.xfeatures & mask) {
void *dst = __raw_xsave_addr(xsave, i);
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-05-02 7:34 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-26 12:25 arch/x86/kernel/fpu/xstate.c:1117:7: warning: Local variable 'mask' shadows outer variable [shadowVariable] kernel test robot
2022-05-02 7:33 ` [tip: x86/fpu] x86/fpu: Cleanup variable shadowing tip-bot2 for Thomas Gleixner
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.