Skip to content

Commit f9cd5f9

Browse files
nathanchancempe
authored andcommitted
powerpc: Avoid clang uninitialized warning in __get_user_size_allowed
Commit 9975f85 ("powerpc/uaccess: Remove calls to __get_user_bad() and __put_user_bad()") switch to BUILD_BUG() in the default case, which leaves x uninitialized. This will not be an issue because the build will be broken in that case but clang does static analysis before it realizes the default case will be done so it warns about x being uninitialized (trimmed for brevity): In file included from mm/mprotect.c:13: In file included from ./include/linux/hugetlb.h:28: In file included from ./include/linux/mempolicy.h:16: ./include/linux/pagemap.h:772:16: warning: variable '__gu_val' is used uninitialized whenever switch default is taken [-Wsometimes-uninitialized] if (unlikely(__get_user(c, uaddr) != 0)) ^~~~~~~~~~~~~~~~~~~~ ./arch/powerpc/include/asm/uaccess.h:266:2: note: expanded from macro '__get_user' __get_user_size_allowed(__gu_val, __gu_addr, __gu_size, __gu_err); \ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ./arch/powerpc/include/asm/uaccess.h:235:2: note: expanded from macro '__get_user_size_allowed' default: BUILD_BUG(); \ ^~~~~~~ Commit 5cd29b1 ("powerpc/uaccess: Use asm goto for get_user when compiler supports it") added an initialization for x because of the same reason. Do the same thing here so there is no warning across all versions of clang. Signed-off-by: Nathan Chancellor <[email protected]> Acked-by: Christophe Leroy <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: ClangBuiltLinux#1359 Link: https://lore.kernel.org/r/[email protected]
1 parent adb68c3 commit f9cd5f9

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

arch/powerpc/include/asm/uaccess.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ do { \
232232
case 2: __get_user_asm(x, (u16 __user *)ptr, retval, "lhz"); break; \
233233
case 4: __get_user_asm(x, (u32 __user *)ptr, retval, "lwz"); break; \
234234
case 8: __get_user_asm2(x, (u64 __user *)ptr, retval); break; \
235-
default: BUILD_BUG(); \
235+
default: x = 0; BUILD_BUG(); \
236236
} \
237237
} while (0)
238238

0 commit comments

Comments
 (0)