lib: dynamic_debug: no need to check return value of debugfs_create functions
Subsystems (2)
PATCH 1/1 lib: dynamic_debug: 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/dynamic_debug.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)
lib/dynamic_debug.c +3 -9
@@ -993,20 +993,14 @@ static __initdata int ddebug_init_success;static int __init dynamic_debug_init_debugfs (void ) { -struct dentry *dir, *file; +struct dentry *dir;if (!ddebug_init_success)return -ENODEV ; dir =debugfs_create_dir ("dynamic_debug" ,NULL ); -if (!dir) -return -ENOMEM ; - file =debugfs_create_file ("control" ,0644 , dir,NULL , - &ddebug_proc_fops); -if (!file) { -debugfs_remove (dir); -return -ENOMEM ; - } +debugfs_create_file ("control" ,0644 , dir,NULL , &ddebug_proc_fops); +return 0 ; }
Signature · 1 line
2.22.0
Jason Baron
maintainerQuoted 30 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 Jason Baron <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- lib/dynamic_debug.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)lib/dynamic_debug.c +1
-4@@ -993,20 +993,14 @@ static __initdata int ddebug_init_success;static int __init dynamic_debug_init_debugfs (void ) { -struct dentry *dir, *file; +struct dentry *dir;if (!ddebug_init_success)return -ENODEV ; dir =debugfs_create_dir ("dynamic_debug" ,NULL ); -if (!dir) -return -ENOMEM ; - file = debugfs_create_file("control", 0644, dir, NULL,
lib/dynamic_debug.c static __initdata int ddebug_init_success; · line 1006
Quoted 10 lines
lib/dynamic_debug.c +2
-5- &ddebug_proc_fops); -if (!file) { -debugfs_remove (dir); -return -ENOMEM ; - } +debugfs_create_file ("control" ,0644 , dir,NULL , &ddebug_proc_fops); +return 0 ; }
Looks like debugfs_create_dir() can return NULL, and in that case if its passed to debugfs_create_file() then the 'control' file ends up in the root of debugfs? I think its better to just not create the file then have it in the wrong place so maybe the file creation should be guarded by if(IS_ERR_OR_NULL(dir)).
Thanks,
-Jason
Quoted 35 lines · Jason Baron
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 Jason Baron <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- lib/dynamic_debug.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)lib/dynamic_debug.c +1
-9@@ -993,20 +993,14 @@ static __initdata int ddebug_init_success;static int __init dynamic_debug_init_debugfs (void ) { -struct dentry *dir, *file; +struct dentry *dir;if (!ddebug_init_success)return -ENODEV ; dir =debugfs_create_dir ("dynamic_debug" ,NULL ); -if (!dir) -return -ENOMEM ; - file =debugfs_create_file ("control" ,0644 , dir,NULL , - &ddebug_proc_fops); -if (!file) { -debugfs_remove (dir); -return -ENOMEM ; - }
Quoted 8 lines
lib/dynamic_debug.c static __initdata int ddebug_init_success; · line 1006
Quoted 6 lines
lib/dynamic_debug.c +2
-0+debugfs_create_file ("control" ,0644 , dir,NULL , &ddebug_proc_fops); +return 0 ; }Looks like
debugfs_create_dir()can return NULL,
No it can not.
Quoted 2 lines
and in that case if its passed to
debugfs_create_file()then the 'control' file ends up in the root of debugfs?
If it could, yes, that is what would happen.
Quoted 3 lines
I think its better to just not create the file then have it in the wrong place so maybe the file creation should be guarded by if(IS_ERR_OR_NULL(dir)).
As debugfs_create_dir() can not return NULL, you don't have to worry about this :)
thanks,
greg k-h
Quoted 45 lines · Greg Kroah-Hartman
Quoted 35 lines · Jason Baron
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 Jason Baron <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- lib/dynamic_debug.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)lib/dynamic_debug.c +1
-9@@ -993,20 +993,14 @@ static __initdata int ddebug_init_success;static int __init dynamic_debug_init_debugfs (void ) { -struct dentry *dir, *file; +struct dentry *dir;if (!ddebug_init_success)return -ENODEV ; dir =debugfs_create_dir ("dynamic_debug" ,NULL ); -if (!dir) -return -ENOMEM ; - file =debugfs_create_file ("control" ,0644 , dir,NULL , - &ddebug_proc_fops); -if (!file) { -debugfs_remove (dir); -return -ENOMEM ; - }Quoted 8 lines
lib/dynamic_debug.c static __initdata int ddebug_init_success; · line 1006
Quoted 6 lines
lib/dynamic_debug.c +2
-0+debugfs_create_file ("control" ,0644 , dir,NULL , &ddebug_proc_fops); +return 0 ; }Looks like
debugfs_create_dir()can return NULL,
Quoted 2 lines
No it can not.
Ok, I looked at the wrong definition for failed_creating() :( In that case:
Thanks,
-Jason
Quoted 48 lines · Jason Baron
Quoted 45 lines · Greg Kroah-Hartman
Quoted 43 lines · Jason Baron
Quoted 30 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 Jason Baron <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- lib/dynamic_debug.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)lib/dynamic_debug.c +1
-4@@ -993,20 +993,14 @@ static __initdata int ddebug_init_success;static int __init dynamic_debug_init_debugfs (void ) { -struct dentry *dir, *file; +struct dentry *dir;if (!ddebug_init_success)return -ENODEV ; dir =debugfs_create_dir ("dynamic_debug" ,NULL ); -if (!dir) -return -ENOMEM ; - file = debugfs_create_file("control", 0644, dir, NULL,lib/dynamic_debug.c static __initdata int ddebug_init_success; · line 1006
Quoted 10 lines
lib/dynamic_debug.c +2
-5- &ddebug_proc_fops); -if (!file) { -debugfs_remove (dir); -return -ENOMEM ; - } +debugfs_create_file ("control" ,0644 , dir,NULL , &ddebug_proc_fops); +return 0 ; }Looks like
debugfs_create_dir()can return NULL,
Quoted 4 lines
Quoted 2 lines
No it can not.
Ok, I looked at the wrong definition for
failed_creating():(
Yeah, tracefs should also probably change, it makes users of their api easier...
Quoted 3 lines
In that case:
Acked-by Jason Baron <[email protected]>
Wonderful, thanks for the review.
greg k-h