diff --git a/include/linux/lockdep_types.h b/include/linux/lockdep_types.h
index 9f361d3ab9d95d98428dbc9b25361c3ffe9e4e10..cb943f4b238569e2f5dbddd202e248710aa23f41 100644
--- a/include/linux/lockdep_types.h
+++ b/include/linux/lockdep_types.h
@@ -252,8 +252,8 @@ struct held_lock {
 	unsigned int check:1;       /* see lock_acquire() comment */
 	unsigned int hardirqs_off:1;
 	unsigned int sync:1;
-	unsigned int references:11;					/* 32 bits */
-	unsigned int pin_count;
+	unsigned int pin_count:11;					/* 32 bits */
+	unsigned int references;
 };
 
 #else /* !CONFIG_LOCKDEP */
diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index 4470680f022697f85da14cb2d78462ac02bafd9b..2b5c36dce94c26c34306474ed843bef4eb82e62c 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -5614,11 +5614,14 @@ static struct pin_cookie __lock_pin_lock(struct lockdep_map *lock)
 
 		if (match_held_lock(hlock, lock)) {
 			/*
-			 * Grab 16bits of randomness; this is sufficient to not
-			 * be guessable and still allows some pin nesting in
-			 * our u32 pin_count.
+			 * Grab 6bits of randomness; this is barely sufficient
+			 * to not be guessable and still allows some 32 levels
+			 * of pin nesting in our u11 pin_count.
 			 */
-			cookie.val = 1 + (sched_clock() & 0xffff);
+			cookie.val = 1 + (sched_clock() & 0x3f);
+			if (DEBUG_LOCKS_WARN_ON(hlock->pin_count + cookie.val >= 1 << 11))
+				return NIL_COOKIE;
+
 			hlock->pin_count += cookie.val;
 			return cookie;
 		}