return true;
 }
 
+/*
+ * Initialize the lock_classes[] array elements.
+ */
+static void init_data_structures_once(void)
+{
+       static bool initialization_happened;
+       int i;
+
+       if (likely(initialization_happened))
+               return;
+
+       initialization_happened = true;
+
+       for (i = 0; i < ARRAY_SIZE(lock_classes); i++) {
+               INIT_LIST_HEAD(&lock_classes[i].locks_after);
+               INIT_LIST_HEAD(&lock_classes[i].locks_before);
+       }
+}
+
 /*
  * Register a lock's class in the hash-table, if the class is not present
  * yet. Otherwise we look it up. We cache the result in the lock object
                        goto out_unlock_set;
        }
 
+       init_data_structures_once();
+
        /*
         * Allocate a new key from the static array, and add it to
         * the hash:
        class->key = key;
        class->name = lock->name;
        class->subclass = subclass;
-       INIT_LIST_HEAD(&class->locks_before);
-       INIT_LIST_HEAD(&class->locks_after);
+       WARN_ON_ONCE(!list_empty(&class->locks_before));
+       WARN_ON_ONCE(!list_empty(&class->locks_after));
        class->name_version = count_matching_names(class);
        /*
         * We use RCU's safe list-add method to make
        int i;
        int locked;
 
+       init_data_structures_once();
+
        raw_local_irq_save(flags);
        locked = graph_lock();
 
        unsigned long flags;
        int j, locked;
 
+       init_data_structures_once();
+
        raw_local_irq_save(flags);
        locked = graph_lock();