Skip to content

Commit 1898300

Browse files
andreas-schwabpalmer-dabbelt
authored andcommitted
riscv/atomic: Do proper sign extension also for unsigned in arch_cmpxchg
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]>
1 parent c6ec1e1 commit 1898300

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
@@ -231,7 +231,7 @@
231231
__arch_cmpxchg(".w", ".w" sc_sfx, ".w" cas_sfx, \
232232
sc_prepend, sc_append, \
233233
cas_prepend, cas_append, \
234-
__ret, __ptr, (long), __old, __new); \
234+
__ret, __ptr, (long)(int)(long), __old, __new); \
235235
break; \
236236
case 8: \
237237
__arch_cmpxchg(".d", ".d" sc_sfx, ".d" cas_sfx, \

0 commit comments

Comments
 (0)