lib: debugobjects: no need to check return value of debugfs_create functions
Subsystems (2)
PATCH 1/1 lib: debugobjects: 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.
--- lib/debugobjects.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-)
lib/debugobjects.c +2 -12
@@ -850,26 +850,16 @@ static const struct file_operations debug_stats_fops = {static int __init debug_objects_init_debugfs (void ) { -struct dentry *dbgdir, *dbgstats; +struct dentry *dbgdir;if (!debug_objects_enabled)return 0 ; dbgdir =debugfs_create_dir ("debug_objects" ,NULL ); -if (!dbgdir) -return -ENOMEM ; - dbgstats =debugfs_create_file ("stats" ,0444 , dbgdir,NULL , - &debug_stats_fops); -if (!dbgstats) - goto err; +debugfs_create_file ("stats" ,0444 , dbgdir,NULL , &debug_stats_fops);return 0 ; - -err: -debugfs_remove (dbgdir); - -return -ENOMEM ; }__initcall (debug_objects_init_debugfs);
Signature · 1 line
2.22.0
Quoted 29 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 Qian Cai <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Andrew Morton <[email protected]>Cc Waiman Long <[email protected]>Cc "Joel Fernandes (Google)" <[email protected]>Cc Zhong Jiang <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- lib/debugobjects.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-)lib/debugobjects.c +1
-1@@ -850,26 +850,16 @@ static const struct file_operations debug_stats_fops = {static int __init debug_objects_init_debugfs (void ) { -struct dentry *dbgdir, *dbgstats; +struct dentry *dbgdir;if (!debug_objects_enabled)return 0 ;
lib/debugobjects.c static const struct file_operations debug_stats_fops = { · line 860
Quoted 10 lines
lib/debugobjects.c +1
-6dbgdir =debugfs_create_dir ("debug_objects" ,NULL ); -if (!dbgdir) -return -ENOMEM ; - dbgstats =debugfs_create_file ("stats" ,0444 , dbgdir,NULL , - &debug_stats_fops); -if (!dbgstats) - goto err; +debugfs_create_file ("stats" ,0444 , dbgdir,NULL , &debug_stats_fops);
One weirdness is, if dbgdir is ever NULL, then debugfs_create_file() may end up creating the stats file in the root.
In debugfs_create_file():
/* If the parent is not specified, we create it in the root.
* We need the root dentry to do this, which is in the super
* block. A pointer to that is in the struct vfsmount that we
* have around.
*/
if (!parent)
parent = debugfs_mount->mnt_root;
But I guess that's not a major issue since its debugfs :-) So LGTM,
thanks,
- Joel
Quoted 13 lines
lib/debugobjects.c +0
-5return 0 ; - -err: -debugfs_remove (dbgdir); - -return -ENOMEM ; }__initcall (debug_objects_init_debugfs);Signature · 1 line
2.22.0
Quoted 35 lines · Joel Fernandes
Quoted 34 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 Qian Cai <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Andrew Morton <[email protected]>Cc Waiman Long <[email protected]>Cc "Joel Fernandes (Google)" <[email protected]>Cc Zhong Jiang <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- lib/debugobjects.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-)lib/debugobjects.c +1
-3@@ -850,26 +850,16 @@ static const struct file_operations debug_stats_fops = {static int __init debug_objects_init_debugfs (void ) { -struct dentry *dbgdir, *dbgstats; +struct dentry *dbgdir;if (!debug_objects_enabled)return 0 ; dbgdir =debugfs_create_dir ("debug_objects" ,NULL ); -if (!dbgdir) -return -ENOMEM ;
Quoted 9 lines
lib/debugobjects.c static const struct file_operations debug_stats_fops = { · line 860
Quoted 5 lines
lib/debugobjects.c +1
-4- dbgstats =debugfs_create_file ("stats" ,0444 , dbgdir,NULL , - &debug_stats_fops); -if (!dbgstats) - goto err; +debugfs_create_file ("stats" ,0444 , dbgdir,NULL , &debug_stats_fops);One weirdness is, if dbgdir is ever NULL, then
debugfs_create_file()may end up creating the stats file in the root.
Yes, but dbgdir can not be NULL.
Quoted 8 lines
In
debugfs_create_file():
/* If the parent is not specified, we create it in the root.
* We need the root dentry to do this, which is in the super
* block. A pointer to that is in the struct vfsmount that we
* have around.
*/
if (!parent)
parent =debugfs_mount->mnt_root;
Yes, but debugfs_create_dir() will never return NULL.
Quoted 1 line
But I guess that's not a major issue since its debugfs :-) So LGTM,
Yup!
Quoted 1 line
Reviewed-by Joel Fernandes (Google) <[email protected]>
thanks for the review.
greg k-h
Quoted 47 lines · Greg Kroah-Hartman
Quoted 35 lines · Joel Fernandes
Quoted 34 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 Qian Cai <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Andrew Morton <[email protected]>Cc Waiman Long <[email protected]>Cc "Joel Fernandes (Google)" <[email protected]>Cc Zhong Jiang <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- lib/debugobjects.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-)lib/debugobjects.c +1
-3@@ -850,26 +850,16 @@ static const struct file_operations debug_stats_fops = {static int __init debug_objects_init_debugfs (void ) { -struct dentry *dbgdir, *dbgstats; +struct dentry *dbgdir;if (!debug_objects_enabled)return 0 ; dbgdir =debugfs_create_dir ("debug_objects" ,NULL ); -if (!dbgdir) -return -ENOMEM ;Quoted 9 lines
lib/debugobjects.c static const struct file_operations debug_stats_fops = { · line 860
Quoted 5 lines
lib/debugobjects.c +1
-4- dbgstats =debugfs_create_file ("stats" ,0444 , dbgdir,NULL , - &debug_stats_fops); -if (!dbgstats) - goto err; +debugfs_create_file ("stats" ,0444 , dbgdir,NULL , &debug_stats_fops);One weirdness is, if dbgdir is ever NULL, then
debugfs_create_file()may end up creating the stats file in the root.
Quoted 1 line
Yes, but dbgdir can not be NULL.
Makes sense, thanks for clarification,
- Joel
tip-bot for Greg Kroah-Hartman
merge bot[tip:core/debugobjects] debugobjects: No need to check return value of debugfs_create()
In reply to Greg Kroah-Hartmandebugobjects: No need to check return value of debugfs_create()
Commit-ID: fecb0d95cdf752836cafdfffc1661f61ba4e2101 Gitweb: https://git.kernel.org/tip/fecb0d95cdf752836cafdfffc1661f61ba4e2101 Author: Greg Kroah-Hartman <[email protected]> AuthorDate: Wed, 12 Jun 2019 17:35:13 +0200 Committer: Thomas Gleixner <[email protected]> CommitDate: Fri, 14 Jun 2019 14:51:14 +0200
debugobjects: No need to check return value of debugfs_create()
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.
--- lib/debugobjects.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-)
lib/debugobjects.c +2 -12
@@ -850,26 +850,16 @@ static const struct file_operations debug_stats_fops = {static int __init debug_objects_init_debugfs (void ) { -struct dentry *dbgdir, *dbgstats; +struct dentry *dbgdir;if (!debug_objects_enabled)return 0 ; dbgdir =debugfs_create_dir ("debug_objects" ,NULL ); -if (!dbgdir) -return -ENOMEM ; - dbgstats =debugfs_create_file ("stats" ,0444 , dbgdir,NULL , - &debug_stats_fops); -if (!dbgstats) - goto err; +debugfs_create_file ("stats" ,0444 , dbgdir,NULL , &debug_stats_fops);return 0 ; - -err: -debugfs_remove (dbgdir); - -return -ENOMEM ; }__initcall (debug_objects_init_debugfs);