From 926c0ee8ef84a79a7ba03d0141571c7f57032647 Mon Sep 17 00:00:00 2001 From: jhb Date: Wed, 11 Apr 2007 13:44:55 +0000 Subject: Group the loop to acquire/release Giant with the WITNESS_SAVE/RESTORE under a single conditional. The two operations are linked, but since the link is not very direct, Coverity can't see it. Humans might also miss the link as well. So, this isn't fixing any actual bugs, just improving readability. CID: 1787 (likely others as well) Found by: Coverity Prevent (tm) --- sys/sys/mutex.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/sys/sys/mutex.h b/sys/sys/mutex.h index 4116e38..caa1311 100644 --- a/sys/sys/mutex.h +++ b/sys/sys/mutex.h @@ -360,13 +360,14 @@ extern struct mtx Giant; #ifndef DROP_GIANT #define DROP_GIANT() \ do { \ - int _giantcnt; \ + int _giantcnt = 0; \ WITNESS_SAVE_DECL(Giant); \ \ - if (mtx_owned(&Giant)) \ + if (mtx_owned(&Giant)) { \ WITNESS_SAVE(&Giant.lock_object, Giant); \ - for (_giantcnt = 0; mtx_owned(&Giant); _giantcnt++) \ - mtx_unlock(&Giant) + for (_giantcnt = 0; mtx_owned(&Giant); _giantcnt++) \ + mtx_unlock(&Giant); \ + } #define PICKUP_GIANT() \ PARTIAL_PICKUP_GIANT(); \ @@ -374,10 +375,11 @@ do { \ #define PARTIAL_PICKUP_GIANT() \ mtx_assert(&Giant, MA_NOTOWNED); \ - while (_giantcnt--) \ - mtx_lock(&Giant); \ - if (mtx_owned(&Giant)) \ - WITNESS_RESTORE(&Giant.lock_object, Giant) + if (_giantcnt > 0) { \ + while (_giantcnt--) \ + mtx_lock(&Giant); \ + WITNESS_RESTORE(&Giant.lock_object, Giant); \ + } #endif #define UGAR(rval) do { \ -- cgit v1.1