aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/ubi
diff options
context:
space:
mode:
authorEzequiel Garcia <elezegarcia@gmail.com>2012-11-28 07:18:30 -0500
committerArtem Bityutskiy <artem.bityutskiy@linux.intel.com>2012-12-10 06:38:59 -0500
commiteab737722ed6a5638f6251e83f0d293c2ffe549f (patch)
treeccac47deaa15cf48608352e73ded2dcf387c2737 /drivers/mtd/ubi
parent64575574f26d7969713ede9bde750c979da4037e (diff)
UBI: embed ubi_debug_info field in ubi_device struct
ubi_debug_info struct was dynamically allocated which is always suboptimal, for it tends to fragment memory and make the code error-prone. Fix this by embedding it in ubi_device struct. Signed-off-by: Ezequiel Garcia <elezegarcia@gmail.com> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Diffstat (limited to 'drivers/mtd/ubi')
-rw-r--r--drivers/mtd/ubi/build.c9
-rw-r--r--drivers/mtd/ubi/debug.c34
-rw-r--r--drivers/mtd/ubi/debug.h52
-rw-r--r--drivers/mtd/ubi/ubi.h40
4 files changed, 50 insertions, 85 deletions
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index fb59604854c9..a56133585e92 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -985,14 +985,10 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
985 if (!ubi->fm_buf) 985 if (!ubi->fm_buf)
986 goto out_free; 986 goto out_free;
987#endif 987#endif
988 err = ubi_debugging_init_dev(ubi);
989 if (err)
990 goto out_free;
991
992 err = ubi_attach(ubi, 0); 988 err = ubi_attach(ubi, 0);
993 if (err) { 989 if (err) {
994 ubi_err("failed to attach mtd%d, error %d", mtd->index, err); 990 ubi_err("failed to attach mtd%d, error %d", mtd->index, err);
995 goto out_debugging; 991 goto out_free;
996 } 992 }
997 993
998 if (ubi->autoresize_vol_id != -1) { 994 if (ubi->autoresize_vol_id != -1) {
@@ -1059,8 +1055,6 @@ out_detach:
1059 ubi_wl_close(ubi); 1055 ubi_wl_close(ubi);
1060 ubi_free_internal_volumes(ubi); 1056 ubi_free_internal_volumes(ubi);
1061 vfree(ubi->vtbl); 1057 vfree(ubi->vtbl);
1062out_debugging:
1063 ubi_debugging_exit_dev(ubi);
1064out_free: 1058out_free:
1065 vfree(ubi->peb_buf); 1059 vfree(ubi->peb_buf);
1066 vfree(ubi->fm_buf); 1060 vfree(ubi->fm_buf);
@@ -1138,7 +1132,6 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)
1138 ubi_free_internal_volumes(ubi); 1132 ubi_free_internal_volumes(ubi);
1139 vfree(ubi->vtbl); 1133 vfree(ubi->vtbl);
1140 put_mtd_device(ubi->mtd); 1134 put_mtd_device(ubi->mtd);
1141 ubi_debugging_exit_dev(ubi);
1142 vfree(ubi->peb_buf); 1135 vfree(ubi->peb_buf);
1143 vfree(ubi->fm_buf); 1136 vfree(ubi->fm_buf);
1144 ubi_msg("mtd%d is detached from ubi%d", ubi->mtd->index, ubi->ubi_num); 1137 ubi_msg("mtd%d is detached from ubi%d", ubi->mtd->index, ubi->ubi_num);
diff --git a/drivers/mtd/ubi/debug.c b/drivers/mtd/ubi/debug.c
index 26908a59506b..63cb1d7236ce 100644
--- a/drivers/mtd/ubi/debug.c
+++ b/drivers/mtd/ubi/debug.c
@@ -217,32 +217,6 @@ void ubi_dump_mkvol_req(const struct ubi_mkvol_req *req)
217 pr_err("\t1st 16 characters of name: %s\n", nm); 217 pr_err("\t1st 16 characters of name: %s\n", nm);
218} 218}
219 219
220/**
221 * ubi_debugging_init_dev - initialize debugging for an UBI device.
222 * @ubi: UBI device description object
223 *
224 * This function initializes debugging-related data for UBI device @ubi.
225 * Returns zero in case of success and a negative error code in case of
226 * failure.
227 */
228int ubi_debugging_init_dev(struct ubi_device *ubi)
229{
230 ubi->dbg = kzalloc(sizeof(struct ubi_debug_info), GFP_KERNEL);
231 if (!ubi->dbg)
232 return -ENOMEM;
233
234 return 0;
235}
236
237/**
238 * ubi_debugging_exit_dev - free debugging data for an UBI device.
239 * @ubi: UBI device description object
240 */
241void ubi_debugging_exit_dev(struct ubi_device *ubi)
242{
243 kfree(ubi->dbg);
244}
245
246/* 220/*
247 * Root directory for UBI stuff in debugfs. Contains sub-directories which 221 * Root directory for UBI stuff in debugfs. Contains sub-directories which
248 * contain the stuff specific to particular UBI devices. 222 * contain the stuff specific to particular UBI devices.
@@ -295,7 +269,7 @@ static ssize_t dfs_file_read(struct file *file, char __user *user_buf,
295 ubi = ubi_get_device(ubi_num); 269 ubi = ubi_get_device(ubi_num);
296 if (!ubi) 270 if (!ubi)
297 return -ENODEV; 271 return -ENODEV;
298 d = ubi->dbg; 272 d = &ubi->dbg;
299 273
300 if (dent == d->dfs_chk_gen) 274 if (dent == d->dfs_chk_gen)
301 val = d->chk_gen; 275 val = d->chk_gen;
@@ -341,7 +315,7 @@ static ssize_t dfs_file_write(struct file *file, const char __user *user_buf,
341 ubi = ubi_get_device(ubi_num); 315 ubi = ubi_get_device(ubi_num);
342 if (!ubi) 316 if (!ubi)
343 return -ENODEV; 317 return -ENODEV;
344 d = ubi->dbg; 318 d = &ubi->dbg;
345 319
346 buf_size = min_t(size_t, count, (sizeof(buf) - 1)); 320 buf_size = min_t(size_t, count, (sizeof(buf) - 1));
347 if (copy_from_user(buf, user_buf, buf_size)) { 321 if (copy_from_user(buf, user_buf, buf_size)) {
@@ -398,7 +372,7 @@ int ubi_debugfs_init_dev(struct ubi_device *ubi)
398 unsigned long ubi_num = ubi->ubi_num; 372 unsigned long ubi_num = ubi->ubi_num;
399 const char *fname; 373 const char *fname;
400 struct dentry *dent; 374 struct dentry *dent;
401 struct ubi_debug_info *d = ubi->dbg; 375 struct ubi_debug_info *d = &ubi->dbg;
402 376
403 if (!IS_ENABLED(CONFIG_DEBUG_FS)) 377 if (!IS_ENABLED(CONFIG_DEBUG_FS))
404 return 0; 378 return 0;
@@ -471,5 +445,5 @@ out:
471void ubi_debugfs_exit_dev(struct ubi_device *ubi) 445void ubi_debugfs_exit_dev(struct ubi_device *ubi)
472{ 446{
473 if (IS_ENABLED(CONFIG_DEBUG_FS)) 447 if (IS_ENABLED(CONFIG_DEBUG_FS))
474 debugfs_remove_recursive(ubi->dbg->dfs_dir); 448 debugfs_remove_recursive(ubi->dbg.dfs_dir);
475} 449}
diff --git a/drivers/mtd/ubi/debug.h b/drivers/mtd/ubi/debug.h
index 0add8d8a1672..33f8f3b2c9b2 100644
--- a/drivers/mtd/ubi/debug.h
+++ b/drivers/mtd/ubi/debug.h
@@ -60,51 +60,11 @@ void ubi_dump_aeb(const struct ubi_ainf_peb *aeb, int type);
60void ubi_dump_mkvol_req(const struct ubi_mkvol_req *req); 60void ubi_dump_mkvol_req(const struct ubi_mkvol_req *req);
61int ubi_self_check_all_ff(struct ubi_device *ubi, int pnum, int offset, 61int ubi_self_check_all_ff(struct ubi_device *ubi, int pnum, int offset,
62 int len); 62 int len);
63int ubi_debugging_init_dev(struct ubi_device *ubi);
64void ubi_debugging_exit_dev(struct ubi_device *ubi);
65int ubi_debugfs_init(void); 63int ubi_debugfs_init(void);
66void ubi_debugfs_exit(void); 64void ubi_debugfs_exit(void);
67int ubi_debugfs_init_dev(struct ubi_device *ubi); 65int ubi_debugfs_init_dev(struct ubi_device *ubi);
68void ubi_debugfs_exit_dev(struct ubi_device *ubi); 66void ubi_debugfs_exit_dev(struct ubi_device *ubi);
69 67
70/*
71 * The UBI debugfs directory name pattern and maximum name length (3 for "ubi"
72 * + 2 for the number plus 1 for the trailing zero byte.
73 */
74#define UBI_DFS_DIR_NAME "ubi%d"
75#define UBI_DFS_DIR_LEN (3 + 2 + 1)
76
77/**
78 * struct ubi_debug_info - debugging information for an UBI device.
79 *
80 * @chk_gen: if UBI general extra checks are enabled
81 * @chk_io: if UBI I/O extra checks are enabled
82 * @disable_bgt: disable the background task for testing purposes
83 * @emulate_bitflips: emulate bit-flips for testing purposes
84 * @emulate_io_failures: emulate write/erase failures for testing purposes
85 * @dfs_dir_name: name of debugfs directory containing files of this UBI device
86 * @dfs_dir: direntry object of the UBI device debugfs directory
87 * @dfs_chk_gen: debugfs knob to enable UBI general extra checks
88 * @dfs_chk_io: debugfs knob to enable UBI I/O extra checks
89 * @dfs_disable_bgt: debugfs knob to disable the background task
90 * @dfs_emulate_bitflips: debugfs knob to emulate bit-flips
91 * @dfs_emulate_io_failures: debugfs knob to emulate write/erase failures
92 */
93struct ubi_debug_info {
94 unsigned int chk_gen:1;
95 unsigned int chk_io:1;
96 unsigned int disable_bgt:1;
97 unsigned int emulate_bitflips:1;
98 unsigned int emulate_io_failures:1;
99 char dfs_dir_name[UBI_DFS_DIR_LEN + 1];
100 struct dentry *dfs_dir;
101 struct dentry *dfs_chk_gen;
102 struct dentry *dfs_chk_io;
103 struct dentry *dfs_disable_bgt;
104 struct dentry *dfs_emulate_bitflips;
105 struct dentry *dfs_emulate_io_failures;
106};
107
108/** 68/**
109 * ubi_dbg_is_bgt_disabled - if the background thread is disabled. 69 * ubi_dbg_is_bgt_disabled - if the background thread is disabled.
110 * @ubi: UBI device description object 70 * @ubi: UBI device description object
@@ -114,7 +74,7 @@ struct ubi_debug_info {
114 */ 74 */
115static inline int ubi_dbg_is_bgt_disabled(const struct ubi_device *ubi) 75static inline int ubi_dbg_is_bgt_disabled(const struct ubi_device *ubi)
116{ 76{
117 return ubi->dbg->disable_bgt; 77 return ubi->dbg.disable_bgt;
118} 78}
119 79
120/** 80/**
@@ -125,7 +85,7 @@ static inline int ubi_dbg_is_bgt_disabled(const struct ubi_device *ubi)
125 */ 85 */
126static inline int ubi_dbg_is_bitflip(const struct ubi_device *ubi) 86static inline int ubi_dbg_is_bitflip(const struct ubi_device *ubi)
127{ 87{
128 if (ubi->dbg->emulate_bitflips) 88 if (ubi->dbg.emulate_bitflips)
129 return !(random32() % 200); 89 return !(random32() % 200);
130 return 0; 90 return 0;
131} 91}
@@ -139,7 +99,7 @@ static inline int ubi_dbg_is_bitflip(const struct ubi_device *ubi)
139 */ 99 */
140static inline int ubi_dbg_is_write_failure(const struct ubi_device *ubi) 100static inline int ubi_dbg_is_write_failure(const struct ubi_device *ubi)
141{ 101{
142 if (ubi->dbg->emulate_io_failures) 102 if (ubi->dbg.emulate_io_failures)
143 return !(random32() % 500); 103 return !(random32() % 500);
144 return 0; 104 return 0;
145} 105}
@@ -153,18 +113,18 @@ static inline int ubi_dbg_is_write_failure(const struct ubi_device *ubi)
153 */ 113 */
154static inline int ubi_dbg_is_erase_failure(const struct ubi_device *ubi) 114static inline int ubi_dbg_is_erase_failure(const struct ubi_device *ubi)
155{ 115{
156 if (ubi->dbg->emulate_io_failures) 116 if (ubi->dbg.emulate_io_failures)
157 return !(random32() % 400); 117 return !(random32() % 400);
158 return 0; 118 return 0;
159} 119}
160 120
161static inline int ubi_dbg_chk_io(const struct ubi_device *ubi) 121static inline int ubi_dbg_chk_io(const struct ubi_device *ubi)
162{ 122{
163 return ubi->dbg->chk_io; 123 return ubi->dbg.chk_io;
164} 124}
165 125
166static inline int ubi_dbg_chk_gen(const struct ubi_device *ubi) 126static inline int ubi_dbg_chk_gen(const struct ubi_device *ubi)
167{ 127{
168 return ubi->dbg->chk_gen; 128 return ubi->dbg.chk_gen;
169} 129}
170#endif /* !__UBI_DEBUG_H__ */ 130#endif /* !__UBI_DEBUG_H__ */
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
index 7d57469723cf..8ea6297a208f 100644
--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -85,6 +85,13 @@
85#define UBI_UNKNOWN -1 85#define UBI_UNKNOWN -1
86 86
87/* 87/*
88 * The UBI debugfs directory name pattern and maximum name length (3 for "ubi"
89 * + 2 for the number plus 1 for the trailing zero byte.
90 */
91#define UBI_DFS_DIR_NAME "ubi%d"
92#define UBI_DFS_DIR_LEN (3 + 2 + 1)
93
94/*
88 * Error codes returned by the I/O sub-system. 95 * Error codes returned by the I/O sub-system.
89 * 96 *
90 * UBI_IO_FF: the read region of flash contains only 0xFFs 97 * UBI_IO_FF: the read region of flash contains only 0xFFs
@@ -342,6 +349,37 @@ struct ubi_volume_desc {
342struct ubi_wl_entry; 349struct ubi_wl_entry;
343 350
344/** 351/**
352 * struct ubi_debug_info - debugging information for an UBI device.
353 *
354 * @chk_gen: if UBI general extra checks are enabled
355 * @chk_io: if UBI I/O extra checks are enabled
356 * @disable_bgt: disable the background task for testing purposes
357 * @emulate_bitflips: emulate bit-flips for testing purposes
358 * @emulate_io_failures: emulate write/erase failures for testing purposes
359 * @dfs_dir_name: name of debugfs directory containing files of this UBI device
360 * @dfs_dir: direntry object of the UBI device debugfs directory
361 * @dfs_chk_gen: debugfs knob to enable UBI general extra checks
362 * @dfs_chk_io: debugfs knob to enable UBI I/O extra checks
363 * @dfs_disable_bgt: debugfs knob to disable the background task
364 * @dfs_emulate_bitflips: debugfs knob to emulate bit-flips
365 * @dfs_emulate_io_failures: debugfs knob to emulate write/erase failures
366 */
367struct ubi_debug_info {
368 unsigned int chk_gen:1;
369 unsigned int chk_io:1;
370 unsigned int disable_bgt:1;
371 unsigned int emulate_bitflips:1;
372 unsigned int emulate_io_failures:1;
373 char dfs_dir_name[UBI_DFS_DIR_LEN + 1];
374 struct dentry *dfs_dir;
375 struct dentry *dfs_chk_gen;
376 struct dentry *dfs_chk_io;
377 struct dentry *dfs_disable_bgt;
378 struct dentry *dfs_emulate_bitflips;
379 struct dentry *dfs_emulate_io_failures;
380};
381
382/**
345 * struct ubi_device - UBI device description structure 383 * struct ubi_device - UBI device description structure
346 * @dev: UBI device object to use the the Linux device model 384 * @dev: UBI device object to use the the Linux device model
347 * @cdev: character device object to create character device 385 * @cdev: character device object to create character device
@@ -545,7 +583,7 @@ struct ubi_device {
545 struct mutex buf_mutex; 583 struct mutex buf_mutex;
546 struct mutex ckvol_mutex; 584 struct mutex ckvol_mutex;
547 585
548 struct ubi_debug_info *dbg; 586 struct ubi_debug_info dbg;
549}; 587};
550 588
551/** 589/**