power: domain: no need to check return value of debugfs_create functions
Subsystems (4)
Greg Kroah-Hartman
maintainerPATCH 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.
--- drivers/base/power/domain.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/base/power/domain.c +2 -9
@@ -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
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]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- drivers/base/power/domain.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)drivers/base/power/domain.c +2
-10@@ -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
Greg Kroah-Hartman
maintainerQuoted 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 inalloc_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
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 inalloc_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
Greg Kroah-Hartman
maintainerQuoted 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 inalloc_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
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]>Signed-off-by Greg Kroah-Hartman <[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@@ -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
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]>Signed-off-by Greg Kroah-Hartman <[email protected]>Reviewed-by Ulf Hansson <[email protected]>
Patch applied, thanks!