linuxkpi: Fix atomic_long_sub()
overflow
By (ab)using `atomic_long_add_return()`, `atomic_long_sub()` was making the atomic long overflow. Indeed the underlying FreeBSD atomic is based on an unsigned long. Reviewed by: manu Approved by: manu Differential Revision: https://reviews.freebsd.org/D38090
This commit is contained in:
parent
b99bc86232
commit
9491ea7c68
@ -41,7 +41,7 @@ typedef struct {
|
||||
} atomic_long_t;
|
||||
|
||||
#define atomic_long_add(i, v) atomic_long_add_return((i), (v))
|
||||
#define atomic_long_sub(i, v) atomic_long_add_return(-(i), (v))
|
||||
#define atomic_long_sub(i, v) atomic_long_sub_return((i), (v))
|
||||
#define atomic_long_inc_return(v) atomic_long_add_return(1, (v))
|
||||
#define atomic_long_inc_not_zero(v) atomic_long_add_unless((v), 1, 0)
|
||||
|
||||
@ -51,6 +51,12 @@ atomic_long_add_return(long i, atomic_long_t *v)
|
||||
return i + atomic_fetchadd_long(&v->counter, i);
|
||||
}
|
||||
|
||||
static inline long
|
||||
atomic_long_sub_return(long i, atomic_long_t *v)
|
||||
{
|
||||
return atomic_fetchadd_long(&v->counter, -i) - i;
|
||||
}
|
||||
|
||||
static inline void
|
||||
atomic_long_set(atomic_long_t *v, long i)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user