locking/pvqspinlock: Robustify init_qspinlock_stat()
authorDavidlohr Bueso <dave@stgolabs.net>
Wed, 20 Apr 2016 04:17:25 +0000 (21:17 -0700)
committerIngo Molnar <mingo@kernel.org>
Thu, 5 May 2016 07:58:51 +0000 (09:58 +0200)
Specifically around the debugfs file creation calls,
I have no idea if they could ever possibly fail, but
this is core code (debug aside) so lets at least
check the return value and inform anything fishy.

Signed-off-by: Davidlohr Bueso <dbueso@suse.de>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Waiman Long <Waiman.Long@hpe.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/20160420041725.GC3472@linux-uzut.site
Signed-off-by: Ingo Molnar <mingo@kernel.org>
kernel/locking/qspinlock_stat.h

index 72722334237a54818c9550f26de5fbeb96bf1d91..22e02530984574a6fee718aad26720516c34d497 100644 (file)
@@ -212,10 +212,8 @@ static int __init init_qspinlock_stat(void)
        struct dentry *d_qstat = debugfs_create_dir("qlockstat", NULL);
        int i;
 
-       if (!d_qstat) {
-               pr_warn("Could not create 'qlockstat' debugfs directory\n");
-               return 0;
-       }
+       if (!d_qstat)
+               goto out;
 
        /*
         * Create the debugfs files
@@ -225,12 +223,20 @@ static int __init init_qspinlock_stat(void)
         * performance.
         */
        for (i = 0; i < qstat_num; i++)
-               debugfs_create_file(qstat_names[i], 0400, d_qstat,
-                                  (void *)(long)i, &fops_qstat);
+               if (!debugfs_create_file(qstat_names[i], 0400, d_qstat,
+                                        (void *)(long)i, &fops_qstat))
+                       goto fail_undo;
+
+       if (!debugfs_create_file(qstat_names[qstat_reset_cnts], 0200, d_qstat,
+                                (void *)(long)qstat_reset_cnts, &fops_qstat))
+               goto fail_undo;
 
-       debugfs_create_file(qstat_names[qstat_reset_cnts], 0200, d_qstat,
-                          (void *)(long)qstat_reset_cnts, &fops_qstat);
        return 0;
+fail_undo:
+       debugfs_remove_recursive(d_qstat);
+out:
+       pr_warn("Could not create 'qlockstat' debugfs entries\n");
+       return -ENOMEM;
 }
 fs_initcall(init_qspinlock_stat);