Skip to contentSkip to conversation

qspinlock: no need to check return value of debugfs_create functions

PATCH In review Greg Kroah-Hartman 3 participants 5 messages Jan 22, 2019 – Feb 1, 2019 Locking primitives

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qspinlock: no need to check return value of debugfs_create functions

When calling debugfs functions, there is no need to ever check the return value. The function can work or not, but the code logic should never do something different based on this.

Cc Peter Zijlstra <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Will Deacon <[email protected]>
---
 kernel/locking/qspinlock_stat.h | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)
kernel/locking/qspinlock_stat.h +4 -14
index 42d3d8dc8f49..766fa0c8c115 100644
@@ -213,9 +213,6 @@ static int __init init_qspinlock_stat(void)
 	struct dentry *d_qstat = debugfs_create_dir("qlockstat", NULL);
 	int i;
 
-	if (!d_qstat)
-		goto out;
-
 	/*
 	 * Create the debugfs files
 	 *
@@ -224,20 +221,13 @@ static int __init init_qspinlock_stat(void)
 	 * performance.
 	 */
 	for (i = 0; i < qstat_num; i++)
-		if (!debugfs_create_file(qstat_names[i], 0400, d_qstat,
-					 (void *)(long)i, &fops_qstat))
-			goto fail_undo;
+		debugfs_create_file(qstat_names[i], 0400, d_qstat,
+				    (void *)(long)i, &fops_qstat);
 
-	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);
 
Signature · 1 line
2.20.1
maintainer
#1 lore raw
Quoted 3 lines · Greg Kroah-Hartman

When calling debugfs functions, there is no need to ever check the return value. The function can work or not, but the code logic should never do something different based on this.

So I've seen you do a fair number of these patches; but I don't fully understand.

The existing code rolls back the created files such that we either have all files or none at all. Why is this wrong?

It for some daft reason one of the debugfs calls fails (imagine this was a module and we did modprobe while under memory pressure), why should we present a partial interface to the 'user' ?

Quoted 50 lines
Cc Peter Zijlstra <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Will Deacon <[email protected]>
---
 kernel/locking/qspinlock_stat.h | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)
kernel/locking/qspinlock_stat.h +4 -14
index 42d3d8dc8f49..766fa0c8c115 100644
@@ -213,9 +213,6 @@ static int __init init_qspinlock_stat(void)
 	struct dentry *d_qstat = debugfs_create_dir("qlockstat", NULL);
 	int i;
 
-	if (!d_qstat)
-		goto out;
-
 	/*
 	 * Create the debugfs files
 	 *
@@ -224,20 +221,13 @@ static int __init init_qspinlock_stat(void)
 	 * performance.
 	 */
 	for (i = 0; i < qstat_num; i++)
-		if (!debugfs_create_file(qstat_names[i], 0400, d_qstat,
-					 (void *)(long)i, &fops_qstat))
-			goto fail_undo;
+		debugfs_create_file(qstat_names[i], 0400, d_qstat,
+				    (void *)(long)i, &fops_qstat);
 
-	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);
 
Signature · 1 line
2.20.1
#2 lore raw

Sorry for the delay, got stuck with other things...

Quoted 10 lines · Peter Zijlstra
Quoted 3 lines · Greg Kroah-Hartman

When calling debugfs functions, there is no need to ever check the return value. The function can work or not, but the code logic should never do something different based on this.

So I've seen you do a fair number of these patches; but I don't fully understand.

The existing code rolls back the created files such that we either have all files or none at all. Why is this wrong?

Normally you should not care if debugfs files can, or can not, be created. So just call the debugfs code and move on. The worst case is where valid kernel code aborts just because debugging files could not be created for some reason, which is not ok.

Quoted 3 lines

It for some daft reason one of the debugfs calls fails (imagine this was a module and we did modprobe while under memory pressure), why should we present a partial interface to the 'user' ?

Because it's not an interface anyone should ever depend on :)

But, for some code, that only uses debugfs, maybe it does make sense to just abort the whole thing and keep going on. If this code should work that way, my mistake, let's leave it alone.

The overall goal with these patches is to make the code surrounding using debugfs easier and simpler. You should not need to handle any errors from debugfs, as it should never be used for anything that actually matters to the system, except when trying to debug it.

thanks,

greg k-h

#3 lore raw
In reply to Greg Kroah-Hartman
Quoted 11 lines · Greg Kroah-Hartman

When calling debugfs functions, there is no need to ever check the return value. The function can work or not, but the code logic should never do something different based on this.

Cc Peter Zijlstra <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Will Deacon <[email protected]>
---
 kernel/locking/qspinlock_stat.h | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)

Curious, but are you planning to make these functions return void after you've modified all of the callers?

Will

#4 lore raw
Quoted 13 lines · Will Deacon
Quoted 11 lines · Greg Kroah-Hartman

When calling debugfs functions, there is no need to ever check the return value. The function can work or not, but the code logic should never do something different based on this.

Cc Peter Zijlstra <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Will Deacon <[email protected]>
---
 kernel/locking/qspinlock_stat.h | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)
Quoted 2 lines

Curious, but are you planning to make these functions return void after you've modified all of the callers?

I wish, but I can't, as those values are needed for some other debugfs calls.

thanks,

greg k-h