aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ubifs
diff options
context:
space:
mode:
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2011-05-19 07:13:16 -0400
committerArtem Bityutskiy <dedekind1@gmail.com>2011-07-04 03:54:26 -0400
commitae380ce04731579f45f27b3a84d7d8d8ee1f9b1b (patch)
treef887f69b40899eb6bc5a61554da9485100ed2f89 /fs/ubifs
parent549c999a768a7a144c60a0faa58f34c48f39112b (diff)
UBIFS: lessen the size of debugging info data structure
This patch lessens the 'struct ubifs_debug_info' size by 90 bytes by allocating less bytes for the debugfs root directory name. It introduces macros for the name patter an length instead of hard-coding 100 bytes. It also makes UBIFS use 'snprintf()' and teaches it to gracefully catch situations when the name array is too short. Additionally, this patch makes 2 unrelated changes - I just thought they do not deserve separate commits: simplifies 'ubifs_assert()' for non-debugging case and makes 'dbg_debugfs_init()' properly verify debugfs return code which may be an error code or NULL, so we should you 'IS_ERR_OR_NULL()' instead of 'IS_ERR()'. Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Diffstat (limited to 'fs/ubifs')
-rw-r--r--fs/ubifs/debug.c18
-rw-r--r--fs/ubifs/debug.h11
2 files changed, 22 insertions, 7 deletions
diff --git a/fs/ubifs/debug.c b/fs/ubifs/debug.c
index 0bb2bcef0de9..c9609a63512e 100644
--- a/fs/ubifs/debug.c
+++ b/fs/ubifs/debug.c
@@ -2815,8 +2815,8 @@ static struct dentry *dfs_rootdir;
2815int dbg_debugfs_init(void) 2815int dbg_debugfs_init(void)
2816{ 2816{
2817 dfs_rootdir = debugfs_create_dir("ubifs", NULL); 2817 dfs_rootdir = debugfs_create_dir("ubifs", NULL);
2818 if (IS_ERR(dfs_rootdir)) { 2818 if (IS_ERR_OR_NULL(dfs_rootdir)) {
2819 int err = PTR_ERR(dfs_rootdir); 2819 int err = dfs_rootdir ? PTR_ERR(dfs_rootdir) : -ENODEV;
2820 ubifs_err("cannot create \"ubifs\" debugfs directory, " 2820 ubifs_err("cannot create \"ubifs\" debugfs directory, "
2821 "error %d\n", err); 2821 "error %d\n", err);
2822 return err; 2822 return err;
@@ -2880,12 +2880,20 @@ static const struct file_operations dfs_fops = {
2880 */ 2880 */
2881int dbg_debugfs_init_fs(struct ubifs_info *c) 2881int dbg_debugfs_init_fs(struct ubifs_info *c)
2882{ 2882{
2883 int err; 2883 int err, n;
2884 const char *fname; 2884 const char *fname;
2885 struct dentry *dent; 2885 struct dentry *dent;
2886 struct ubifs_debug_info *d = c->dbg; 2886 struct ubifs_debug_info *d = c->dbg;
2887 2887
2888 sprintf(d->dfs_dir_name, "ubi%d_%d", c->vi.ubi_num, c->vi.vol_id); 2888 n = snprintf(d->dfs_dir_name, UBIFS_DFS_DIR_LEN + 1, UBIFS_DFS_DIR_NAME,
2889 c->vi.ubi_num, c->vi.vol_id);
2890 if (n == UBIFS_DFS_DIR_LEN) {
2891 /* The array size is too small */
2892 fname = UBIFS_DFS_DIR_NAME;
2893 dent = ERR_PTR(-EINVAL);
2894 goto out;
2895 }
2896
2889 fname = d->dfs_dir_name; 2897 fname = d->dfs_dir_name;
2890 dent = debugfs_create_dir(fname, dfs_rootdir); 2898 dent = debugfs_create_dir(fname, dfs_rootdir);
2891 if (IS_ERR_OR_NULL(dent)) 2899 if (IS_ERR_OR_NULL(dent))
@@ -2916,7 +2924,7 @@ out_remove:
2916 debugfs_remove_recursive(d->dfs_dir); 2924 debugfs_remove_recursive(d->dfs_dir);
2917out: 2925out:
2918 err = dent ? PTR_ERR(dent) : -ENODEV; 2926 err = dent ? PTR_ERR(dent) : -ENODEV;
2919 ubifs_err("cannot create \"%s\" debugfs directory, error %d\n", 2927 ubifs_err("cannot create \"%s\" debugfs filr or directory, error %d\n",
2920 fname, err); 2928 fname, err);
2921 return err; 2929 return err;
2922} 2930}
diff --git a/fs/ubifs/debug.h b/fs/ubifs/debug.h
index a811ac4a26bb..b59c43a4149c 100644
--- a/fs/ubifs/debug.h
+++ b/fs/ubifs/debug.h
@@ -33,6 +33,13 @@ typedef int (*dbg_znode_callback)(struct ubifs_info *c,
33 33
34#include <linux/random.h> 34#include <linux/random.h>
35 35
36/*
37 * The UBIFS debugfs directory name pattern and maximum name length (3 for "ubi"
38 * + 1 for "_" and plus 2x2 for 2 UBI numbers and 1 for the trailing zero byte.
39 */
40#define UBIFS_DFS_DIR_NAME "ubi%d_%d"
41#define UBIFS_DFS_DIR_LEN (3 + 1 + 2*2 + 1)
42
36/** 43/**
37 * ubifs_debug_info - per-FS debugging information. 44 * ubifs_debug_info - per-FS debugging information.
38 * @old_zroot: old index root - used by 'dbg_check_old_index()' 45 * @old_zroot: old index root - used by 'dbg_check_old_index()'
@@ -84,7 +91,7 @@ struct ubifs_debug_info {
84 long long saved_free; 91 long long saved_free;
85 int saved_idx_gc_cnt; 92 int saved_idx_gc_cnt;
86 93
87 char dfs_dir_name[100]; 94 char dfs_dir_name[UBIFS_DFS_DIR_LEN + 1];
88 struct dentry *dfs_dir; 95 struct dentry *dfs_dir;
89 struct dentry *dfs_dump_lprops; 96 struct dentry *dfs_dump_lprops;
90 struct dentry *dfs_dump_budg; 97 struct dentry *dfs_dump_budg;
@@ -313,7 +320,7 @@ void dbg_debugfs_exit_fs(struct ubifs_info *c);
313 320
314/* Use "if (0)" to make compiler check arguments even if debugging is off */ 321/* Use "if (0)" to make compiler check arguments even if debugging is off */
315#define ubifs_assert(expr) do { \ 322#define ubifs_assert(expr) do { \
316 if (0 && (expr)) \ 323 if (0) \
317 printk(KERN_CRIT "UBIFS assert failed in %s at %u (pid %d)\n", \ 324 printk(KERN_CRIT "UBIFS assert failed in %s at %u (pid %d)\n", \
318 __func__, __LINE__, current->pid); \ 325 __func__, __LINE__, current->pid); \
319} while (0) 326} while (0)