diff options
Diffstat (limited to 'drivers/mtd')
-rw-r--r-- | drivers/mtd/ubi/build.c | 28 | ||||
-rw-r--r-- | drivers/mtd/ubi/debug.c | 269 | ||||
-rw-r--r-- | drivers/mtd/ubi/debug.h | 113 | ||||
-rw-r--r-- | drivers/mtd/ubi/io.c | 20 | ||||
-rw-r--r-- | drivers/mtd/ubi/scan.c | 2 | ||||
-rw-r--r-- | drivers/mtd/ubi/ubi.h | 8 | ||||
-rw-r--r-- | drivers/mtd/ubi/vmt.c | 2 | ||||
-rw-r--r-- | drivers/mtd/ubi/vtbl.c | 18 | ||||
-rw-r--r-- | drivers/mtd/ubi/wl.c | 42 |
9 files changed, 398 insertions, 104 deletions
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c index 65626c1c446d..6c3fb5ab20f5 100644 --- a/drivers/mtd/ubi/build.c +++ b/drivers/mtd/ubi/build.c | |||
@@ -953,10 +953,14 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset) | |||
953 | if (!ubi->peb_buf2) | 953 | if (!ubi->peb_buf2) |
954 | goto out_free; | 954 | goto out_free; |
955 | 955 | ||
956 | err = ubi_debugging_init_dev(ubi); | ||
957 | if (err) | ||
958 | goto out_free; | ||
959 | |||
956 | err = attach_by_scanning(ubi); | 960 | err = attach_by_scanning(ubi); |
957 | if (err) { | 961 | if (err) { |
958 | dbg_err("failed to attach by scanning, error %d", err); | 962 | dbg_err("failed to attach by scanning, error %d", err); |
959 | goto out_free; | 963 | goto out_debugging; |
960 | } | 964 | } |
961 | 965 | ||
962 | if (ubi->autoresize_vol_id != -1) { | 966 | if (ubi->autoresize_vol_id != -1) { |
@@ -969,12 +973,16 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset) | |||
969 | if (err) | 973 | if (err) |
970 | goto out_detach; | 974 | goto out_detach; |
971 | 975 | ||
976 | err = ubi_debugfs_init_dev(ubi); | ||
977 | if (err) | ||
978 | goto out_uif; | ||
979 | |||
972 | ubi->bgt_thread = kthread_create(ubi_thread, ubi, ubi->bgt_name); | 980 | ubi->bgt_thread = kthread_create(ubi_thread, ubi, ubi->bgt_name); |
973 | if (IS_ERR(ubi->bgt_thread)) { | 981 | if (IS_ERR(ubi->bgt_thread)) { |
974 | err = PTR_ERR(ubi->bgt_thread); | 982 | err = PTR_ERR(ubi->bgt_thread); |
975 | ubi_err("cannot spawn \"%s\", error %d", ubi->bgt_name, | 983 | ubi_err("cannot spawn \"%s\", error %d", ubi->bgt_name, |
976 | err); | 984 | err); |
977 | goto out_uif; | 985 | goto out_debugfs; |
978 | } | 986 | } |
979 | 987 | ||
980 | ubi_msg("attached mtd%d to ubi%d", mtd->index, ubi_num); | 988 | ubi_msg("attached mtd%d to ubi%d", mtd->index, ubi_num); |
@@ -1008,12 +1016,18 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset) | |||
1008 | ubi_notify_all(ubi, UBI_VOLUME_ADDED, NULL); | 1016 | ubi_notify_all(ubi, UBI_VOLUME_ADDED, NULL); |
1009 | return ubi_num; | 1017 | return ubi_num; |
1010 | 1018 | ||
1019 | out_debugfs: | ||
1020 | ubi_debugfs_exit_dev(ubi); | ||
1011 | out_uif: | 1021 | out_uif: |
1022 | get_device(&ubi->dev); | ||
1023 | ubi_assert(ref); | ||
1012 | uif_close(ubi); | 1024 | uif_close(ubi); |
1013 | out_detach: | 1025 | out_detach: |
1014 | ubi_wl_close(ubi); | 1026 | ubi_wl_close(ubi); |
1015 | free_internal_volumes(ubi); | 1027 | free_internal_volumes(ubi); |
1016 | vfree(ubi->vtbl); | 1028 | vfree(ubi->vtbl); |
1029 | out_debugging: | ||
1030 | ubi_debugging_exit_dev(ubi); | ||
1017 | out_free: | 1031 | out_free: |
1018 | vfree(ubi->peb_buf1); | 1032 | vfree(ubi->peb_buf1); |
1019 | vfree(ubi->peb_buf2); | 1033 | vfree(ubi->peb_buf2); |
@@ -1080,11 +1094,13 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway) | |||
1080 | */ | 1094 | */ |
1081 | get_device(&ubi->dev); | 1095 | get_device(&ubi->dev); |
1082 | 1096 | ||
1097 | ubi_debugfs_exit_dev(ubi); | ||
1083 | uif_close(ubi); | 1098 | uif_close(ubi); |
1084 | ubi_wl_close(ubi); | 1099 | ubi_wl_close(ubi); |
1085 | free_internal_volumes(ubi); | 1100 | free_internal_volumes(ubi); |
1086 | vfree(ubi->vtbl); | 1101 | vfree(ubi->vtbl); |
1087 | put_mtd_device(ubi->mtd); | 1102 | put_mtd_device(ubi->mtd); |
1103 | ubi_debugging_exit_dev(ubi); | ||
1088 | vfree(ubi->peb_buf1); | 1104 | vfree(ubi->peb_buf1); |
1089 | vfree(ubi->peb_buf2); | 1105 | vfree(ubi->peb_buf2); |
1090 | ubi_msg("mtd%d is detached from ubi%d", ubi->mtd->index, ubi->ubi_num); | 1106 | ubi_msg("mtd%d is detached from ubi%d", ubi->mtd->index, ubi->ubi_num); |
@@ -1199,6 +1215,11 @@ static int __init ubi_init(void) | |||
1199 | if (!ubi_wl_entry_slab) | 1215 | if (!ubi_wl_entry_slab) |
1200 | goto out_dev_unreg; | 1216 | goto out_dev_unreg; |
1201 | 1217 | ||
1218 | err = ubi_debugfs_init(); | ||
1219 | if (err) | ||
1220 | goto out_slab; | ||
1221 | |||
1222 | |||
1202 | /* Attach MTD devices */ | 1223 | /* Attach MTD devices */ |
1203 | for (i = 0; i < mtd_devs; i++) { | 1224 | for (i = 0; i < mtd_devs; i++) { |
1204 | struct mtd_dev_param *p = &mtd_dev_param[i]; | 1225 | struct mtd_dev_param *p = &mtd_dev_param[i]; |
@@ -1247,6 +1268,8 @@ out_detach: | |||
1247 | ubi_detach_mtd_dev(ubi_devices[k]->ubi_num, 1); | 1268 | ubi_detach_mtd_dev(ubi_devices[k]->ubi_num, 1); |
1248 | mutex_unlock(&ubi_devices_mutex); | 1269 | mutex_unlock(&ubi_devices_mutex); |
1249 | } | 1270 | } |
1271 | ubi_debugfs_exit(); | ||
1272 | out_slab: | ||
1250 | kmem_cache_destroy(ubi_wl_entry_slab); | 1273 | kmem_cache_destroy(ubi_wl_entry_slab); |
1251 | out_dev_unreg: | 1274 | out_dev_unreg: |
1252 | misc_deregister(&ubi_ctrl_cdev); | 1275 | misc_deregister(&ubi_ctrl_cdev); |
@@ -1270,6 +1293,7 @@ static void __exit ubi_exit(void) | |||
1270 | ubi_detach_mtd_dev(ubi_devices[i]->ubi_num, 1); | 1293 | ubi_detach_mtd_dev(ubi_devices[i]->ubi_num, 1); |
1271 | mutex_unlock(&ubi_devices_mutex); | 1294 | mutex_unlock(&ubi_devices_mutex); |
1272 | } | 1295 | } |
1296 | ubi_debugfs_exit(); | ||
1273 | kmem_cache_destroy(ubi_wl_entry_slab); | 1297 | kmem_cache_destroy(ubi_wl_entry_slab); |
1274 | misc_deregister(&ubi_ctrl_cdev); | 1298 | misc_deregister(&ubi_ctrl_cdev); |
1275 | class_remove_file(ubi_class, &ubi_version); | 1299 | class_remove_file(ubi_class, &ubi_version); |
diff --git a/drivers/mtd/ubi/debug.c b/drivers/mtd/ubi/debug.c index 2224cbe41ddf..ab80c0debac8 100644 --- a/drivers/mtd/ubi/debug.c +++ b/drivers/mtd/ubi/debug.c | |||
@@ -27,17 +27,9 @@ | |||
27 | #ifdef CONFIG_MTD_UBI_DEBUG | 27 | #ifdef CONFIG_MTD_UBI_DEBUG |
28 | 28 | ||
29 | #include "ubi.h" | 29 | #include "ubi.h" |
30 | #include <linux/debugfs.h> | ||
31 | #include <linux/uaccess.h> | ||
30 | #include <linux/module.h> | 32 | #include <linux/module.h> |
31 | #include <linux/moduleparam.h> | ||
32 | |||
33 | unsigned int ubi_chk_flags; | ||
34 | unsigned int ubi_tst_flags; | ||
35 | |||
36 | module_param_named(debug_chks, ubi_chk_flags, uint, S_IRUGO | S_IWUSR); | ||
37 | module_param_named(debug_tsts, ubi_chk_flags, uint, S_IRUGO | S_IWUSR); | ||
38 | |||
39 | MODULE_PARM_DESC(debug_chks, "Debug check flags"); | ||
40 | MODULE_PARM_DESC(debug_tsts, "Debug special test flags"); | ||
41 | 33 | ||
42 | /** | 34 | /** |
43 | * ubi_dbg_dump_ec_hdr - dump an erase counter header. | 35 | * ubi_dbg_dump_ec_hdr - dump an erase counter header. |
@@ -239,4 +231,261 @@ out: | |||
239 | return; | 231 | return; |
240 | } | 232 | } |
241 | 233 | ||
234 | /** | ||
235 | * ubi_debugging_init_dev - initialize debugging for an UBI device. | ||
236 | * @ubi: UBI device description object | ||
237 | * | ||
238 | * This function initializes debugging-related data for UBI device @ubi. | ||
239 | * Returns zero in case of success and a negative error code in case of | ||
240 | * failure. | ||
241 | */ | ||
242 | int ubi_debugging_init_dev(struct ubi_device *ubi) | ||
243 | { | ||
244 | ubi->dbg = kzalloc(sizeof(struct ubi_debug_info), GFP_KERNEL); | ||
245 | if (!ubi->dbg) | ||
246 | return -ENOMEM; | ||
247 | |||
248 | return 0; | ||
249 | } | ||
250 | |||
251 | /** | ||
252 | * ubi_debugging_exit_dev - free debugging data for an UBI device. | ||
253 | * @ubi: UBI device description object | ||
254 | */ | ||
255 | void ubi_debugging_exit_dev(struct ubi_device *ubi) | ||
256 | { | ||
257 | kfree(ubi->dbg); | ||
258 | } | ||
259 | |||
260 | /* | ||
261 | * Root directory for UBI stuff in debugfs. Contains sub-directories which | ||
262 | * contain the stuff specific to particular UBI devices. | ||
263 | */ | ||
264 | static struct dentry *dfs_rootdir; | ||
265 | |||
266 | /** | ||
267 | * ubi_debugfs_init - create UBI debugfs directory. | ||
268 | * | ||
269 | * Create UBI debugfs directory. Returns zero in case of success and a negative | ||
270 | * error code in case of failure. | ||
271 | */ | ||
272 | int ubi_debugfs_init(void) | ||
273 | { | ||
274 | dfs_rootdir = debugfs_create_dir("ubi", NULL); | ||
275 | if (IS_ERR_OR_NULL(dfs_rootdir)) { | ||
276 | int err = dfs_rootdir ? -ENODEV : PTR_ERR(dfs_rootdir); | ||
277 | |||
278 | ubi_err("cannot create \"ubi\" debugfs directory, error %d\n", | ||
279 | err); | ||
280 | return err; | ||
281 | } | ||
282 | |||
283 | return 0; | ||
284 | } | ||
285 | |||
286 | /** | ||
287 | * ubi_debugfs_exit - remove UBI debugfs directory. | ||
288 | */ | ||
289 | void ubi_debugfs_exit(void) | ||
290 | { | ||
291 | debugfs_remove(dfs_rootdir); | ||
292 | } | ||
293 | |||
294 | /* Read an UBI debugfs file */ | ||
295 | static ssize_t dfs_file_read(struct file *file, char __user *user_buf, | ||
296 | size_t count, loff_t *ppos) | ||
297 | { | ||
298 | unsigned long ubi_num = (unsigned long)file->private_data; | ||
299 | struct dentry *dent = file->f_path.dentry; | ||
300 | struct ubi_device *ubi; | ||
301 | struct ubi_debug_info *d; | ||
302 | char buf[3]; | ||
303 | int val; | ||
304 | |||
305 | ubi = ubi_get_device(ubi_num); | ||
306 | if (!ubi) | ||
307 | return -ENODEV; | ||
308 | d = ubi->dbg; | ||
309 | |||
310 | if (dent == d->dfs_chk_gen) | ||
311 | val = d->chk_gen; | ||
312 | else if (dent == d->dfs_chk_io) | ||
313 | val = d->chk_io; | ||
314 | else if (dent == d->dfs_disable_bgt) | ||
315 | val = d->disable_bgt; | ||
316 | else if (dent == d->dfs_emulate_bitflips) | ||
317 | val = d->emulate_bitflips; | ||
318 | else if (dent == d->dfs_emulate_io_failures) | ||
319 | val = d->emulate_io_failures; | ||
320 | else { | ||
321 | count = -EINVAL; | ||
322 | goto out; | ||
323 | } | ||
324 | |||
325 | if (val) | ||
326 | buf[0] = '1'; | ||
327 | else | ||
328 | buf[0] = '0'; | ||
329 | buf[1] = '\n'; | ||
330 | buf[2] = 0x00; | ||
331 | |||
332 | count = simple_read_from_buffer(user_buf, count, ppos, buf, 2); | ||
333 | |||
334 | out: | ||
335 | ubi_put_device(ubi); | ||
336 | return count; | ||
337 | } | ||
338 | |||
339 | /* Write an UBI debugfs file */ | ||
340 | static ssize_t dfs_file_write(struct file *file, const char __user *user_buf, | ||
341 | size_t count, loff_t *ppos) | ||
342 | { | ||
343 | unsigned long ubi_num = (unsigned long)file->private_data; | ||
344 | struct dentry *dent = file->f_path.dentry; | ||
345 | struct ubi_device *ubi; | ||
346 | struct ubi_debug_info *d; | ||
347 | size_t buf_size; | ||
348 | char buf[8]; | ||
349 | int val; | ||
350 | |||
351 | ubi = ubi_get_device(ubi_num); | ||
352 | if (!ubi) | ||
353 | return -ENODEV; | ||
354 | d = ubi->dbg; | ||
355 | |||
356 | buf_size = min_t(size_t, count, (sizeof(buf) - 1)); | ||
357 | if (copy_from_user(buf, user_buf, buf_size)) { | ||
358 | count = -EFAULT; | ||
359 | goto out; | ||
360 | } | ||
361 | |||
362 | if (buf[0] == '1') | ||
363 | val = 1; | ||
364 | else if (buf[0] == '0') | ||
365 | val = 0; | ||
366 | else { | ||
367 | count = -EINVAL; | ||
368 | goto out; | ||
369 | } | ||
370 | |||
371 | if (dent == d->dfs_chk_gen) | ||
372 | d->chk_gen = val; | ||
373 | else if (dent == d->dfs_chk_io) | ||
374 | d->chk_io = val; | ||
375 | else if (dent == d->dfs_disable_bgt) | ||
376 | d->disable_bgt = val; | ||
377 | else if (dent == d->dfs_emulate_bitflips) | ||
378 | d->emulate_bitflips = val; | ||
379 | else if (dent == d->dfs_emulate_io_failures) | ||
380 | d->emulate_io_failures = val; | ||
381 | else | ||
382 | count = -EINVAL; | ||
383 | |||
384 | out: | ||
385 | ubi_put_device(ubi); | ||
386 | return count; | ||
387 | } | ||
388 | |||
389 | static int default_open(struct inode *inode, struct file *file) | ||
390 | { | ||
391 | if (inode->i_private) | ||
392 | file->private_data = inode->i_private; | ||
393 | |||
394 | return 0; | ||
395 | } | ||
396 | |||
397 | /* File operations for all UBI debugfs files */ | ||
398 | static const struct file_operations dfs_fops = { | ||
399 | .read = dfs_file_read, | ||
400 | .write = dfs_file_write, | ||
401 | .open = default_open, | ||
402 | .llseek = no_llseek, | ||
403 | .owner = THIS_MODULE, | ||
404 | }; | ||
405 | |||
406 | /** | ||
407 | * ubi_debugfs_init_dev - initialize debugfs for an UBI device. | ||
408 | * @ubi: UBI device description object | ||
409 | * | ||
410 | * This function creates all debugfs files for UBI device @ubi. Returns zero in | ||
411 | * case of success and a negative error code in case of failure. | ||
412 | */ | ||
413 | int ubi_debugfs_init_dev(struct ubi_device *ubi) | ||
414 | { | ||
415 | int err, n; | ||
416 | unsigned long ubi_num = ubi->ubi_num; | ||
417 | const char *fname; | ||
418 | struct dentry *dent; | ||
419 | struct ubi_debug_info *d = ubi->dbg; | ||
420 | |||
421 | n = snprintf(d->dfs_dir_name, UBI_DFS_DIR_LEN + 1, UBI_DFS_DIR_NAME, | ||
422 | ubi->ubi_num); | ||
423 | if (n == UBI_DFS_DIR_LEN) { | ||
424 | /* The array size is too small */ | ||
425 | fname = UBI_DFS_DIR_NAME; | ||
426 | dent = ERR_PTR(-EINVAL); | ||
427 | goto out; | ||
428 | } | ||
429 | |||
430 | fname = d->dfs_dir_name; | ||
431 | dent = debugfs_create_dir(fname, dfs_rootdir); | ||
432 | if (IS_ERR_OR_NULL(dent)) | ||
433 | goto out; | ||
434 | d->dfs_dir = dent; | ||
435 | |||
436 | fname = "chk_gen"; | ||
437 | dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, (void *)ubi_num, | ||
438 | &dfs_fops); | ||
439 | if (IS_ERR_OR_NULL(dent)) | ||
440 | goto out_remove; | ||
441 | d->dfs_chk_gen = dent; | ||
442 | |||
443 | fname = "chk_io"; | ||
444 | dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, (void *)ubi_num, | ||
445 | &dfs_fops); | ||
446 | if (IS_ERR_OR_NULL(dent)) | ||
447 | goto out_remove; | ||
448 | d->dfs_chk_io = dent; | ||
449 | |||
450 | fname = "tst_disable_bgt"; | ||
451 | dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, (void *)ubi_num, | ||
452 | &dfs_fops); | ||
453 | if (IS_ERR_OR_NULL(dent)) | ||
454 | goto out_remove; | ||
455 | d->dfs_disable_bgt = dent; | ||
456 | |||
457 | fname = "tst_emulate_bitflips"; | ||
458 | dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, (void *)ubi_num, | ||
459 | &dfs_fops); | ||
460 | if (IS_ERR_OR_NULL(dent)) | ||
461 | goto out_remove; | ||
462 | d->dfs_emulate_bitflips = dent; | ||
463 | |||
464 | fname = "tst_emulate_io_failures"; | ||
465 | dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, (void *)ubi_num, | ||
466 | &dfs_fops); | ||
467 | if (IS_ERR_OR_NULL(dent)) | ||
468 | goto out_remove; | ||
469 | d->dfs_emulate_io_failures = dent; | ||
470 | |||
471 | return 0; | ||
472 | |||
473 | out_remove: | ||
474 | debugfs_remove_recursive(d->dfs_dir); | ||
475 | out: | ||
476 | err = dent ? PTR_ERR(dent) : -ENODEV; | ||
477 | ubi_err("cannot create \"%s\" debugfs file or directory, error %d\n", | ||
478 | fname, err); | ||
479 | return err; | ||
480 | } | ||
481 | |||
482 | /** | ||
483 | * dbg_debug_exit_dev - free all debugfs files corresponding to device @ubi | ||
484 | * @ubi: UBI device description object | ||
485 | */ | ||
486 | void ubi_debugfs_exit_dev(struct ubi_device *ubi) | ||
487 | { | ||
488 | debugfs_remove_recursive(ubi->dbg->dfs_dir); | ||
489 | } | ||
490 | |||
242 | #endif /* CONFIG_MTD_UBI_DEBUG */ | 491 | #endif /* CONFIG_MTD_UBI_DEBUG */ |
diff --git a/drivers/mtd/ubi/debug.h b/drivers/mtd/ubi/debug.h index 3f1a09c5c438..65b5b76cc379 100644 --- a/drivers/mtd/ubi/debug.h +++ b/drivers/mtd/ubi/debug.h | |||
@@ -21,14 +21,6 @@ | |||
21 | #ifndef __UBI_DEBUG_H__ | 21 | #ifndef __UBI_DEBUG_H__ |
22 | #define __UBI_DEBUG_H__ | 22 | #define __UBI_DEBUG_H__ |
23 | 23 | ||
24 | struct ubi_ec_hdr; | ||
25 | struct ubi_vid_hdr; | ||
26 | struct ubi_volume; | ||
27 | struct ubi_vtbl_record; | ||
28 | struct ubi_scan_volume; | ||
29 | struct ubi_scan_leb; | ||
30 | struct ubi_mkvol_req; | ||
31 | |||
32 | #ifdef CONFIG_MTD_UBI_DEBUG | 24 | #ifdef CONFIG_MTD_UBI_DEBUG |
33 | #include <linux/random.h> | 25 | #include <linux/random.h> |
34 | 26 | ||
@@ -71,86 +63,103 @@ void ubi_dbg_dump_sv(const struct ubi_scan_volume *sv); | |||
71 | void ubi_dbg_dump_seb(const struct ubi_scan_leb *seb, int type); | 63 | void ubi_dbg_dump_seb(const struct ubi_scan_leb *seb, int type); |
72 | void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req); | 64 | void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req); |
73 | void ubi_dbg_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len); | 65 | void ubi_dbg_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len); |
74 | |||
75 | extern unsigned int ubi_chk_flags; | ||
76 | |||
77 | /* | ||
78 | * Debugging check flags. | ||
79 | * | ||
80 | * UBI_CHK_GEN: general checks | ||
81 | * UBI_CHK_IO: check writes and erases | ||
82 | */ | ||
83 | enum { | ||
84 | UBI_CHK_GEN = 0x1, | ||
85 | UBI_CHK_IO = 0x2, | ||
86 | }; | ||
87 | |||
88 | int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len); | 66 | int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len); |
89 | int ubi_dbg_check_write(struct ubi_device *ubi, const void *buf, int pnum, | 67 | int ubi_dbg_check_write(struct ubi_device *ubi, const void *buf, int pnum, |
90 | int offset, int len); | 68 | int offset, int len); |
91 | 69 | int ubi_debugging_init_dev(struct ubi_device *ubi); | |
92 | extern unsigned int ubi_tst_flags; | 70 | void ubi_debugging_exit_dev(struct ubi_device *ubi); |
71 | int ubi_debugfs_init(void); | ||
72 | void ubi_debugfs_exit(void); | ||
73 | int ubi_debugfs_init_dev(struct ubi_device *ubi); | ||
74 | void ubi_debugfs_exit_dev(struct ubi_device *ubi); | ||
93 | 75 | ||
94 | /* | 76 | /* |
95 | * Special testing flags. | 77 | * The UBI debugfs directory name pattern and maximum name length (3 for "ubi" |
78 | * + 2 for the number plus 1 for the trailing zero byte. | ||
79 | */ | ||
80 | #define UBI_DFS_DIR_NAME "ubi%d" | ||
81 | #define UBI_DFS_DIR_LEN (3 + 2 + 1) | ||
82 | |||
83 | /** | ||
84 | * struct ubi_debug_info - debugging information for an UBI device. | ||
96 | * | 85 | * |
97 | * UBIFS_TST_DISABLE_BGT: disable the background thread | 86 | * @chk_gen: if UBI general extra checks are enabled |
98 | * UBI_TST_EMULATE_BITFLIPS: emulate bit-flips | 87 | * @chk_io: if UBI I/O extra checks are enabled |
99 | * UBI_TST_EMULATE_WRITE_FAILURES: emulate write failures | 88 | * @disable_bgt: disable the background task for testing purposes |
100 | * UBI_TST_EMULATE_ERASE_FAILURES: emulate erase failures | 89 | * @emulate_bitflips: emulate bit-flips for testing purposes |
90 | * @emulate_io_failures: emulate write/erase failures for testing purposes | ||
91 | * @dfs_dir_name: name of debugfs directory containing files of this UBI device | ||
92 | * @dfs_dir: direntry object of the UBI device debugfs directory | ||
93 | * @dfs_chk_gen: debugfs knob to enable UBI general extra checks | ||
94 | * @dfs_chk_io: debugfs knob to enable UBI I/O extra checks | ||
95 | * @dfs_disable_bgt: debugfs knob to disable the background task | ||
96 | * @dfs_emulate_bitflips: debugfs knob to emulate bit-flips | ||
97 | * @dfs_emulate_io_failures: debugfs knob to emulate write/erase failures | ||
101 | */ | 98 | */ |
102 | enum { | 99 | struct ubi_debug_info { |
103 | UBI_TST_DISABLE_BGT = 0x1, | 100 | unsigned int chk_gen:1; |
104 | UBI_TST_EMULATE_BITFLIPS = 0x2, | 101 | unsigned int chk_io:1; |
105 | UBI_TST_EMULATE_WRITE_FAILURES = 0x4, | 102 | unsigned int disable_bgt:1; |
106 | UBI_TST_EMULATE_ERASE_FAILURES = 0x8, | 103 | unsigned int emulate_bitflips:1; |
104 | unsigned int emulate_io_failures:1; | ||
105 | char dfs_dir_name[UBI_DFS_DIR_LEN + 1]; | ||
106 | struct dentry *dfs_dir; | ||
107 | struct dentry *dfs_chk_gen; | ||
108 | struct dentry *dfs_chk_io; | ||
109 | struct dentry *dfs_disable_bgt; | ||
110 | struct dentry *dfs_emulate_bitflips; | ||
111 | struct dentry *dfs_emulate_io_failures; | ||
107 | }; | 112 | }; |
108 | 113 | ||
109 | /** | 114 | /** |
110 | * ubi_dbg_is_bgt_disabled - if the background thread is disabled. | 115 | * ubi_dbg_is_bgt_disabled - if the background thread is disabled. |
116 | * @ubi: UBI device description object | ||
111 | * | 117 | * |
112 | * Returns non-zero if the UBI background thread is disabled for testing | 118 | * Returns non-zero if the UBI background thread is disabled for testing |
113 | * purposes. | 119 | * purposes. |
114 | */ | 120 | */ |
115 | static inline int ubi_dbg_is_bgt_disabled(void) | 121 | static inline int ubi_dbg_is_bgt_disabled(const struct ubi_device *ubi) |
116 | { | 122 | { |
117 | return ubi_tst_flags & UBI_TST_DISABLE_BGT; | 123 | return ubi->dbg->disable_bgt; |
118 | } | 124 | } |
119 | 125 | ||
120 | /** | 126 | /** |
121 | * ubi_dbg_is_bitflip - if it is time to emulate a bit-flip. | 127 | * ubi_dbg_is_bitflip - if it is time to emulate a bit-flip. |
128 | * @ubi: UBI device description object | ||
122 | * | 129 | * |
123 | * Returns non-zero if a bit-flip should be emulated, otherwise returns zero. | 130 | * Returns non-zero if a bit-flip should be emulated, otherwise returns zero. |
124 | */ | 131 | */ |
125 | static inline int ubi_dbg_is_bitflip(void) | 132 | static inline int ubi_dbg_is_bitflip(const struct ubi_device *ubi) |
126 | { | 133 | { |
127 | if (ubi_tst_flags & UBI_TST_EMULATE_BITFLIPS) | 134 | if (ubi->dbg->emulate_bitflips) |
128 | return !(random32() % 200); | 135 | return !(random32() % 200); |
129 | return 0; | 136 | return 0; |
130 | } | 137 | } |
131 | 138 | ||
132 | /** | 139 | /** |
133 | * ubi_dbg_is_write_failure - if it is time to emulate a write failure. | 140 | * ubi_dbg_is_write_failure - if it is time to emulate a write failure. |
141 | * @ubi: UBI device description object | ||
134 | * | 142 | * |
135 | * Returns non-zero if a write failure should be emulated, otherwise returns | 143 | * Returns non-zero if a write failure should be emulated, otherwise returns |
136 | * zero. | 144 | * zero. |
137 | */ | 145 | */ |
138 | static inline int ubi_dbg_is_write_failure(void) | 146 | static inline int ubi_dbg_is_write_failure(const struct ubi_device *ubi) |
139 | { | 147 | { |
140 | if (ubi_tst_flags & UBI_TST_EMULATE_WRITE_FAILURES) | 148 | if (ubi->dbg->emulate_io_failures) |
141 | return !(random32() % 500); | 149 | return !(random32() % 500); |
142 | return 0; | 150 | return 0; |
143 | } | 151 | } |
144 | 152 | ||
145 | /** | 153 | /** |
146 | * ubi_dbg_is_erase_failure - if its time to emulate an erase failure. | 154 | * ubi_dbg_is_erase_failure - if its time to emulate an erase failure. |
155 | * @ubi: UBI device description object | ||
147 | * | 156 | * |
148 | * Returns non-zero if an erase failure should be emulated, otherwise returns | 157 | * Returns non-zero if an erase failure should be emulated, otherwise returns |
149 | * zero. | 158 | * zero. |
150 | */ | 159 | */ |
151 | static inline int ubi_dbg_is_erase_failure(void) | 160 | static inline int ubi_dbg_is_erase_failure(const struct ubi_device *ubi) |
152 | { | 161 | { |
153 | if (ubi_tst_flags & UBI_TST_EMULATE_ERASE_FAILURES) | 162 | if (ubi->dbg->emulate_io_failures) |
154 | return !(random32() % 400); | 163 | return !(random32() % 400); |
155 | return 0; | 164 | return 0; |
156 | } | 165 | } |
@@ -201,11 +210,6 @@ static inline void ubi_dbg_dump_flash(struct ubi_device *ubi, | |||
201 | static inline void | 210 | static inline void |
202 | ubi_dbg_print_hex_dump(const char *l, const char *ps, int pt, int r, | 211 | ubi_dbg_print_hex_dump(const char *l, const char *ps, int pt, int r, |
203 | int g, const void *b, size_t len, bool a) { return; } | 212 | int g, const void *b, size_t len, bool a) { return; } |
204 | |||
205 | static inline int ubi_dbg_is_bgt_disabled(void) { return 0; } | ||
206 | static inline int ubi_dbg_is_bitflip(void) { return 0; } | ||
207 | static inline int ubi_dbg_is_write_failure(void) { return 0; } | ||
208 | static inline int ubi_dbg_is_erase_failure(void) { return 0; } | ||
209 | static inline int ubi_dbg_check_all_ff(struct ubi_device *ubi, | 213 | static inline int ubi_dbg_check_all_ff(struct ubi_device *ubi, |
210 | int pnum, int offset, | 214 | int pnum, int offset, |
211 | int len) { return 0; } | 215 | int len) { return 0; } |
@@ -213,5 +217,20 @@ static inline int ubi_dbg_check_write(struct ubi_device *ubi, | |||
213 | const void *buf, int pnum, | 217 | const void *buf, int pnum, |
214 | int offset, int len) { return 0; } | 218 | int offset, int len) { return 0; } |
215 | 219 | ||
220 | static inline int ubi_debugging_init_dev(struct ubi_device *ubi) { return 0; } | ||
221 | static inline void ubi_debugging_exit_dev(struct ubi_device *ubi) { return; } | ||
222 | static inline int ubi_debugfs_init(void) { return 0; } | ||
223 | static inline void ubi_debugfs_exit(void) { return; } | ||
224 | static inline int ubi_debugfs_init_dev(struct ubi_device *ubi) { return 0; } | ||
225 | static inline void ubi_debugfs_exit_dev(struct ubi_device *ubi) { return; } | ||
226 | |||
227 | static inline int | ||
228 | ubi_dbg_is_bgt_disabled(const struct ubi_device *ubi) { return 0; } | ||
229 | static inline int ubi_dbg_is_bitflip(const struct ubi_device *ubi) { return 0; } | ||
230 | static inline int | ||
231 | ubi_dbg_is_write_failure(const struct ubi_device *ubi) { return 0; } | ||
232 | static inline int | ||
233 | ubi_dbg_is_erase_failure(const struct ubi_device *ubi) { return 0; } | ||
234 | |||
216 | #endif /* !CONFIG_MTD_UBI_DEBUG */ | 235 | #endif /* !CONFIG_MTD_UBI_DEBUG */ |
217 | #endif /* !__UBI_DEBUG_H__ */ | 236 | #endif /* !__UBI_DEBUG_H__ */ |
diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c index 8c1b1c7bc4a7..6ba55c235873 100644 --- a/drivers/mtd/ubi/io.c +++ b/drivers/mtd/ubi/io.c | |||
@@ -212,7 +212,7 @@ retry: | |||
212 | } else { | 212 | } else { |
213 | ubi_assert(len == read); | 213 | ubi_assert(len == read); |
214 | 214 | ||
215 | if (ubi_dbg_is_bitflip()) { | 215 | if (ubi_dbg_is_bitflip(ubi)) { |
216 | dbg_gen("bit-flip (emulated)"); | 216 | dbg_gen("bit-flip (emulated)"); |
217 | err = UBI_IO_BITFLIPS; | 217 | err = UBI_IO_BITFLIPS; |
218 | } | 218 | } |
@@ -281,7 +281,7 @@ int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset, | |||
281 | return err; | 281 | return err; |
282 | } | 282 | } |
283 | 283 | ||
284 | if (ubi_dbg_is_write_failure()) { | 284 | if (ubi_dbg_is_write_failure(ubi)) { |
285 | dbg_err("cannot write %d bytes to PEB %d:%d " | 285 | dbg_err("cannot write %d bytes to PEB %d:%d " |
286 | "(emulated)", len, pnum, offset); | 286 | "(emulated)", len, pnum, offset); |
287 | ubi_dbg_dump_stack(); | 287 | ubi_dbg_dump_stack(); |
@@ -396,7 +396,7 @@ retry: | |||
396 | if (err) | 396 | if (err) |
397 | return err; | 397 | return err; |
398 | 398 | ||
399 | if (ubi_dbg_is_erase_failure()) { | 399 | if (ubi_dbg_is_erase_failure(ubi)) { |
400 | dbg_err("cannot erase PEB %d (emulated)", pnum); | 400 | dbg_err("cannot erase PEB %d (emulated)", pnum); |
401 | return -EIO; | 401 | return -EIO; |
402 | } | 402 | } |
@@ -1146,7 +1146,7 @@ static int paranoid_check_not_bad(const struct ubi_device *ubi, int pnum) | |||
1146 | { | 1146 | { |
1147 | int err; | 1147 | int err; |
1148 | 1148 | ||
1149 | if (!(ubi_chk_flags & UBI_CHK_IO)) | 1149 | if (!ubi->dbg->chk_io) |
1150 | return 0; | 1150 | return 0; |
1151 | 1151 | ||
1152 | err = ubi_io_is_bad(ubi, pnum); | 1152 | err = ubi_io_is_bad(ubi, pnum); |
@@ -1173,7 +1173,7 @@ static int paranoid_check_ec_hdr(const struct ubi_device *ubi, int pnum, | |||
1173 | int err; | 1173 | int err; |
1174 | uint32_t magic; | 1174 | uint32_t magic; |
1175 | 1175 | ||
1176 | if (!(ubi_chk_flags & UBI_CHK_IO)) | 1176 | if (!ubi->dbg->chk_io) |
1177 | return 0; | 1177 | return 0; |
1178 | 1178 | ||
1179 | magic = be32_to_cpu(ec_hdr->magic); | 1179 | magic = be32_to_cpu(ec_hdr->magic); |
@@ -1211,7 +1211,7 @@ static int paranoid_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum) | |||
1211 | uint32_t crc, hdr_crc; | 1211 | uint32_t crc, hdr_crc; |
1212 | struct ubi_ec_hdr *ec_hdr; | 1212 | struct ubi_ec_hdr *ec_hdr; |
1213 | 1213 | ||
1214 | if (!(ubi_chk_flags & UBI_CHK_IO)) | 1214 | if (!ubi->dbg->chk_io) |
1215 | return 0; | 1215 | return 0; |
1216 | 1216 | ||
1217 | ec_hdr = kzalloc(ubi->ec_hdr_alsize, GFP_NOFS); | 1217 | ec_hdr = kzalloc(ubi->ec_hdr_alsize, GFP_NOFS); |
@@ -1255,7 +1255,7 @@ static int paranoid_check_vid_hdr(const struct ubi_device *ubi, int pnum, | |||
1255 | int err; | 1255 | int err; |
1256 | uint32_t magic; | 1256 | uint32_t magic; |
1257 | 1257 | ||
1258 | if (!(ubi_chk_flags & UBI_CHK_IO)) | 1258 | if (!ubi->dbg->chk_io) |
1259 | return 0; | 1259 | return 0; |
1260 | 1260 | ||
1261 | magic = be32_to_cpu(vid_hdr->magic); | 1261 | magic = be32_to_cpu(vid_hdr->magic); |
@@ -1296,7 +1296,7 @@ static int paranoid_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum) | |||
1296 | struct ubi_vid_hdr *vid_hdr; | 1296 | struct ubi_vid_hdr *vid_hdr; |
1297 | void *p; | 1297 | void *p; |
1298 | 1298 | ||
1299 | if (!(ubi_chk_flags & UBI_CHK_IO)) | 1299 | if (!ubi->dbg->chk_io) |
1300 | return 0; | 1300 | return 0; |
1301 | 1301 | ||
1302 | vid_hdr = ubi_zalloc_vid_hdr(ubi, GFP_NOFS); | 1302 | vid_hdr = ubi_zalloc_vid_hdr(ubi, GFP_NOFS); |
@@ -1348,7 +1348,7 @@ int ubi_dbg_check_write(struct ubi_device *ubi, const void *buf, int pnum, | |||
1348 | void *buf1; | 1348 | void *buf1; |
1349 | loff_t addr = (loff_t)pnum * ubi->peb_size + offset; | 1349 | loff_t addr = (loff_t)pnum * ubi->peb_size + offset; |
1350 | 1350 | ||
1351 | if (!(ubi_chk_flags & UBI_CHK_IO)) | 1351 | if (!ubi->dbg->chk_io) |
1352 | return 0; | 1352 | return 0; |
1353 | 1353 | ||
1354 | buf1 = __vmalloc(len, GFP_NOFS, PAGE_KERNEL); | 1354 | buf1 = __vmalloc(len, GFP_NOFS, PAGE_KERNEL); |
@@ -1412,7 +1412,7 @@ int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len) | |||
1412 | void *buf; | 1412 | void *buf; |
1413 | loff_t addr = (loff_t)pnum * ubi->peb_size + offset; | 1413 | loff_t addr = (loff_t)pnum * ubi->peb_size + offset; |
1414 | 1414 | ||
1415 | if (!(ubi_chk_flags & UBI_CHK_IO)) | 1415 | if (!ubi->dbg->chk_io) |
1416 | return 0; | 1416 | return 0; |
1417 | 1417 | ||
1418 | buf = __vmalloc(len, GFP_NOFS, PAGE_KERNEL); | 1418 | buf = __vmalloc(len, GFP_NOFS, PAGE_KERNEL); |
diff --git a/drivers/mtd/ubi/scan.c b/drivers/mtd/ubi/scan.c index 2135a53732ff..a3a198f9b98d 100644 --- a/drivers/mtd/ubi/scan.c +++ b/drivers/mtd/ubi/scan.c | |||
@@ -1347,7 +1347,7 @@ static int paranoid_check_si(struct ubi_device *ubi, struct ubi_scan_info *si) | |||
1347 | struct ubi_scan_leb *seb, *last_seb; | 1347 | struct ubi_scan_leb *seb, *last_seb; |
1348 | uint8_t *buf; | 1348 | uint8_t *buf; |
1349 | 1349 | ||
1350 | if (!(ubi_chk_flags & UBI_CHK_GEN)) | 1350 | if (!ubi->dbg->chk_gen) |
1351 | return 0; | 1351 | return 0; |
1352 | 1352 | ||
1353 | /* | 1353 | /* |
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h index c6c22295898e..dc64c767fd21 100644 --- a/drivers/mtd/ubi/ubi.h +++ b/drivers/mtd/ubi/ubi.h | |||
@@ -44,7 +44,6 @@ | |||
44 | 44 | ||
45 | #include "ubi-media.h" | 45 | #include "ubi-media.h" |
46 | #include "scan.h" | 46 | #include "scan.h" |
47 | #include "debug.h" | ||
48 | 47 | ||
49 | /* Maximum number of supported UBI devices */ | 48 | /* Maximum number of supported UBI devices */ |
50 | #define UBI_MAX_DEVICES 32 | 49 | #define UBI_MAX_DEVICES 32 |
@@ -390,6 +389,8 @@ struct ubi_wl_entry; | |||
390 | * @peb_buf2: another buffer of PEB size used for different purposes | 389 | * @peb_buf2: another buffer of PEB size used for different purposes |
391 | * @buf_mutex: protects @peb_buf1 and @peb_buf2 | 390 | * @buf_mutex: protects @peb_buf1 and @peb_buf2 |
392 | * @ckvol_mutex: serializes static volume checking when opening | 391 | * @ckvol_mutex: serializes static volume checking when opening |
392 | * | ||
393 | * @dbg: debugging information for this UBI device | ||
393 | */ | 394 | */ |
394 | struct ubi_device { | 395 | struct ubi_device { |
395 | struct cdev cdev; | 396 | struct cdev cdev; |
@@ -472,8 +473,12 @@ struct ubi_device { | |||
472 | void *peb_buf2; | 473 | void *peb_buf2; |
473 | struct mutex buf_mutex; | 474 | struct mutex buf_mutex; |
474 | struct mutex ckvol_mutex; | 475 | struct mutex ckvol_mutex; |
476 | |||
477 | struct ubi_debug_info *dbg; | ||
475 | }; | 478 | }; |
476 | 479 | ||
480 | #include "debug.h" | ||
481 | |||
477 | extern struct kmem_cache *ubi_wl_entry_slab; | 482 | extern struct kmem_cache *ubi_wl_entry_slab; |
478 | extern const struct file_operations ubi_ctrl_cdev_operations; | 483 | extern const struct file_operations ubi_ctrl_cdev_operations; |
479 | extern const struct file_operations ubi_cdev_operations; | 484 | extern const struct file_operations ubi_cdev_operations; |
@@ -662,6 +667,7 @@ static inline void ubi_ro_mode(struct ubi_device *ubi) | |||
662 | if (!ubi->ro_mode) { | 667 | if (!ubi->ro_mode) { |
663 | ubi->ro_mode = 1; | 668 | ubi->ro_mode = 1; |
664 | ubi_warn("switch to read-only mode"); | 669 | ubi_warn("switch to read-only mode"); |
670 | ubi_dbg_dump_stack(); | ||
665 | } | 671 | } |
666 | } | 672 | } |
667 | 673 | ||
diff --git a/drivers/mtd/ubi/vmt.c b/drivers/mtd/ubi/vmt.c index 366eb70219a6..97e093d19672 100644 --- a/drivers/mtd/ubi/vmt.c +++ b/drivers/mtd/ubi/vmt.c | |||
@@ -871,7 +871,7 @@ static int paranoid_check_volumes(struct ubi_device *ubi) | |||
871 | { | 871 | { |
872 | int i, err = 0; | 872 | int i, err = 0; |
873 | 873 | ||
874 | if (!(ubi_chk_flags & UBI_CHK_GEN)) | 874 | if (!ubi->dbg->chk_gen) |
875 | return 0; | 875 | return 0; |
876 | 876 | ||
877 | for (i = 0; i < ubi->vtbl_slots; i++) { | 877 | for (i = 0; i < ubi->vtbl_slots; i++) { |
diff --git a/drivers/mtd/ubi/vtbl.c b/drivers/mtd/ubi/vtbl.c index fd3bf770f518..4b50a3029b84 100644 --- a/drivers/mtd/ubi/vtbl.c +++ b/drivers/mtd/ubi/vtbl.c | |||
@@ -307,8 +307,7 @@ static int create_vtbl(struct ubi_device *ubi, struct ubi_scan_info *si, | |||
307 | { | 307 | { |
308 | int err, tries = 0; | 308 | int err, tries = 0; |
309 | static struct ubi_vid_hdr *vid_hdr; | 309 | static struct ubi_vid_hdr *vid_hdr; |
310 | struct ubi_scan_volume *sv; | 310 | struct ubi_scan_leb *new_seb; |
311 | struct ubi_scan_leb *new_seb, *old_seb = NULL; | ||
312 | 311 | ||
313 | ubi_msg("create volume table (copy #%d)", copy + 1); | 312 | ubi_msg("create volume table (copy #%d)", copy + 1); |
314 | 313 | ||
@@ -316,15 +315,6 @@ static int create_vtbl(struct ubi_device *ubi, struct ubi_scan_info *si, | |||
316 | if (!vid_hdr) | 315 | if (!vid_hdr) |
317 | return -ENOMEM; | 316 | return -ENOMEM; |
318 | 317 | ||
319 | /* | ||
320 | * Check if there is a logical eraseblock which would have to contain | ||
321 | * this volume table copy was found during scanning. It has to be wiped | ||
322 | * out. | ||
323 | */ | ||
324 | sv = ubi_scan_find_sv(si, UBI_LAYOUT_VOLUME_ID); | ||
325 | if (sv) | ||
326 | old_seb = ubi_scan_find_seb(sv, copy); | ||
327 | |||
328 | retry: | 318 | retry: |
329 | new_seb = ubi_scan_get_free_peb(ubi, si); | 319 | new_seb = ubi_scan_get_free_peb(ubi, si); |
330 | if (IS_ERR(new_seb)) { | 320 | if (IS_ERR(new_seb)) { |
@@ -351,8 +341,8 @@ retry: | |||
351 | goto write_error; | 341 | goto write_error; |
352 | 342 | ||
353 | /* | 343 | /* |
354 | * And add it to the scanning information. Don't delete the old | 344 | * And add it to the scanning information. Don't delete the old version |
355 | * @old_seb as it will be deleted and freed in 'ubi_scan_add_used()'. | 345 | * of this LEB as it will be deleted and freed in 'ubi_scan_add_used()'. |
356 | */ | 346 | */ |
357 | err = ubi_scan_add_used(ubi, si, new_seb->pnum, new_seb->ec, | 347 | err = ubi_scan_add_used(ubi, si, new_seb->pnum, new_seb->ec, |
358 | vid_hdr, 0); | 348 | vid_hdr, 0); |
@@ -876,7 +866,7 @@ out_free: | |||
876 | */ | 866 | */ |
877 | static void paranoid_vtbl_check(const struct ubi_device *ubi) | 867 | static void paranoid_vtbl_check(const struct ubi_device *ubi) |
878 | { | 868 | { |
879 | if (!(ubi_chk_flags & UBI_CHK_GEN)) | 869 | if (!ubi->dbg->chk_gen) |
880 | return; | 870 | return; |
881 | 871 | ||
882 | if (vtbl_check(ubi, ubi->vtbl)) { | 872 | if (vtbl_check(ubi, ubi->vtbl)) { |
diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c index ff2c4956eeff..42c684cf3688 100644 --- a/drivers/mtd/ubi/wl.c +++ b/drivers/mtd/ubi/wl.c | |||
@@ -1,4 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * @ubi: UBI device description object | ||
2 | * Copyright (c) International Business Machines Corp., 2006 | 3 | * Copyright (c) International Business Machines Corp., 2006 |
3 | * | 4 | * |
4 | * This program is free software; you can redistribute it and/or modify | 5 | * This program is free software; you can redistribute it and/or modify |
@@ -163,12 +164,14 @@ struct ubi_work { | |||
163 | 164 | ||
164 | #ifdef CONFIG_MTD_UBI_DEBUG | 165 | #ifdef CONFIG_MTD_UBI_DEBUG |
165 | static int paranoid_check_ec(struct ubi_device *ubi, int pnum, int ec); | 166 | static int paranoid_check_ec(struct ubi_device *ubi, int pnum, int ec); |
166 | static int paranoid_check_in_wl_tree(struct ubi_wl_entry *e, | 167 | static int paranoid_check_in_wl_tree(const struct ubi_device *ubi, |
168 | struct ubi_wl_entry *e, | ||
167 | struct rb_root *root); | 169 | struct rb_root *root); |
168 | static int paranoid_check_in_pq(struct ubi_device *ubi, struct ubi_wl_entry *e); | 170 | static int paranoid_check_in_pq(const struct ubi_device *ubi, |
171 | struct ubi_wl_entry *e); | ||
169 | #else | 172 | #else |
170 | #define paranoid_check_ec(ubi, pnum, ec) 0 | 173 | #define paranoid_check_ec(ubi, pnum, ec) 0 |
171 | #define paranoid_check_in_wl_tree(e, root) | 174 | #define paranoid_check_in_wl_tree(ubi, e, root) |
172 | #define paranoid_check_in_pq(ubi, e) 0 | 175 | #define paranoid_check_in_pq(ubi, e) 0 |
173 | #endif | 176 | #endif |
174 | 177 | ||
@@ -449,7 +452,7 @@ retry: | |||
449 | BUG(); | 452 | BUG(); |
450 | } | 453 | } |
451 | 454 | ||
452 | paranoid_check_in_wl_tree(e, &ubi->free); | 455 | paranoid_check_in_wl_tree(ubi, e, &ubi->free); |
453 | 456 | ||
454 | /* | 457 | /* |
455 | * Move the physical eraseblock to the protection queue where it will | 458 | * Move the physical eraseblock to the protection queue where it will |
@@ -613,7 +616,7 @@ static void schedule_ubi_work(struct ubi_device *ubi, struct ubi_work *wrk) | |||
613 | list_add_tail(&wrk->list, &ubi->works); | 616 | list_add_tail(&wrk->list, &ubi->works); |
614 | ubi_assert(ubi->works_count >= 0); | 617 | ubi_assert(ubi->works_count >= 0); |
615 | ubi->works_count += 1; | 618 | ubi->works_count += 1; |
616 | if (ubi->thread_enabled && !ubi_dbg_is_bgt_disabled()) | 619 | if (ubi->thread_enabled && !ubi_dbg_is_bgt_disabled(ubi)) |
617 | wake_up_process(ubi->bgt_thread); | 620 | wake_up_process(ubi->bgt_thread); |
618 | spin_unlock(&ubi->wl_lock); | 621 | spin_unlock(&ubi->wl_lock); |
619 | } | 622 | } |
@@ -712,7 +715,7 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk, | |||
712 | e1->ec, e2->ec); | 715 | e1->ec, e2->ec); |
713 | goto out_cancel; | 716 | goto out_cancel; |
714 | } | 717 | } |
715 | paranoid_check_in_wl_tree(e1, &ubi->used); | 718 | paranoid_check_in_wl_tree(ubi, e1, &ubi->used); |
716 | rb_erase(&e1->u.rb, &ubi->used); | 719 | rb_erase(&e1->u.rb, &ubi->used); |
717 | dbg_wl("move PEB %d EC %d to PEB %d EC %d", | 720 | dbg_wl("move PEB %d EC %d to PEB %d EC %d", |
718 | e1->pnum, e1->ec, e2->pnum, e2->ec); | 721 | e1->pnum, e1->ec, e2->pnum, e2->ec); |
@@ -721,12 +724,12 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk, | |||
721 | scrubbing = 1; | 724 | scrubbing = 1; |
722 | e1 = rb_entry(rb_first(&ubi->scrub), struct ubi_wl_entry, u.rb); | 725 | e1 = rb_entry(rb_first(&ubi->scrub), struct ubi_wl_entry, u.rb); |
723 | e2 = find_wl_entry(&ubi->free, WL_FREE_MAX_DIFF); | 726 | e2 = find_wl_entry(&ubi->free, WL_FREE_MAX_DIFF); |
724 | paranoid_check_in_wl_tree(e1, &ubi->scrub); | 727 | paranoid_check_in_wl_tree(ubi, e1, &ubi->scrub); |
725 | rb_erase(&e1->u.rb, &ubi->scrub); | 728 | rb_erase(&e1->u.rb, &ubi->scrub); |
726 | dbg_wl("scrub PEB %d to PEB %d", e1->pnum, e2->pnum); | 729 | dbg_wl("scrub PEB %d to PEB %d", e1->pnum, e2->pnum); |
727 | } | 730 | } |
728 | 731 | ||
729 | paranoid_check_in_wl_tree(e2, &ubi->free); | 732 | paranoid_check_in_wl_tree(ubi, e2, &ubi->free); |
730 | rb_erase(&e2->u.rb, &ubi->free); | 733 | rb_erase(&e2->u.rb, &ubi->free); |
731 | ubi->move_from = e1; | 734 | ubi->move_from = e1; |
732 | ubi->move_to = e2; | 735 | ubi->move_to = e2; |
@@ -1169,13 +1172,13 @@ retry: | |||
1169 | return 0; | 1172 | return 0; |
1170 | } else { | 1173 | } else { |
1171 | if (in_wl_tree(e, &ubi->used)) { | 1174 | if (in_wl_tree(e, &ubi->used)) { |
1172 | paranoid_check_in_wl_tree(e, &ubi->used); | 1175 | paranoid_check_in_wl_tree(ubi, e, &ubi->used); |
1173 | rb_erase(&e->u.rb, &ubi->used); | 1176 | rb_erase(&e->u.rb, &ubi->used); |
1174 | } else if (in_wl_tree(e, &ubi->scrub)) { | 1177 | } else if (in_wl_tree(e, &ubi->scrub)) { |
1175 | paranoid_check_in_wl_tree(e, &ubi->scrub); | 1178 | paranoid_check_in_wl_tree(ubi, e, &ubi->scrub); |
1176 | rb_erase(&e->u.rb, &ubi->scrub); | 1179 | rb_erase(&e->u.rb, &ubi->scrub); |
1177 | } else if (in_wl_tree(e, &ubi->erroneous)) { | 1180 | } else if (in_wl_tree(e, &ubi->erroneous)) { |
1178 | paranoid_check_in_wl_tree(e, &ubi->erroneous); | 1181 | paranoid_check_in_wl_tree(ubi, e, &ubi->erroneous); |
1179 | rb_erase(&e->u.rb, &ubi->erroneous); | 1182 | rb_erase(&e->u.rb, &ubi->erroneous); |
1180 | ubi->erroneous_peb_count -= 1; | 1183 | ubi->erroneous_peb_count -= 1; |
1181 | ubi_assert(ubi->erroneous_peb_count >= 0); | 1184 | ubi_assert(ubi->erroneous_peb_count >= 0); |
@@ -1242,7 +1245,7 @@ retry: | |||
1242 | } | 1245 | } |
1243 | 1246 | ||
1244 | if (in_wl_tree(e, &ubi->used)) { | 1247 | if (in_wl_tree(e, &ubi->used)) { |
1245 | paranoid_check_in_wl_tree(e, &ubi->used); | 1248 | paranoid_check_in_wl_tree(ubi, e, &ubi->used); |
1246 | rb_erase(&e->u.rb, &ubi->used); | 1249 | rb_erase(&e->u.rb, &ubi->used); |
1247 | } else { | 1250 | } else { |
1248 | int err; | 1251 | int err; |
@@ -1364,7 +1367,7 @@ int ubi_thread(void *u) | |||
1364 | 1367 | ||
1365 | spin_lock(&ubi->wl_lock); | 1368 | spin_lock(&ubi->wl_lock); |
1366 | if (list_empty(&ubi->works) || ubi->ro_mode || | 1369 | if (list_empty(&ubi->works) || ubi->ro_mode || |
1367 | !ubi->thread_enabled || ubi_dbg_is_bgt_disabled()) { | 1370 | !ubi->thread_enabled || ubi_dbg_is_bgt_disabled(ubi)) { |
1368 | set_current_state(TASK_INTERRUPTIBLE); | 1371 | set_current_state(TASK_INTERRUPTIBLE); |
1369 | spin_unlock(&ubi->wl_lock); | 1372 | spin_unlock(&ubi->wl_lock); |
1370 | schedule(); | 1373 | schedule(); |
@@ -1579,7 +1582,7 @@ static int paranoid_check_ec(struct ubi_device *ubi, int pnum, int ec) | |||
1579 | long long read_ec; | 1582 | long long read_ec; |
1580 | struct ubi_ec_hdr *ec_hdr; | 1583 | struct ubi_ec_hdr *ec_hdr; |
1581 | 1584 | ||
1582 | if (!(ubi_chk_flags & UBI_CHK_GEN)) | 1585 | if (!ubi->dbg->chk_gen) |
1583 | return 0; | 1586 | return 0; |
1584 | 1587 | ||
1585 | ec_hdr = kzalloc(ubi->ec_hdr_alsize, GFP_NOFS); | 1588 | ec_hdr = kzalloc(ubi->ec_hdr_alsize, GFP_NOFS); |
@@ -1609,16 +1612,18 @@ out_free: | |||
1609 | 1612 | ||
1610 | /** | 1613 | /** |
1611 | * paranoid_check_in_wl_tree - check that wear-leveling entry is in WL RB-tree. | 1614 | * paranoid_check_in_wl_tree - check that wear-leveling entry is in WL RB-tree. |
1615 | * @ubi: UBI device description object | ||
1612 | * @e: the wear-leveling entry to check | 1616 | * @e: the wear-leveling entry to check |
1613 | * @root: the root of the tree | 1617 | * @root: the root of the tree |
1614 | * | 1618 | * |
1615 | * This function returns zero if @e is in the @root RB-tree and %-EINVAL if it | 1619 | * This function returns zero if @e is in the @root RB-tree and %-EINVAL if it |
1616 | * is not. | 1620 | * is not. |
1617 | */ | 1621 | */ |
1618 | static int paranoid_check_in_wl_tree(struct ubi_wl_entry *e, | 1622 | static int paranoid_check_in_wl_tree(const struct ubi_device *ubi, |
1623 | struct ubi_wl_entry *e, | ||
1619 | struct rb_root *root) | 1624 | struct rb_root *root) |
1620 | { | 1625 | { |
1621 | if (!(ubi_chk_flags & UBI_CHK_GEN)) | 1626 | if (!ubi->dbg->chk_gen) |
1622 | return 0; | 1627 | return 0; |
1623 | 1628 | ||
1624 | if (in_wl_tree(e, root)) | 1629 | if (in_wl_tree(e, root)) |
@@ -1638,12 +1643,13 @@ static int paranoid_check_in_wl_tree(struct ubi_wl_entry *e, | |||
1638 | * | 1643 | * |
1639 | * This function returns zero if @e is in @ubi->pq and %-EINVAL if it is not. | 1644 | * This function returns zero if @e is in @ubi->pq and %-EINVAL if it is not. |
1640 | */ | 1645 | */ |
1641 | static int paranoid_check_in_pq(struct ubi_device *ubi, struct ubi_wl_entry *e) | 1646 | static int paranoid_check_in_pq(const struct ubi_device *ubi, |
1647 | struct ubi_wl_entry *e) | ||
1642 | { | 1648 | { |
1643 | struct ubi_wl_entry *p; | 1649 | struct ubi_wl_entry *p; |
1644 | int i; | 1650 | int i; |
1645 | 1651 | ||
1646 | if (!(ubi_chk_flags & UBI_CHK_GEN)) | 1652 | if (!ubi->dbg->chk_gen) |
1647 | return 0; | 1653 | return 0; |
1648 | 1654 | ||
1649 | for (i = 0; i < UBI_PROT_QUEUE_LEN; ++i) | 1655 | for (i = 0; i < UBI_PROT_QUEUE_LEN; ++i) |