changeset 758:de53a9548b85

synch: check synch type of locks Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
date Thu, 25 Jul 2019 12:32:27 -0400
parents ac902673ea0a
children 58ae4d8031a5
files synch.c
diffstat 1 files changed, 24 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/synch.c	Thu Jul 25 12:32:05 2019 -0400
+++ b/synch.c	Thu Jul 25 12:32:27 2019 -0400
@@ -393,12 +393,9 @@
 /*
  * state checking
  */
-static void check_lock_magic(struct lock *lock, const char *op,
-			     const struct lock_context *where)
+static void __bad_magic(struct lock *lock, const char *op,
+			const struct lock_context *where)
 {
-	if (lock->info.magic == (uintptr_t) &lock->info)
-		return;
-
 	cmn_err(CE_CRIT, "lockdep: thread trying to %s lock with bad magic", op);
 	print_lock(lock, where);
 #ifdef JEFFPC_LOCK_TRACKING
@@ -408,6 +405,28 @@
 	panic("lockdep: Aborting - bad lock magic");
 }
 
+static void __bad_type(struct lock *lock, const char *op,
+		       const struct lock_context *where)
+{
+	cmn_err(CE_CRIT, "lockdep: thread trying to %s lock with "
+		"mismatched synch type", op);
+	print_lock(lock, where);
+#ifdef JEFFPC_LOCK_TRACKING
+	cmn_err(CE_CRIT, "lockdep: while holding:");
+	print_held_locks(NULL);
+#endif
+	panic("lockdep: Aborting - mismatched synch type");
+}
+
+static void check_lock_magic(struct lock *lock, const char *op,
+			     const struct lock_context *where)
+{
+	if (lock->info.magic != (uintptr_t) &lock->info)
+		__bad_magic(lock, op, where);
+	else if (lock->info.type != SYNCH_TYPE_MUTEX)
+		__bad_type(lock, op, where);
+}
+
 static void check_rw_magic(struct rwlock *lock, const char *op,
 			   const struct lock_context *where)
 {