Skip to contentSkip to conversation

power: domain: no need to check return value of debugfs_create functions

PATCH In review Greg Kroah-Hartman 3 participants 7 messages Jan 22, 2019 – Jan 24, 2019

Subsystems (4)
lore
Share & tools
lore

Greg Kroah-Hartman

author maintainer
#0 lore raw

PATCH 1/1 power: domain: 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 "Rafael J. Wysocki" <[email protected]>
Cc Kevin Hilman <[email protected]>
Cc Ulf Hansson <[email protected]>
Cc Len Brown <[email protected]>
---
 drivers/base/power/domain.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/base/power/domain.c +2 -9
index 500de1dee967..45eafe8cf7dd 100644
@@ -2948,18 +2948,11 @@ static int __init genpd_debug_init(void)
 
 	genpd_debugfs_dir = debugfs_create_dir("pm_genpd", NULL);
 
-	if (!genpd_debugfs_dir)
-		return -ENOMEM;
-
-	d = debugfs_create_file("pm_genpd_summary", S_IRUGO,
-			genpd_debugfs_dir, NULL, &summary_fops);
-	if (!d)
-		return -ENOMEM;
+	debugfs_create_file("pm_genpd_summary", S_IRUGO, genpd_debugfs_dir,
+			    NULL, &summary_fops);
 
 	list_for_each_entry(genpd, &gpd_list, gpd_list_node) {
 		d = debugfs_create_dir(genpd->name, genpd_debugfs_dir);
-		if (!d)
-			return -ENOMEM;
 
 		debugfs_create_file("current_state", 0444,
 				d, genpd, &status_fops);
Signature · 1 line
2.20.1
#1 lore raw
Quoted 4 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.

Doesn't this boils done to whether we want to care to check if memory allocation failed?

Somewhere down the call chain from debugfs_create_dir(), we end up in alloc_inode() and it looks like that can fail, no?

Kind regards
Uffe

Quoted 39 lines
Cc "Rafael J. Wysocki" <[email protected]>
Cc Kevin Hilman <[email protected]>
Cc Ulf Hansson <[email protected]>
Cc Len Brown <[email protected]>
---
 drivers/base/power/domain.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/base/power/domain.c +2 -10
index 500de1dee967..45eafe8cf7dd 100644
@@ -2948,18 +2948,11 @@ static int __init genpd_debug_init(void)
 
        genpd_debugfs_dir = debugfs_create_dir("pm_genpd", NULL);
 
-       if (!genpd_debugfs_dir)
-               return -ENOMEM;
-
-       d = debugfs_create_file("pm_genpd_summary", S_IRUGO,
-                       genpd_debugfs_dir, NULL, &summary_fops);
-       if (!d)
-               return -ENOMEM;
+       debugfs_create_file("pm_genpd_summary", S_IRUGO, genpd_debugfs_dir,
+                           NULL, &summary_fops);
 
        list_for_each_entry(genpd, &gpd_list, gpd_list_node) {
                d = debugfs_create_dir(genpd->name, genpd_debugfs_dir);
-               if (!d)
-                       return -ENOMEM;
 
                debugfs_create_file("current_state", 0444,
                                d, genpd, &status_fops);
--

2.20.1

author maintainer
#2 lore raw
Quoted 9 lines · Ulf Hansson
Quoted 4 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.

Doesn't this boils done to whether we want to care to check if memory allocation failed?

You should not care.

Quoted 2 lines

Somewhere down the call chain from debugfs_create_dir(), we end up in alloc_inode() and it looks like that can fail, no?

Yes it can, right now it will return NULL, I'll go change that to return ENOMEM, but even then, your really do not care what happens as none of your other code flow should ever care about what debugfs does, or does not, do.

thanks,

greg k-h

#3 lore raw
Quoted 5 lines · Greg Kroah-Hartman
Quoted 3 lines · Ulf Hansson
Quoted 1 line · Greg Kroah-Hartman
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

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.

Doesn't this boils done to whether we want to care to check if memory allocation failed?

You should not care.

Okay.

Quoted 8 lines
Quoted 3 lines

Somewhere down the call chain from debugfs_create_dir(), we end up in alloc_inode() and it looks like that can fail, no?

Yes it can, right now it will return NULL, I'll go change that to return ENOMEM, but even then, your really do not care what happens as none of your other code flow should ever care about what debugfs does, or does not, do.

In that case, why don't we convert the debugfs_create_dir() and friends, to becomes "void" functions? Or maybe that's your plan going forward?

Kind regards
Uffe

author maintainer
#4 lore raw
Quoted 22 lines · Ulf Hansson
Quoted 5 lines · Greg Kroah-Hartman
Quoted 3 lines · Ulf Hansson
Quoted 1 line · Greg Kroah-Hartman
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

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.

Doesn't this boils done to whether we want to care to check if memory allocation failed?

You should not care.

Okay.

Quoted 4 lines
Quoted 3 lines

Somewhere down the call chain from debugfs_create_dir(), we end up in alloc_inode() and it looks like that can fail, no?

Quoted 8 lines
Quoted 4 lines

Yes it can, right now it will return NULL, I'll go change that to return ENOMEM, but even then, your really do not care what happens as none of your other code flow should ever care about what debugfs does, or does not, do.

In that case, why don't we convert the debugfs_create_dir() and friends, to becomes "void" functions? Or maybe that's your plan going forward?

I can't, as sometimes you actually care about using the return value in another debugfs call.

thanks,

greg k-h

Reviewed-by on v1 1/1
#5 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 "Rafael J. Wysocki" <[email protected]>
Cc Kevin Hilman <[email protected]>
Cc Ulf Hansson <[email protected]>
Cc Len Brown <[email protected]>

Kind regards
Uffe

Quoted 32 lines
---
 drivers/base/power/domain.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/base/power/domain.c +2 -10
index 500de1dee967..45eafe8cf7dd 100644
@@ -2948,18 +2948,11 @@ static int __init genpd_debug_init(void)
 
        genpd_debugfs_dir = debugfs_create_dir("pm_genpd", NULL);
 
-       if (!genpd_debugfs_dir)
-               return -ENOMEM;
-
-       d = debugfs_create_file("pm_genpd_summary", S_IRUGO,
-                       genpd_debugfs_dir, NULL, &summary_fops);
-       if (!d)
-               return -ENOMEM;
+       debugfs_create_file("pm_genpd_summary", S_IRUGO, genpd_debugfs_dir,
+                           NULL, &summary_fops);
 
        list_for_each_entry(genpd, &gpd_list, gpd_list_node) {
                d = debugfs_create_dir(genpd->name, genpd_debugfs_dir);
-               if (!d)
-                       return -ENOMEM;
 
                debugfs_create_file("current_state", 0444,
                                d, genpd, &status_fops);
--

2.20.1

#6 lore raw
Quoted 7 lines · CET Ulf Hansson
Quoted 5 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.

Quoted 8 lines
Quoted 6 lines
Cc "Rafael J. Wysocki" <[email protected]>
Cc Kevin Hilman <[email protected]>
Cc Ulf Hansson <[email protected]>
Cc Len Brown <[email protected]>

Patch applied, thanks!