hlock->references = 2;
                        }
 
-                       return 1;
+                       return 2;
                }
        }
 
 }
 
 static int reacquire_held_locks(struct task_struct *curr, unsigned int depth,
-                             int idx)
+                               int idx, unsigned int *merged)
 {
        struct held_lock *hlock;
+       int first_idx = idx;
 
        if (DEBUG_LOCKS_WARN_ON(!irqs_disabled()))
                return 0;
 
        for (hlock = curr->held_locks + idx; idx < depth; idx++, hlock++) {
-               if (!__lock_acquire(hlock->instance,
+               switch (__lock_acquire(hlock->instance,
                                    hlock_class(hlock)->subclass,
                                    hlock->trylock,
                                    hlock->read, hlock->check,
                                    hlock->hardirqs_off,
                                    hlock->nest_lock, hlock->acquire_ip,
-                                   hlock->references, hlock->pin_count))
+                                   hlock->references, hlock->pin_count)) {
+               case 0:
                        return 1;
+               case 1:
+                       break;
+               case 2:
+                       *merged += (idx == first_idx);
+                       break;
+               default:
+                       WARN_ON(1);
+                       return 0;
+               }
        }
        return 0;
 }
                 unsigned long ip)
 {
        struct task_struct *curr = current;
+       unsigned int depth, merged = 0;
        struct held_lock *hlock;
        struct lock_class *class;
-       unsigned int depth;
        int i;
 
        if (unlikely(!debug_locks))
        curr->lockdep_depth = i;
        curr->curr_chain_key = hlock->prev_chain_key;
 
-       if (reacquire_held_locks(curr, depth, i))
+       if (reacquire_held_locks(curr, depth, i, &merged))
                return 0;
 
        /*
         * I took it apart and put it back together again, except now I have
         * these 'spare' parts.. where shall I put them.
         */
-       if (DEBUG_LOCKS_WARN_ON(curr->lockdep_depth != depth))
+       if (DEBUG_LOCKS_WARN_ON(curr->lockdep_depth != depth - merged))
                return 0;
        return 1;
 }
 static int __lock_downgrade(struct lockdep_map *lock, unsigned long ip)
 {
        struct task_struct *curr = current;
+       unsigned int depth, merged = 0;
        struct held_lock *hlock;
-       unsigned int depth;
        int i;
 
        if (unlikely(!debug_locks))
        hlock->read = 1;
        hlock->acquire_ip = ip;
 
-       if (reacquire_held_locks(curr, depth, i))
+       if (reacquire_held_locks(curr, depth, i, &merged))
+               return 0;
+
+       /* Merging can't happen with unchanged classes.. */
+       if (DEBUG_LOCKS_WARN_ON(merged))
                return 0;
 
        /*
         */
        if (DEBUG_LOCKS_WARN_ON(curr->lockdep_depth != depth))
                return 0;
+
        return 1;
 }
 
 __lock_release(struct lockdep_map *lock, unsigned long ip)
 {
        struct task_struct *curr = current;
+       unsigned int depth, merged = 1;
        struct held_lock *hlock;
-       unsigned int depth;
        int i;
 
        if (unlikely(!debug_locks))
        if (i == depth-1)
                return 1;
 
-       if (reacquire_held_locks(curr, depth, i + 1))
+       if (reacquire_held_locks(curr, depth, i + 1, &merged))
                return 0;
 
        /*
         * We had N bottles of beer on the wall, we drank one, but now
         * there's not N-1 bottles of beer left on the wall...
+        * Pouring two of the bottles together is acceptable.
         */
-       DEBUG_LOCKS_WARN_ON(curr->lockdep_depth != depth-1);
+       DEBUG_LOCKS_WARN_ON(curr->lockdep_depth != depth - merged);
 
        /*
         * Since reacquire_held_locks() would have called check_chain_key()