Skip to content

Commit 7a5c2b7

Browse files
KAGA-KOKOgregkh
authored andcommitted
ARM: futex: Address build warning
[ Upstream commit 8101b5a ] Stephen reported the following build warning on a ARM multi_v7_defconfig build with GCC 9.2.1: kernel/futex.c: In function 'do_futex': kernel/futex.c:1676:17: warning: 'oldval' may be used uninitialized in this function [-Wmaybe-uninitialized] 1676 | return oldval == cmparg; | ~~~~~~~^~~~~~~~~ kernel/futex.c:1652:6: note: 'oldval' was declared here 1652 | int oldval, ret; | ^~~~~~ introduced by commit a08971e ("futex: arch_futex_atomic_op_inuser() calling conventions change"). While that change should not make any difference it confuses GCC which fails to work out that oldval is not referenced when the return value is not zero. GCC fails to properly analyze arch_futex_atomic_op_inuser(). It's not the early return, the issue is with the assembly macros. GCC fails to detect that those either set 'ret' to 0 and set oldval or set 'ret' to -EFAULT which makes oldval uninteresting. The store to the callsite supplied oldval pointer is conditional on ret == 0. The straight forward way to solve this is to make the store unconditional. Aside of addressing the build warning this makes sense anyway because it removes the conditional from the fastpath. In the error case the stored value is uninteresting and the extra store does not matter at all. Reported-by: Stephen Rothwell <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Sasha Levin <[email protected]>
1 parent e09cb4c commit 7a5c2b7

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

arch/arm/include/asm/futex.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,13 @@ arch_futex_atomic_op_inuser(int op, int oparg, int *oval, u32 __user *uaddr)
162162
preempt_enable();
163163
#endif
164164

165-
if (!ret)
166-
*oval = oldval;
165+
/*
166+
* Store unconditionally. If ret != 0 the extra store is the least
167+
* of the worries but GCC cannot figure out that __futex_atomic_op()
168+
* is either setting ret to -EFAULT or storing the old value in
169+
* oldval which results in a uninitialized warning at the call site.
170+
*/
171+
*oval = oldval;
167172

168173
return ret;
169174
}

0 commit comments

Comments
 (0)