From a16ab3b093cc382b713b43bb54bb55f67ea218f6 Mon Sep 17 00:00:00 2001 From: Pawel Jakub Dawidek Date: Wed, 23 Jul 2008 11:17:46 +0000 Subject: [PATCH] Check for negative reference count. Reviewed by: des --- sys/sys/refcount.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/sys/sys/refcount.h b/sys/sys/refcount.h index 5316dd938f78..df4dd4126d24 100644 --- a/sys/sys/refcount.h +++ b/sys/sys/refcount.h @@ -32,6 +32,12 @@ #ifndef __SYS_REFCOUNT_H__ #define __SYS_REFCOUNT_H__ +#ifdef _KERNEL +#include +#else +#include +#define KASSERT(exp, msg) assert(exp) +#endif #include static __inline void @@ -51,9 +57,12 @@ refcount_acquire(volatile u_int *count) static __inline int refcount_release(volatile u_int *count) { + u_int old; /* XXX: Should this have a rel membar? */ - return (atomic_fetchadd_int(count, -1) == 1); + old = atomic_fetchadd_int(count, -1); + KASSERT(old > 0, ("negative refcount %p", count)); + return (old == 1); } #endif /* ! __SYS_REFCOUNT_H__ */