Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc: Fix duplicate const clang warning in user access code

This re-applies commit b91c1e3e7a6f ("powerpc: Fix duplicate const
clang warning in user access code") (Jun 2015) which was undone in
commits:
f2ca80905929 ("powerpc/sparse: Constify the address pointer in __get_user_nosleep()") (Feb 2017)
d466f6c5cac1 ("powerpc/sparse: Constify the address pointer in __get_user_nocheck()") (Feb 2017)
f84ed59a612d ("powerpc/sparse: Constify the address pointer in __get_user_check()") (Feb 2017)

We see a large number of duplicate const errors in the user access
code when building with llvm/clang:

include/linux/pagemap.h:576:8: warning: duplicate 'const' declaration specifier [-Wduplicate-decl-specifier]
ret = __get_user(c, uaddr);

The problem is we are doing const __typeof__(*(ptr)), which will hit
the warning if ptr is marked const.

Removing const does not seem to have any effect on GCC code
generation.

Signed-off-by: Anton Blanchard <anton@samba.org>
Signed-off-by: Joel Stanley <joel@jms.id.au>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>

authored by

Anton Blanchard and committed by
Michael Ellerman
e00d93ac ee9d21b3

+3 -3
+3 -3
arch/powerpc/include/asm/uaccess.h
··· 260 260 ({ \ 261 261 long __gu_err; \ 262 262 __long_type(*(ptr)) __gu_val; \ 263 - const __typeof__(*(ptr)) __user *__gu_addr = (ptr); \ 263 + __typeof__(*(ptr)) __user *__gu_addr = (ptr); \ 264 264 __chk_user_ptr(ptr); \ 265 265 if (!is_kernel_addr((unsigned long)__gu_addr)) \ 266 266 might_fault(); \ ··· 274 274 ({ \ 275 275 long __gu_err = -EFAULT; \ 276 276 __long_type(*(ptr)) __gu_val = 0; \ 277 - const __typeof__(*(ptr)) __user *__gu_addr = (ptr); \ 277 + __typeof__(*(ptr)) __user *__gu_addr = (ptr); \ 278 278 might_fault(); \ 279 279 if (access_ok(VERIFY_READ, __gu_addr, (size))) { \ 280 280 barrier_nospec(); \ ··· 288 288 ({ \ 289 289 long __gu_err; \ 290 290 __long_type(*(ptr)) __gu_val; \ 291 - const __typeof__(*(ptr)) __user *__gu_addr = (ptr); \ 291 + __typeof__(*(ptr)) __user *__gu_addr = (ptr); \ 292 292 __chk_user_ptr(ptr); \ 293 293 barrier_nospec(); \ 294 294 __get_user_size(__gu_val, __gu_addr, (size), __gu_err); \