summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2007-04-11 13:44:55 +0000
committerjhb <jhb@FreeBSD.org>2007-04-11 13:44:55 +0000
commit926c0ee8ef84a79a7ba03d0141571c7f57032647 (patch)
tree1e27fe35fc0370ac1717b0567700bead4a3ee84d
parentbea291208191bdab624311e8ca30e9b9374d3445 (diff)
downloadFreeBSD-src-926c0ee8ef84a79a7ba03d0141571c7f57032647.zip
FreeBSD-src-926c0ee8ef84a79a7ba03d0141571c7f57032647.tar.gz
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)
-rw-r--r--sys/sys/mutex.h18
1 files 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 { \
OpenPOWER on IntegriCloud