Skip to content

Commit b96bbdd

Browse files
Davidlohr Buesoingomolnar
authored andcommitted
locking/pvqspinlock: Robustify init_qspinlock_stat()
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>
1 parent dc209a3 commit b96bbdd

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

‎kernel/locking/qspinlock_stat.h‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,8 @@ static int __init init_qspinlock_stat(void)
212212
struct dentry *d_qstat = debugfs_create_dir("qlockstat", NULL);
213213
int i;
214214

215-
if (!d_qstat) {
216-
pr_warn("Could not create 'qlockstat' debugfs directory\n");
217-
return 0;
218-
}
215+
if (!d_qstat)
216+
goto out;
219217

220218
/*
221219
* Create the debugfs files
@@ -225,12 +223,20 @@ static int __init init_qspinlock_stat(void)
225223
* performance.
226224
*/
227225
for (i = 0; i < qstat_num; i++)
228-
debugfs_create_file(qstat_names[i], 0400, d_qstat,
229-
(void *)(long)i, &fops_qstat);
226+
if (!debugfs_create_file(qstat_names[i], 0400, d_qstat,
227+
(void *)(long)i, &fops_qstat))
228+
goto fail_undo;
229+
230+
if (!debugfs_create_file(qstat_names[qstat_reset_cnts], 0200, d_qstat,
231+
(void *)(long)qstat_reset_cnts, &fops_qstat))
232+
goto fail_undo;
230233

231-
debugfs_create_file(qstat_names[qstat_reset_cnts], 0200, d_qstat,
232-
(void *)(long)qstat_reset_cnts, &fops_qstat);
233234
return 0;
235+
fail_undo:
236+
debugfs_remove_recursive(d_qstat);
237+
out:
238+
pr_warn("Could not create 'qlockstat' debugfs entries\n");
239+
return -ENOMEM;
234240
}
235241
fs_initcall(init_qspinlock_stat);
236242

0 commit comments

Comments
 (0)