lkdtm: no need to check return value of debugfs_create functions
Subsystems (2)
Greg Kroah-Hartman
maintainerPATCH 1/1 lkdtm: 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/misc/lkdtm/core.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-)
drivers/misc/lkdtm/core.c +2 -11
@@ -429,22 +429,13 @@ static int __init lkdtm_module_init(void)/* Register debugfs interface */ lkdtm_debugfs_root =debugfs_create_dir ("provoke-crash" ,NULL ); -if (!lkdtm_debugfs_root) { -pr_err ("creating root dir failed\n" ); -return -ENODEV ; - }/* Install debugfs trigger files. */ for (i =0 ; i <ARRAY_SIZE (crashpoints); i++) {struct crashpoint *cur = &crashpoints[i]; -struct dentry *de; - de =debugfs_create_file (cur->name,0644 , lkdtm_debugfs_root, - cur, &cur->fops); -if (de ==NULL ) { -pr_err ("could not create crashpoint %s\n" , cur->name); - goto out_err; - } +debugfs_create_file (cur->name,0644 , lkdtm_debugfs_root, cur, + &cur->fops); }/* Install crashpoint if one was selected. */
Signature · 1 line
2.22.0
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.
What is the user-visible feedback when, say, debugfs_create_file() fails? And what happens when debugfs_create_file() passes in a NULL root?
-Kees
Quoted 41 lines
Cc Kees Cook <[email protected]>Cc Arnd Bergmann <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- drivers/misc/lkdtm/core.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-)drivers/misc/lkdtm/core.c +2
-11@@ -429,22 +429,13 @@ static int __init lkdtm_module_init(void)/* Register debugfs interface */ lkdtm_debugfs_root =debugfs_create_dir ("provoke-crash" ,NULL ); -if (!lkdtm_debugfs_root) { -pr_err ("creating root dir failed\n" ); -return -ENODEV ; - }/* Install debugfs trigger files. */ for (i =0 ; i <ARRAY_SIZE (crashpoints); i++) {struct crashpoint *cur = &crashpoints[i]; -struct dentry *de; - de =debugfs_create_file (cur->name,0644 , lkdtm_debugfs_root, - cur, &cur->fops); -if (de ==NULL ) { -pr_err ("could not create crashpoint %s\n" , cur->name); - goto out_err; - } +debugfs_create_file (cur->name,0644 , lkdtm_debugfs_root, cur, + &cur->fops); }/* Install crashpoint if one was selected. */ Signature · 1 line
2.22.0
Signature · 1 line
Kees Cook
Greg Kroah-Hartman
maintainerQuoted 7 lines · Kees Cook
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.
What is the user-visible feedback when, say,
debugfs_create_file()fails?
All of the memory in your system is now gone and it would have long locked up a while before this call ever happened :)
And no user functionality should ever change if a debugfs call fails, or succeeds, this is debugging only.
Quoted 1 line
And what happens when
debugfs_create_file()passes in a NULL root?
The file ends up in the root of debugfs. But as this can only happen if the system is dead, I wouldn't worry about it.
thanks,
greg k-h
Quoted 8 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 Kees Cook <[email protected]>Cc Arnd Bergmann <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>
-Kees
Quoted 36 lines
--- drivers/misc/lkdtm/core.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-)drivers/misc/lkdtm/core.c +2
-11@@ -429,22 +429,13 @@ static int __init lkdtm_module_init(void)/* Register debugfs interface */ lkdtm_debugfs_root =debugfs_create_dir ("provoke-crash" ,NULL ); -if (!lkdtm_debugfs_root) { -pr_err ("creating root dir failed\n" ); -return -ENODEV ; - }/* Install debugfs trigger files. */ for (i =0 ; i <ARRAY_SIZE (crashpoints); i++) {struct crashpoint *cur = &crashpoints[i]; -struct dentry *de; - de =debugfs_create_file (cur->name,0644 , lkdtm_debugfs_root, - cur, &cur->fops); -if (de ==NULL ) { -pr_err ("could not create crashpoint %s\n" , cur->name); - goto out_err; - } +debugfs_create_file (cur->name,0644 , lkdtm_debugfs_root, cur, + &cur->fops); }/* Install crashpoint if one was selected. */ Signature · 1 line
2.22.0
Signature · 1 line
Kees Cook
Greg Kroah-Hartman
maintainerQuoted 11 lines · Kees Cook
Quoted 8 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 Kees Cook <[email protected]>Cc Arnd Bergmann <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>Acked-by Kees Cook <[email protected]>
Thanks for the review!
greg k-h