It is not rare to spot empty lock chains in /proc/lockdep_chains, where only
shows irq_context but not the locks, which is useless and makes people
confused.

This happens because the chained lock classes are freeed, so consider this
when printing the lock chains.

Signed-off-by: Yuyang Du <[email protected]>
---
 kernel/locking/lockdep_proc.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
index 3d31f9b..47a6f4f 100644
--- a/kernel/locking/lockdep_proc.c
+++ b/kernel/locking/lockdep_proc.c
@@ -127,7 +127,7 @@ static int lc_show(struct seq_file *m, void *v)
 {
        struct lock_chain *chain = v;
        struct lock_class *class;
-       int i;
+       int i, nr_locks = 0;
 
        if (v == SEQ_START_TOKEN) {
                if (nr_chain_hlocks > MAX_LOCKDEP_CHAIN_HLOCKS)
@@ -136,18 +136,28 @@ static int lc_show(struct seq_file *m, void *v)
                return 0;
        }
 
-       seq_printf(m, "irq_context: %d\n", chain->irq_context);
-
        for (i = 0; i < chain->depth; i++) {
                class = lock_chain_get_class(chain, i);
+               /*
+                * Is this lock class zapped?
+                */
                if (!class->key)
                        continue;
 
+               if (!nr_locks++)
+                       seq_printf(m, "irq_context: %d\n", chain->irq_context);
+
                seq_printf(m, "[%p] ", class->key);
                print_name(m, class);
                seq_puts(m, "\n");
        }
-       seq_puts(m, "\n");
+
+       if (nr_locks) {
+               if (nr_locks != chain->depth)
+                       seq_printf(m, "(chain has %d zapped classes)\n",
+                                  chain->depth - nr_locks);
+               seq_puts(m, "\n");
+       }
 
        return 0;
 }
-- 
1.8.3.1

Reply via email to