Commit 702d6a83 authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

ubifs: 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.

Cc: Richard Weinberger <richard@nod.at>
Cc: Artem Bityutskiy <dedekind1@gmail.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: linux-mtd@lists.infradead.org
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Link: https://lore.kernel.org/r/20190612152120.GA17450@kroah.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent f095adba
...@@ -2812,115 +2812,69 @@ static const struct file_operations dfs_fops = { ...@@ -2812,115 +2812,69 @@ static const struct file_operations dfs_fops = {
* dbg_debugfs_init_fs - initialize debugfs for UBIFS instance. * dbg_debugfs_init_fs - initialize debugfs for UBIFS instance.
* @c: UBIFS file-system description object * @c: UBIFS file-system description object
* *
* This function creates all debugfs files for this instance of UBIFS. Returns * This function creates all debugfs files for this instance of UBIFS.
* zero in case of success and a negative error code in case of failure.
* *
* Note, the only reason we have not merged this function with the * Note, the only reason we have not merged this function with the
* 'ubifs_debugging_init()' function is because it is better to initialize * 'ubifs_debugging_init()' function is because it is better to initialize
* debugfs interfaces at the very end of the mount process, and remove them at * debugfs interfaces at the very end of the mount process, and remove them at
* the very beginning of the mount process. * the very beginning of the mount process.
*/ */
int dbg_debugfs_init_fs(struct ubifs_info *c) void dbg_debugfs_init_fs(struct ubifs_info *c)
{ {
int err, n; int err, n;
const char *fname; const char *fname;
struct dentry *dent;
struct ubifs_debug_info *d = c->dbg; struct ubifs_debug_info *d = c->dbg;
if (!IS_ENABLED(CONFIG_DEBUG_FS))
return 0;
n = snprintf(d->dfs_dir_name, UBIFS_DFS_DIR_LEN + 1, UBIFS_DFS_DIR_NAME, n = snprintf(d->dfs_dir_name, UBIFS_DFS_DIR_LEN + 1, UBIFS_DFS_DIR_NAME,
c->vi.ubi_num, c->vi.vol_id); c->vi.ubi_num, c->vi.vol_id);
if (n == UBIFS_DFS_DIR_LEN) { if (n == UBIFS_DFS_DIR_LEN) {
/* The array size is too small */ /* The array size is too small */
fname = UBIFS_DFS_DIR_NAME; fname = UBIFS_DFS_DIR_NAME;
dent = ERR_PTR(-EINVAL); return;
goto out;
} }
fname = d->dfs_dir_name; fname = d->dfs_dir_name;
dent = debugfs_create_dir(fname, dfs_rootdir); d->dfs_dir = debugfs_create_dir(fname, dfs_rootdir);
if (IS_ERR_OR_NULL(dent))
goto out;
d->dfs_dir = dent;
fname = "dump_lprops"; fname = "dump_lprops";
dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, c, &dfs_fops); d->dfs_dump_lprops = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, c,
if (IS_ERR_OR_NULL(dent)) &dfs_fops);
goto out_remove;
d->dfs_dump_lprops = dent;
fname = "dump_budg"; fname = "dump_budg";
dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, c, &dfs_fops); d->dfs_dump_budg = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, c,
if (IS_ERR_OR_NULL(dent)) &dfs_fops);
goto out_remove;
d->dfs_dump_budg = dent;
fname = "dump_tnc"; fname = "dump_tnc";
dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, c, &dfs_fops); d->dfs_dump_tnc = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, c,
if (IS_ERR_OR_NULL(dent)) &dfs_fops);
goto out_remove;
d->dfs_dump_tnc = dent;
fname = "chk_general"; fname = "chk_general";
dent = debugfs_create_file(fname, S_IRUSR | S_IWUSR, d->dfs_dir, c, d->dfs_chk_gen = debugfs_create_file(fname, S_IRUSR | S_IWUSR,
&dfs_fops); d->dfs_dir, c, &dfs_fops);
if (IS_ERR_OR_NULL(dent))
goto out_remove;
d->dfs_chk_gen = dent;
fname = "chk_index"; fname = "chk_index";
dent = debugfs_create_file(fname, S_IRUSR | S_IWUSR, d->dfs_dir, c, d->dfs_chk_index = debugfs_create_file(fname, S_IRUSR | S_IWUSR,
&dfs_fops); d->dfs_dir, c, &dfs_fops);
if (IS_ERR_OR_NULL(dent))
goto out_remove;
d->dfs_chk_index = dent;
fname = "chk_orphans"; fname = "chk_orphans";
dent = debugfs_create_file(fname, S_IRUSR | S_IWUSR, d->dfs_dir, c, d->dfs_chk_orph = debugfs_create_file(fname, S_IRUSR | S_IWUSR,
&dfs_fops); d->dfs_dir, c, &dfs_fops);
if (IS_ERR_OR_NULL(dent))
goto out_remove;
d->dfs_chk_orph = dent;
fname = "chk_lprops"; fname = "chk_lprops";
dent = debugfs_create_file(fname, S_IRUSR | S_IWUSR, d->dfs_dir, c, d->dfs_chk_lprops = debugfs_create_file(fname, S_IRUSR | S_IWUSR,
&dfs_fops); d->dfs_dir, c, &dfs_fops);
if (IS_ERR_OR_NULL(dent))
goto out_remove;
d->dfs_chk_lprops = dent;
fname = "chk_fs"; fname = "chk_fs";
dent = debugfs_create_file(fname, S_IRUSR | S_IWUSR, d->dfs_dir, c, d->dfs_chk_fs = debugfs_create_file(fname, S_IRUSR | S_IWUSR,
&dfs_fops); d->dfs_dir, c, &dfs_fops);
if (IS_ERR_OR_NULL(dent))
goto out_remove;
d->dfs_chk_fs = dent;
fname = "tst_recovery"; fname = "tst_recovery";
dent = debugfs_create_file(fname, S_IRUSR | S_IWUSR, d->dfs_dir, c, d->dfs_tst_rcvry = debugfs_create_file(fname, S_IRUSR | S_IWUSR,
&dfs_fops); d->dfs_dir, c, &dfs_fops);
if (IS_ERR_OR_NULL(dent))
goto out_remove;
d->dfs_tst_rcvry = dent;
fname = "ro_error"; fname = "ro_error";
dent = debugfs_create_file(fname, S_IRUSR | S_IWUSR, d->dfs_dir, c, d->dfs_ro_error = debugfs_create_file(fname, S_IRUSR | S_IWUSR,
&dfs_fops); d->dfs_dir, c, &dfs_fops);
if (IS_ERR_OR_NULL(dent))
goto out_remove;
d->dfs_ro_error = dent;
return 0;
out_remove:
debugfs_remove_recursive(d->dfs_dir);
out:
err = dent ? PTR_ERR(dent) : -ENODEV;
ubifs_err(c, "cannot create \"%s\" debugfs file or directory, error %d\n",
fname, err);
return err;
} }
/** /**
...@@ -2929,8 +2883,7 @@ int dbg_debugfs_init_fs(struct ubifs_info *c) ...@@ -2929,8 +2883,7 @@ int dbg_debugfs_init_fs(struct ubifs_info *c)
*/ */
void dbg_debugfs_exit_fs(struct ubifs_info *c) void dbg_debugfs_exit_fs(struct ubifs_info *c)
{ {
if (IS_ENABLED(CONFIG_DEBUG_FS)) debugfs_remove_recursive(c->dbg->dfs_dir);
debugfs_remove_recursive(c->dbg->dfs_dir);
} }
struct ubifs_global_debug_info ubifs_dbg; struct ubifs_global_debug_info ubifs_dbg;
...@@ -3006,75 +2959,38 @@ static const struct file_operations dfs_global_fops = { ...@@ -3006,75 +2959,38 @@ static const struct file_operations dfs_global_fops = {
* *
* UBIFS uses debugfs file-system to expose various debugging knobs to * UBIFS uses debugfs file-system to expose various debugging knobs to
* user-space. This function creates "ubifs" directory in the debugfs * user-space. This function creates "ubifs" directory in the debugfs
* file-system. Returns zero in case of success and a negative error code in * file-system.
* case of failure.
*/ */
int dbg_debugfs_init(void) void dbg_debugfs_init(void)
{ {
int err;
const char *fname; const char *fname;
struct dentry *dent;
if (!IS_ENABLED(CONFIG_DEBUG_FS))
return 0;
fname = "ubifs"; fname = "ubifs";
dent = debugfs_create_dir(fname, NULL); dfs_rootdir = debugfs_create_dir(fname, NULL);
if (IS_ERR_OR_NULL(dent))
goto out;
dfs_rootdir = dent;
fname = "chk_general"; fname = "chk_general";
dent = debugfs_create_file(fname, S_IRUSR | S_IWUSR, dfs_rootdir, NULL, dfs_chk_gen = debugfs_create_file(fname, S_IRUSR | S_IWUSR, dfs_rootdir,
&dfs_global_fops); NULL, &dfs_global_fops);
if (IS_ERR_OR_NULL(dent))
goto out_remove;
dfs_chk_gen = dent;
fname = "chk_index"; fname = "chk_index";
dent = debugfs_create_file(fname, S_IRUSR | S_IWUSR, dfs_rootdir, NULL, dfs_chk_index = debugfs_create_file(fname, S_IRUSR | S_IWUSR,
&dfs_global_fops); dfs_rootdir, NULL, &dfs_global_fops);
if (IS_ERR_OR_NULL(dent))
goto out_remove;
dfs_chk_index = dent;
fname = "chk_orphans"; fname = "chk_orphans";
dent = debugfs_create_file(fname, S_IRUSR | S_IWUSR, dfs_rootdir, NULL, dfs_chk_orph = debugfs_create_file(fname, S_IRUSR | S_IWUSR,
&dfs_global_fops); dfs_rootdir, NULL, &dfs_global_fops);
if (IS_ERR_OR_NULL(dent))
goto out_remove;
dfs_chk_orph = dent;
fname = "chk_lprops"; fname = "chk_lprops";
dent = debugfs_create_file(fname, S_IRUSR | S_IWUSR, dfs_rootdir, NULL, dfs_chk_lprops = debugfs_create_file(fname, S_IRUSR | S_IWUSR,
&dfs_global_fops); dfs_rootdir, NULL, &dfs_global_fops);
if (IS_ERR_OR_NULL(dent))
goto out_remove;
dfs_chk_lprops = dent;
fname = "chk_fs"; fname = "chk_fs";
dent = debugfs_create_file(fname, S_IRUSR | S_IWUSR, dfs_rootdir, NULL, dfs_chk_fs = debugfs_create_file(fname, S_IRUSR | S_IWUSR, dfs_rootdir,
&dfs_global_fops); NULL, &dfs_global_fops);
if (IS_ERR_OR_NULL(dent))
goto out_remove;
dfs_chk_fs = dent;
fname = "tst_recovery"; fname = "tst_recovery";
dent = debugfs_create_file(fname, S_IRUSR | S_IWUSR, dfs_rootdir, NULL, dfs_tst_rcvry = debugfs_create_file(fname, S_IRUSR | S_IWUSR,
&dfs_global_fops); dfs_rootdir, NULL, &dfs_global_fops);
if (IS_ERR_OR_NULL(dent))
goto out_remove;
dfs_tst_rcvry = dent;
return 0;
out_remove:
debugfs_remove_recursive(dfs_rootdir);
out:
err = dent ? PTR_ERR(dent) : -ENODEV;
pr_err("UBIFS error (pid %d): cannot create \"%s\" debugfs file or directory, error %d\n",
current->pid, fname, err);
return err;
} }
/** /**
...@@ -3082,8 +2998,7 @@ int dbg_debugfs_init(void) ...@@ -3082,8 +2998,7 @@ int dbg_debugfs_init(void)
*/ */
void dbg_debugfs_exit(void) void dbg_debugfs_exit(void)
{ {
if (IS_ENABLED(CONFIG_DEBUG_FS)) debugfs_remove_recursive(dfs_rootdir);
debugfs_remove_recursive(dfs_rootdir);
} }
void ubifs_assert_failed(struct ubifs_info *c, const char *expr, void ubifs_assert_failed(struct ubifs_info *c, const char *expr,
......
...@@ -309,9 +309,9 @@ int dbg_leb_unmap(struct ubifs_info *c, int lnum); ...@@ -309,9 +309,9 @@ int dbg_leb_unmap(struct ubifs_info *c, int lnum);
int dbg_leb_map(struct ubifs_info *c, int lnum); int dbg_leb_map(struct ubifs_info *c, int lnum);
/* Debugfs-related stuff */ /* Debugfs-related stuff */
int dbg_debugfs_init(void); void dbg_debugfs_init(void);
void dbg_debugfs_exit(void); void dbg_debugfs_exit(void);
int dbg_debugfs_init_fs(struct ubifs_info *c); void dbg_debugfs_init_fs(struct ubifs_info *c);
void dbg_debugfs_exit_fs(struct ubifs_info *c); void dbg_debugfs_exit_fs(struct ubifs_info *c);
#endif /* !__UBIFS_DEBUG_H__ */ #endif /* !__UBIFS_DEBUG_H__ */
...@@ -1477,9 +1477,7 @@ static int mount_ubifs(struct ubifs_info *c) ...@@ -1477,9 +1477,7 @@ static int mount_ubifs(struct ubifs_info *c)
if (err) if (err)
goto out_infos; goto out_infos;
err = dbg_debugfs_init_fs(c); dbg_debugfs_init_fs(c);
if (err)
goto out_infos;
c->mounting = 0; c->mounting = 0;
...@@ -2364,9 +2362,7 @@ static int __init ubifs_init(void) ...@@ -2364,9 +2362,7 @@ static int __init ubifs_init(void)
if (err) if (err)
goto out_shrinker; goto out_shrinker;
err = dbg_debugfs_init(); dbg_debugfs_init();
if (err)
goto out_compr;
err = register_filesystem(&ubifs_fs_type); err = register_filesystem(&ubifs_fs_type);
if (err) { if (err) {
...@@ -2378,7 +2374,6 @@ static int __init ubifs_init(void) ...@@ -2378,7 +2374,6 @@ static int __init ubifs_init(void)
out_dbg: out_dbg:
dbg_debugfs_exit(); dbg_debugfs_exit();
out_compr:
ubifs_compressors_exit(); ubifs_compressors_exit();
out_shrinker: out_shrinker:
unregister_shrinker(&ubifs_shrinker_info); unregister_shrinker(&ubifs_shrinker_info);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment