From c365a2934ecaafdbb9721b6587a8a32b40b3715c Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Sat, 10 Dec 2016 02:56:44 +0000 Subject: [PATCH] Return a non-NULL owner only if the lock is exclusively held in owner_sx(). Fix some whitespace bugs while here. MFC after: 2 weeks --- sys/kern/kern_sx.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/sys/kern/kern_sx.c b/sys/kern/kern_sx.c index 9115d5a82ed..0036734caff 100644 --- a/sys/kern/kern_sx.c +++ b/sys/kern/kern_sx.c @@ -215,12 +215,14 @@ unlock_sx(struct lock_object *lock) int owner_sx(const struct lock_object *lock, struct thread **owner) { - const struct sx *sx = (const struct sx *)lock; - uintptr_t x = sx->sx_lock; + const struct sx *sx; + uintptr_t x; - *owner = (struct thread *)SX_OWNER(x); - return ((x & SX_LOCK_SHARED) != 0 ? (SX_SHARERS(x) != 0) : - (*owner != NULL)); + sx = (const struct sx *)lock; + x = sx->sx_lock; + *owner = NULL; + return ((x & SX_LOCK_SHARED) != 0 ? (SX_SHARERS(x) != 0) : + ((*owner = (struct thread *)SX_OWNER(x)) != NULL)); } #endif