Skip to content

Commit 1fc00e1

Browse files
Sasha Levingregkh
authored andcommitted
riscv/atomic: Do proper sign extension also for unsigned in arch_cmpxchg
[ Upstream commit 1898300 ] Sign extend also an unsigned compare value to match what lr.w is doing. Otherwise try_cmpxchg may spuriously return true when used on a u32 value that has the sign bit set, as it happens often in inode_set_ctime_current. Do this in three conversion steps. The first conversion to long is needed to avoid a -Wpointer-to-int-cast warning when arch_cmpxchg is used with a pointer type. Then convert to int and back to long to always sign extend the 32-bit value to 64-bit. Fixes: 6c58f25 ("riscv/atomic: Fix sign extension for RV64I") Signed-off-by: Andreas Schwab <[email protected]> Reviewed-by: Alexandre Ghiti <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Tested-by: Xi Ruoyao <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent fbbb0e0 commit 1fc00e1

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

arch/riscv/include/asm/cmpxchg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@
169169
break; \
170170
case 4: \
171171
__arch_cmpxchg(".w", ".w" sc_sfx, prepend, append, \
172-
__ret, __ptr, (long), __old, __new); \
172+
__ret, __ptr, (long)(int)(long), __old, __new); \
173173
break; \
174174
case 8: \
175175
__arch_cmpxchg(".d", ".d" sc_sfx, prepend, append, \

0 commit comments

Comments
 (0)