diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2017-05-13 13:23:12 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-05-13 13:23:12 -0400 |
commit | b53c4d5eb7cda86f7bf495f52116ae43bdc9cf23 (patch) | |
tree | d549854f163d675fccaa5b40e39fd3b63d4df2d7 /drivers | |
parent | ec059019b7e6ae3926a8e1dec02a62d64dd8c060 (diff) | |
parent | 7bccd12d27b7e358823feb5429731b8ee698b173 (diff) |
Merge tag 'upstream-4.12-rc1' of git://git.infradead.org/linux-ubifs
Pull UBI/UBIFS updates from Richard Weinberger:
- new config option CONFIG_UBIFS_FS_SECURITY
- minor improvements
- random fixes
* tag 'upstream-4.12-rc1' of git://git.infradead.org/linux-ubifs:
ubi: Add debugfs file for tracking PEB state
ubifs: Fix a typo in comment of ioctl2ubifs & ubifs2ioctl
ubifs: Remove unnecessary assignment
ubifs: Fix cut and paste error on sb type comparisons
ubi: fastmap: Fix slab corruption
ubifs: Add CONFIG_UBIFS_FS_SECURITY to disable/enable security labels
ubi: Make mtd parameter readable
ubi: Fix section mismatch
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/mtd/ubi/build.c | 10 | ||||
-rw-r--r-- | drivers/mtd/ubi/debug.c | 126 | ||||
-rw-r--r-- | drivers/mtd/ubi/fastmap.c | 33 |
3 files changed, 159 insertions, 10 deletions
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c index 8bae3731d039..93e5d251a9e4 100644 --- a/drivers/mtd/ubi/build.c +++ b/drivers/mtd/ubi/build.c | |||
@@ -74,10 +74,10 @@ struct mtd_dev_param { | |||
74 | }; | 74 | }; |
75 | 75 | ||
76 | /* Numbers of elements set in the @mtd_dev_param array */ | 76 | /* Numbers of elements set in the @mtd_dev_param array */ |
77 | static int __initdata mtd_devs; | 77 | static int mtd_devs; |
78 | 78 | ||
79 | /* MTD devices specification parameters */ | 79 | /* MTD devices specification parameters */ |
80 | static struct mtd_dev_param __initdata mtd_dev_param[UBI_MAX_DEVICES]; | 80 | static struct mtd_dev_param mtd_dev_param[UBI_MAX_DEVICES]; |
81 | #ifdef CONFIG_MTD_UBI_FASTMAP | 81 | #ifdef CONFIG_MTD_UBI_FASTMAP |
82 | /* UBI module parameter to enable fastmap automatically on non-fastmap images */ | 82 | /* UBI module parameter to enable fastmap automatically on non-fastmap images */ |
83 | static bool fm_autoconvert; | 83 | static bool fm_autoconvert; |
@@ -1294,7 +1294,7 @@ module_exit(ubi_exit); | |||
1294 | * This function returns positive resulting integer in case of success and a | 1294 | * This function returns positive resulting integer in case of success and a |
1295 | * negative error code in case of failure. | 1295 | * negative error code in case of failure. |
1296 | */ | 1296 | */ |
1297 | static int __init bytes_str_to_int(const char *str) | 1297 | static int bytes_str_to_int(const char *str) |
1298 | { | 1298 | { |
1299 | char *endp; | 1299 | char *endp; |
1300 | unsigned long result; | 1300 | unsigned long result; |
@@ -1332,7 +1332,7 @@ static int __init bytes_str_to_int(const char *str) | |||
1332 | * This function returns zero in case of success and a negative error code in | 1332 | * This function returns zero in case of success and a negative error code in |
1333 | * case of error. | 1333 | * case of error. |
1334 | */ | 1334 | */ |
1335 | static int __init ubi_mtd_param_parse(const char *val, struct kernel_param *kp) | 1335 | static int ubi_mtd_param_parse(const char *val, struct kernel_param *kp) |
1336 | { | 1336 | { |
1337 | int i, len; | 1337 | int i, len; |
1338 | struct mtd_dev_param *p; | 1338 | struct mtd_dev_param *p; |
@@ -1413,7 +1413,7 @@ static int __init ubi_mtd_param_parse(const char *val, struct kernel_param *kp) | |||
1413 | return 0; | 1413 | return 0; |
1414 | } | 1414 | } |
1415 | 1415 | ||
1416 | module_param_call(mtd, ubi_mtd_param_parse, NULL, NULL, 000); | 1416 | module_param_call(mtd, ubi_mtd_param_parse, NULL, NULL, 0400); |
1417 | MODULE_PARM_DESC(mtd, "MTD devices to attach. Parameter format: mtd=<name|num|path>[,<vid_hdr_offs>[,max_beb_per1024[,ubi_num]]].\n" | 1417 | MODULE_PARM_DESC(mtd, "MTD devices to attach. Parameter format: mtd=<name|num|path>[,<vid_hdr_offs>[,max_beb_per1024[,ubi_num]]].\n" |
1418 | "Multiple \"mtd\" parameters may be specified.\n" | 1418 | "Multiple \"mtd\" parameters may be specified.\n" |
1419 | "MTD devices may be specified by their number, name, or path to the MTD character device node.\n" | 1419 | "MTD devices may be specified by their number, name, or path to the MTD character device node.\n" |
diff --git a/drivers/mtd/ubi/debug.c b/drivers/mtd/ubi/debug.c index f101a4985a7c..7bc96294ae4d 100644 --- a/drivers/mtd/ubi/debug.c +++ b/drivers/mtd/ubi/debug.c | |||
@@ -22,6 +22,7 @@ | |||
22 | #include <linux/debugfs.h> | 22 | #include <linux/debugfs.h> |
23 | #include <linux/uaccess.h> | 23 | #include <linux/uaccess.h> |
24 | #include <linux/module.h> | 24 | #include <linux/module.h> |
25 | #include <linux/seq_file.h> | ||
25 | 26 | ||
26 | 27 | ||
27 | /** | 28 | /** |
@@ -386,7 +387,9 @@ out: | |||
386 | return count; | 387 | return count; |
387 | } | 388 | } |
388 | 389 | ||
389 | /* File operations for all UBI debugfs files */ | 390 | /* File operations for all UBI debugfs files except |
391 | * detailed_erase_block_info | ||
392 | */ | ||
390 | static const struct file_operations dfs_fops = { | 393 | static const struct file_operations dfs_fops = { |
391 | .read = dfs_file_read, | 394 | .read = dfs_file_read, |
392 | .write = dfs_file_write, | 395 | .write = dfs_file_write, |
@@ -395,6 +398,121 @@ static const struct file_operations dfs_fops = { | |||
395 | .owner = THIS_MODULE, | 398 | .owner = THIS_MODULE, |
396 | }; | 399 | }; |
397 | 400 | ||
401 | /* As long as the position is less then that total number of erase blocks, | ||
402 | * we still have more to print. | ||
403 | */ | ||
404 | static void *eraseblk_count_seq_start(struct seq_file *s, loff_t *pos) | ||
405 | { | ||
406 | struct ubi_device *ubi = s->private; | ||
407 | |||
408 | if (*pos == 0) | ||
409 | return SEQ_START_TOKEN; | ||
410 | |||
411 | if (*pos < ubi->peb_count) | ||
412 | return pos; | ||
413 | |||
414 | return NULL; | ||
415 | } | ||
416 | |||
417 | /* Since we are using the position as the iterator, we just need to check if we | ||
418 | * are done and increment the position. | ||
419 | */ | ||
420 | static void *eraseblk_count_seq_next(struct seq_file *s, void *v, loff_t *pos) | ||
421 | { | ||
422 | struct ubi_device *ubi = s->private; | ||
423 | |||
424 | if (v == SEQ_START_TOKEN) | ||
425 | return pos; | ||
426 | (*pos)++; | ||
427 | |||
428 | if (*pos < ubi->peb_count) | ||
429 | return pos; | ||
430 | |||
431 | return NULL; | ||
432 | } | ||
433 | |||
434 | static void eraseblk_count_seq_stop(struct seq_file *s, void *v) | ||
435 | { | ||
436 | } | ||
437 | |||
438 | static int eraseblk_count_seq_show(struct seq_file *s, void *iter) | ||
439 | { | ||
440 | struct ubi_device *ubi = s->private; | ||
441 | struct ubi_wl_entry *wl; | ||
442 | int *block_number = iter; | ||
443 | int erase_count = -1; | ||
444 | int err; | ||
445 | |||
446 | /* If this is the start, print a header */ | ||
447 | if (iter == SEQ_START_TOKEN) { | ||
448 | seq_puts(s, | ||
449 | "physical_block_number\terase_count\tblock_status\tread_status\n"); | ||
450 | return 0; | ||
451 | } | ||
452 | |||
453 | err = ubi_io_is_bad(ubi, *block_number); | ||
454 | if (err) | ||
455 | return err; | ||
456 | |||
457 | spin_lock(&ubi->wl_lock); | ||
458 | |||
459 | wl = ubi->lookuptbl[*block_number]; | ||
460 | if (wl) | ||
461 | erase_count = wl->ec; | ||
462 | |||
463 | spin_unlock(&ubi->wl_lock); | ||
464 | |||
465 | if (erase_count < 0) | ||
466 | return 0; | ||
467 | |||
468 | seq_printf(s, "%-22d\t%-11d\n", *block_number, erase_count); | ||
469 | |||
470 | return 0; | ||
471 | } | ||
472 | |||
473 | static const struct seq_operations eraseblk_count_seq_ops = { | ||
474 | .start = eraseblk_count_seq_start, | ||
475 | .next = eraseblk_count_seq_next, | ||
476 | .stop = eraseblk_count_seq_stop, | ||
477 | .show = eraseblk_count_seq_show | ||
478 | }; | ||
479 | |||
480 | static int eraseblk_count_open(struct inode *inode, struct file *f) | ||
481 | { | ||
482 | struct seq_file *s; | ||
483 | int err; | ||
484 | |||
485 | err = seq_open(f, &eraseblk_count_seq_ops); | ||
486 | if (err) | ||
487 | return err; | ||
488 | |||
489 | s = f->private_data; | ||
490 | s->private = ubi_get_device((unsigned long)inode->i_private); | ||
491 | |||
492 | if (!s->private) | ||
493 | return -ENODEV; | ||
494 | else | ||
495 | return 0; | ||
496 | } | ||
497 | |||
498 | static int eraseblk_count_release(struct inode *inode, struct file *f) | ||
499 | { | ||
500 | struct seq_file *s = f->private_data; | ||
501 | struct ubi_device *ubi = s->private; | ||
502 | |||
503 | ubi_put_device(ubi); | ||
504 | |||
505 | return seq_release(inode, f); | ||
506 | } | ||
507 | |||
508 | static const struct file_operations eraseblk_count_fops = { | ||
509 | .owner = THIS_MODULE, | ||
510 | .open = eraseblk_count_open, | ||
511 | .read = seq_read, | ||
512 | .llseek = seq_lseek, | ||
513 | .release = eraseblk_count_release, | ||
514 | }; | ||
515 | |||
398 | /** | 516 | /** |
399 | * ubi_debugfs_init_dev - initialize debugfs for an UBI device. | 517 | * ubi_debugfs_init_dev - initialize debugfs for an UBI device. |
400 | * @ubi: UBI device description object | 518 | * @ubi: UBI device description object |
@@ -491,6 +609,12 @@ int ubi_debugfs_init_dev(struct ubi_device *ubi) | |||
491 | goto out_remove; | 609 | goto out_remove; |
492 | d->dfs_power_cut_max = dent; | 610 | d->dfs_power_cut_max = dent; |
493 | 611 | ||
612 | fname = "detailed_erase_block_info"; | ||
613 | dent = debugfs_create_file(fname, S_IRUSR, d->dfs_dir, (void *)ubi_num, | ||
614 | &eraseblk_count_fops); | ||
615 | if (IS_ERR_OR_NULL(dent)) | ||
616 | goto out_remove; | ||
617 | |||
494 | return 0; | 618 | return 0; |
495 | 619 | ||
496 | out_remove: | 620 | out_remove: |
diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c index c1f5c29e458e..b44c8d348e78 100644 --- a/drivers/mtd/ubi/fastmap.c +++ b/drivers/mtd/ubi/fastmap.c | |||
@@ -828,6 +828,24 @@ static int find_fm_anchor(struct ubi_attach_info *ai) | |||
828 | return ret; | 828 | return ret; |
829 | } | 829 | } |
830 | 830 | ||
831 | static struct ubi_ainf_peb *clone_aeb(struct ubi_attach_info *ai, | ||
832 | struct ubi_ainf_peb *old) | ||
833 | { | ||
834 | struct ubi_ainf_peb *new; | ||
835 | |||
836 | new = ubi_alloc_aeb(ai, old->pnum, old->ec); | ||
837 | if (!new) | ||
838 | return NULL; | ||
839 | |||
840 | new->vol_id = old->vol_id; | ||
841 | new->sqnum = old->sqnum; | ||
842 | new->lnum = old->lnum; | ||
843 | new->scrub = old->scrub; | ||
844 | new->copy_flag = old->copy_flag; | ||
845 | |||
846 | return new; | ||
847 | } | ||
848 | |||
831 | /** | 849 | /** |
832 | * ubi_scan_fastmap - scan the fastmap. | 850 | * ubi_scan_fastmap - scan the fastmap. |
833 | * @ubi: UBI device object | 851 | * @ubi: UBI device object |
@@ -847,7 +865,7 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai, | |||
847 | struct ubi_vid_hdr *vh; | 865 | struct ubi_vid_hdr *vh; |
848 | struct ubi_ec_hdr *ech; | 866 | struct ubi_ec_hdr *ech; |
849 | struct ubi_fastmap_layout *fm; | 867 | struct ubi_fastmap_layout *fm; |
850 | struct ubi_ainf_peb *tmp_aeb, *aeb; | 868 | struct ubi_ainf_peb *aeb; |
851 | int i, used_blocks, pnum, fm_anchor, ret = 0; | 869 | int i, used_blocks, pnum, fm_anchor, ret = 0; |
852 | size_t fm_size; | 870 | size_t fm_size; |
853 | __be32 crc, tmp_crc; | 871 | __be32 crc, tmp_crc; |
@@ -857,9 +875,16 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai, | |||
857 | if (fm_anchor < 0) | 875 | if (fm_anchor < 0) |
858 | return UBI_NO_FASTMAP; | 876 | return UBI_NO_FASTMAP; |
859 | 877 | ||
860 | /* Move all (possible) fastmap blocks into our new attach structure. */ | 878 | /* Copy all (possible) fastmap blocks into our new attach structure. */ |
861 | list_for_each_entry_safe(aeb, tmp_aeb, &scan_ai->fastmap, u.list) | 879 | list_for_each_entry(aeb, &scan_ai->fastmap, u.list) { |
862 | list_move_tail(&aeb->u.list, &ai->fastmap); | 880 | struct ubi_ainf_peb *new; |
881 | |||
882 | new = clone_aeb(ai, aeb); | ||
883 | if (!new) | ||
884 | return -ENOMEM; | ||
885 | |||
886 | list_add(&new->u.list, &ai->fastmap); | ||
887 | } | ||
863 | 888 | ||
864 | down_write(&ubi->fm_protect); | 889 | down_write(&ubi->fm_protect); |
865 | memset(ubi->fm_buf, 0, ubi->fm_size); | 890 | memset(ubi->fm_buf, 0, ubi->fm_size); |