OSDN Git Service

locking/atomic: cmpxchg: Make __generic_cmpxchg_local compare against zero-extended...
authorMatt Evans <mev@rivosinc.com>
Wed, 1 Feb 2023 18:39:48 +0000 (18:39 +0000)
committerArnd Bergmann <arnd@arndb.de>
Fri, 3 Feb 2023 14:31:23 +0000 (15:31 +0100)
commit6246541522845a443b7ae4a8f0e16facc5a91198
tree7dccf933fb3a592cf1abc68b044f637041e83d67
parent88603b6dc419445847923fcb7fe5080067a30f98
locking/atomic: cmpxchg: Make __generic_cmpxchg_local compare against zero-extended 'old' value

__generic_cmpxchg_local takes unsigned long old/new arguments which
might end up being up-cast from smaller signed types (which will
sign-extend).  The loaded compare value must be compared against a
truncated smaller type, so down-cast appropriately for each size.

The issue is apparent on 64-bit machines with code, such as
atomic_dec_unless_positive(), that sign-extends from int.

64-bit machines generally don't use the generic cmpxchg but
development/early ports might make use of it, so make it correct.

Signed-off-by: Matt Evans <mev@rivosinc.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
include/asm-generic/cmpxchg-local.h