watchdog: mei_wdt: no need to check return value of debugfs_create functions
Subsystems (2)
PATCH 1/1 watchdog: mei_wdt: 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/watchdog/mei_wdt.c | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-)
drivers/watchdog/mei_wdt.c +7 -23
@@ -539,38 +539,23 @@ static void dbgfs_unregister(struct mei_wdt *wdt) wdt->dbgfs_dir =NULL ; } -static int dbgfs_register (struct mei_wdt *wdt) +static void dbgfs_register (struct mei_wdt *wdt) { -struct dentry *dir, *f; +struct dentry *dir; dir =debugfs_create_dir (KBUILD_MODNAME ,NULL ); -if (!dir) -return -ENOMEM ; - wdt->dbgfs_dir = dir; - f =debugfs_create_file ("state" ,S_IRUSR , dir, wdt, &dbgfs_fops_state); -if (!f) - goto err; - f =debugfs_create_file ("activation" ,S_IRUSR , - dir, wdt, &dbgfs_fops_activation); -if (!f) - goto err; +debugfs_create_file ("state" ,S_IRUSR , dir, wdt, &dbgfs_fops_state); -return 0 ; -err: -dbgfs_unregister (wdt); -return -ENODEV ; +debugfs_create_file ("activation" ,S_IRUSR , dir, wdt, + &dbgfs_fops_activation); }#else static inline void dbgfs_unregister (struct mei_wdt *wdt) {} - -static inline int dbgfs_register (struct mei_wdt *wdt) -{ -return 0 ; -} +static inline void dbgfs_register (struct mei_wdt *wdt) {}#endif /* CONFIG_DEBUG_FS */ static int mei_wdt_probe(struct mei_cl_device *cldev,
@@ -623,8 +608,7 @@ static int mei_wdt_probe(struct mei_cl_device *cldev,if (ret) goto err_disable; -if (dbgfs_register (wdt)) -dev_warn (&cldev->dev,"cannot register debugfs\n" ); +dbgfs_register (wdt);return 0 ;
Signature · 1 line
2.22.0
Quoted 9 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 Tomas Winkler <[email protected]>Cc Wim Van Sebroeck <[email protected]>Cc Guenter Roeck <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>
Quoted 66 lines
--- drivers/watchdog/mei_wdt.c | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-)drivers/watchdog/mei_wdt.c +7
-23@@ -539,38 +539,23 @@ static void dbgfs_unregister(struct mei_wdt *wdt) wdt->dbgfs_dir =NULL ; } -static int dbgfs_register (struct mei_wdt *wdt) +static void dbgfs_register (struct mei_wdt *wdt) { -struct dentry *dir, *f; +struct dentry *dir; dir =debugfs_create_dir (KBUILD_MODNAME ,NULL ); -if (!dir) -return -ENOMEM ; - wdt->dbgfs_dir = dir; - f =debugfs_create_file ("state" ,S_IRUSR , dir, wdt, &dbgfs_fops_state); -if (!f) - goto err; - f =debugfs_create_file ("activation" ,S_IRUSR , - dir, wdt, &dbgfs_fops_activation); -if (!f) - goto err; +debugfs_create_file ("state" ,S_IRUSR , dir, wdt, &dbgfs_fops_state); -return 0 ; -err: -dbgfs_unregister (wdt); -return -ENODEV ; +debugfs_create_file ("activation" ,S_IRUSR , dir, wdt, + &dbgfs_fops_activation); }#else static inline void dbgfs_unregister (struct mei_wdt *wdt) {} - -static inline int dbgfs_register (struct mei_wdt *wdt) -{ -return 0 ; -} +static inline void dbgfs_register (struct mei_wdt *wdt) {}#endif /* CONFIG_DEBUG_FS */ static int mei_wdt_probe(struct mei_cl_device *cldev,@@ -623,8 +608,7 @@ static int mei_wdt_probe(struct mei_cl_device *cldev,if (ret) goto err_disable; -if (dbgfs_register (wdt)) -dev_warn (&cldev->dev,"cannot register debugfs\n" ); +dbgfs_register (wdt);return 0 ;Signature · 1 line
2.22.0
Quoted 22 lines
Reviewed-by Guenter Roeck <[email protected]>Quoted 18 lines
--- drivers/watchdog/mei_wdt.c | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-)drivers/watchdog/mei_wdt.c +2
-2@@ -539,38 +539,23 @@ static void dbgfs_unregister(struct mei_wdt *wdt) wdt->dbgfs_dir =NULL ; } -static int dbgfs_register (struct mei_wdt *wdt) +static void dbgfs_register (struct mei_wdt *wdt) { -struct dentry *dir, *f; +struct dentry *dir;
Quoted 3 lines
drivers/watchdog/mei_wdt.c static void dbgfs_unregister(struct mei_wdt *wdt) · line 548
Quoted 3 lines
drivers/watchdog/mei_wdt.c +0
-2dir =debugfs_create_dir (KBUILD_MODNAME ,NULL ); -if (!dir) -return -ENOMEM ;
If create dir fails but the consequent create file succeeds, I would guess this will be a mess in the debugs root directory. Also the tear down won't work as debugfs_remove_recursive will just bail out on NULL check.
Isn't it better just return here, when create_dir fails?
Quoted 44 lines
Quoted 44 lines
drivers/watchdog/mei_wdt.c +6
-19- wdt->dbgfs_dir = dir; - f =debugfs_create_file ("state" ,S_IRUSR , dir, wdt, &dbgfs_fops_state); -if (!f) - goto err; - f =debugfs_create_file ("activation" ,S_IRUSR , - dir, wdt, &dbgfs_fops_activation); -if (!f) - goto err; +debugfs_create_file ("state" ,S_IRUSR , dir, wdt, &dbgfs_fops_state); -return 0 ; -err: -dbgfs_unregister (wdt); -return -ENODEV ; +debugfs_create_file ("activation" ,S_IRUSR , dir, wdt, + &dbgfs_fops_activation); }#else static inline void dbgfs_unregister (struct mei_wdt *wdt) {} - -static inline int dbgfs_register(struct mei_wdt *wdt) -{ -return 0 ; -} +static inline void dbgfs_register (struct mei_wdt *wdt) {}#endif /* CONFIG_DEBUG_FS */ static int mei_wdt_probe(struct mei_cl_device *cldev, @@ -623,8 +608,7 @@ static int mei_wdt_probe(struct mei_cl_device *cldev, if (ret) goto err_disable; - if (dbgfs_register(wdt)) - dev_warn(&cldev->dev, "cannot register debugfs\n"); + dbgfs_register(wdt);return 0 ; --2.22.0
Quoted 22 lines · Tomas
Quoted 22 lines
Reviewed-by Guenter Roeck <[email protected]>Quoted 18 lines
--- drivers/watchdog/mei_wdt.c | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-)drivers/watchdog/mei_wdt.c +2
-2@@ -539,38 +539,23 @@ static void dbgfs_unregister(struct mei_wdt *wdt) wdt->dbgfs_dir =NULL ; } -static int dbgfs_register (struct mei_wdt *wdt) +static void dbgfs_register (struct mei_wdt *wdt) { -struct dentry *dir, *f; +struct dentry *dir;
Quoted 5 lines
Quoted 3 lines
drivers/watchdog/mei_wdt.c static void dbgfs_unregister(struct mei_wdt *wdt) · line 548
Quoted 3 lines
drivers/watchdog/mei_wdt.c +0
-2dir =debugfs_create_dir (KBUILD_MODNAME ,NULL ); -if (!dir) -return -ENOMEM ;If create dir fails but the consequent create file succeeds, I would guess this will be a mess in the debugs root directory.
Nope, debugfs_create_dir() can not return NULL, so no files will be created based on a -ERROR as a parent.
Quoted 2 lines
Also the tear down won't work as
debugfs_remove_recursivewill just bail out on NULL check.
Nope, NULL can not be returned from debugfs_create*() functions anymore.
Quoted 1 line
Isn't it better just return here, when
create_dirfails?
Nope, no need to :)
thanks,
greg k-h
Quoted 35 lines · Tomas
Quoted 8 lines
Quoted 8 lines
Reviewed-by Guenter Roeck <[email protected]>Quoted 4 lines
--- drivers/watchdog/mei_wdt.c | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-)Quoted 6 lines
Quoted 6 lines
drivers/watchdog/mei_wdt.c static void dbgfs_unregister(struct mei_wdt
Quoted 6 lines
(quoted diff) +0
-0
b/drivers/watchdog/mei_wdt.cindex8023cf28657a..96a770938ff0100644drivers/watchdog/mei_wdt.c +0
-0@@ -539,38 +539,23 @@ static void dbgfs_unregister(struct mei_wdt*wdt)
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/watchdog/mei_wdt.c +2
-2wdt->dbgfs_dir =NULL ; } -static int dbgfs_register (struct mei_wdt *wdt) +static void dbgfs_register (struct mei_wdt *wdt) { -struct dentry *dir, *f; +struct dentry *dir;Quoted 5 lines
Quoted 3 lines
drivers/watchdog/mei_wdt.c static void dbgfs_unregister(struct mei_wdt *wdt) · line 548
Quoted 3 lines
drivers/watchdog/mei_wdt.c +0
-2dir =debugfs_create_dir (KBUILD_MODNAME ,NULL ); -if (!dir) -return -ENOMEM ;If create dir fails but the consequent create file succeeds, I would guess this will be a mess in the debugs root directory.
Nope,
debugfs_create_dir()can not return NULL, so no files will be created based on a-ERRORas a parent.
Quoted 8 lines
Quoted 2 lines
Also the tear down won't work as
debugfs_remove_recursivewill just bail out on NULL check.Nope, NULL can not be returned from debugfs_create*() functions anymore.
Quoted 1 line
Isn't it better just return here, when
create_dirfails?Nope, no need to :)
I see, not a fun of those dirty tricks but I admit it streamlines the code. Ack
Thanks
Tomas