diff options
Diffstat (limited to 'drivers/mtd/ubi/eba.c')
-rw-r--r-- | drivers/mtd/ubi/eba.c | 98 |
1 files changed, 50 insertions, 48 deletions
diff --git a/drivers/mtd/ubi/eba.c b/drivers/mtd/ubi/eba.c index 7c6b223b3f8a..8aff9385613f 100644 --- a/drivers/mtd/ubi/eba.c +++ b/drivers/mtd/ubi/eba.c | |||
@@ -425,10 +425,10 @@ retry: | |||
425 | } else if (err == UBI_IO_BITFLIPS) | 425 | } else if (err == UBI_IO_BITFLIPS) |
426 | scrub = 1; | 426 | scrub = 1; |
427 | 427 | ||
428 | ubi_assert(lnum < ubi32_to_cpu(vid_hdr->used_ebs)); | 428 | ubi_assert(lnum < be32_to_cpu(vid_hdr->used_ebs)); |
429 | ubi_assert(len == ubi32_to_cpu(vid_hdr->data_size)); | 429 | ubi_assert(len == be32_to_cpu(vid_hdr->data_size)); |
430 | 430 | ||
431 | crc = ubi32_to_cpu(vid_hdr->data_crc); | 431 | crc = be32_to_cpu(vid_hdr->data_crc); |
432 | ubi_free_vid_hdr(ubi, vid_hdr); | 432 | ubi_free_vid_hdr(ubi, vid_hdr); |
433 | } | 433 | } |
434 | 434 | ||
@@ -518,13 +518,13 @@ retry: | |||
518 | goto out_put; | 518 | goto out_put; |
519 | } | 519 | } |
520 | 520 | ||
521 | vid_hdr->sqnum = cpu_to_ubi64(next_sqnum(ubi)); | 521 | vid_hdr->sqnum = cpu_to_be64(next_sqnum(ubi)); |
522 | err = ubi_io_write_vid_hdr(ubi, new_pnum, vid_hdr); | 522 | err = ubi_io_write_vid_hdr(ubi, new_pnum, vid_hdr); |
523 | if (err) | 523 | if (err) |
524 | goto write_error; | 524 | goto write_error; |
525 | 525 | ||
526 | data_size = offset + len; | 526 | data_size = offset + len; |
527 | new_buf = kmalloc(data_size, GFP_KERNEL); | 527 | new_buf = vmalloc(data_size); |
528 | if (!new_buf) { | 528 | if (!new_buf) { |
529 | err = -ENOMEM; | 529 | err = -ENOMEM; |
530 | goto out_put; | 530 | goto out_put; |
@@ -535,7 +535,7 @@ retry: | |||
535 | if (offset > 0) { | 535 | if (offset > 0) { |
536 | err = ubi_io_read_data(ubi, new_buf, pnum, 0, offset); | 536 | err = ubi_io_read_data(ubi, new_buf, pnum, 0, offset); |
537 | if (err && err != UBI_IO_BITFLIPS) { | 537 | if (err && err != UBI_IO_BITFLIPS) { |
538 | kfree(new_buf); | 538 | vfree(new_buf); |
539 | goto out_put; | 539 | goto out_put; |
540 | } | 540 | } |
541 | } | 541 | } |
@@ -544,11 +544,11 @@ retry: | |||
544 | 544 | ||
545 | err = ubi_io_write_data(ubi, new_buf, new_pnum, 0, data_size); | 545 | err = ubi_io_write_data(ubi, new_buf, new_pnum, 0, data_size); |
546 | if (err) { | 546 | if (err) { |
547 | kfree(new_buf); | 547 | vfree(new_buf); |
548 | goto write_error; | 548 | goto write_error; |
549 | } | 549 | } |
550 | 550 | ||
551 | kfree(new_buf); | 551 | vfree(new_buf); |
552 | ubi_free_vid_hdr(ubi, vid_hdr); | 552 | ubi_free_vid_hdr(ubi, vid_hdr); |
553 | 553 | ||
554 | vol->eba_tbl[lnum] = new_pnum; | 554 | vol->eba_tbl[lnum] = new_pnum; |
@@ -634,11 +634,11 @@ int ubi_eba_write_leb(struct ubi_device *ubi, int vol_id, int lnum, | |||
634 | } | 634 | } |
635 | 635 | ||
636 | vid_hdr->vol_type = UBI_VID_DYNAMIC; | 636 | vid_hdr->vol_type = UBI_VID_DYNAMIC; |
637 | vid_hdr->sqnum = cpu_to_ubi64(next_sqnum(ubi)); | 637 | vid_hdr->sqnum = cpu_to_be64(next_sqnum(ubi)); |
638 | vid_hdr->vol_id = cpu_to_ubi32(vol_id); | 638 | vid_hdr->vol_id = cpu_to_be32(vol_id); |
639 | vid_hdr->lnum = cpu_to_ubi32(lnum); | 639 | vid_hdr->lnum = cpu_to_be32(lnum); |
640 | vid_hdr->compat = ubi_get_compat(ubi, vol_id); | 640 | vid_hdr->compat = ubi_get_compat(ubi, vol_id); |
641 | vid_hdr->data_pad = cpu_to_ubi32(vol->data_pad); | 641 | vid_hdr->data_pad = cpu_to_be32(vol->data_pad); |
642 | 642 | ||
643 | retry: | 643 | retry: |
644 | pnum = ubi_wl_get_peb(ubi, dtype); | 644 | pnum = ubi_wl_get_peb(ubi, dtype); |
@@ -692,7 +692,7 @@ write_error: | |||
692 | return err; | 692 | return err; |
693 | } | 693 | } |
694 | 694 | ||
695 | vid_hdr->sqnum = cpu_to_ubi64(next_sqnum(ubi)); | 695 | vid_hdr->sqnum = cpu_to_be64(next_sqnum(ubi)); |
696 | ubi_msg("try another PEB"); | 696 | ubi_msg("try another PEB"); |
697 | goto retry; | 697 | goto retry; |
698 | } | 698 | } |
@@ -748,17 +748,17 @@ int ubi_eba_write_leb_st(struct ubi_device *ubi, int vol_id, int lnum, | |||
748 | return err; | 748 | return err; |
749 | } | 749 | } |
750 | 750 | ||
751 | vid_hdr->sqnum = cpu_to_ubi64(next_sqnum(ubi)); | 751 | vid_hdr->sqnum = cpu_to_be64(next_sqnum(ubi)); |
752 | vid_hdr->vol_id = cpu_to_ubi32(vol_id); | 752 | vid_hdr->vol_id = cpu_to_be32(vol_id); |
753 | vid_hdr->lnum = cpu_to_ubi32(lnum); | 753 | vid_hdr->lnum = cpu_to_be32(lnum); |
754 | vid_hdr->compat = ubi_get_compat(ubi, vol_id); | 754 | vid_hdr->compat = ubi_get_compat(ubi, vol_id); |
755 | vid_hdr->data_pad = cpu_to_ubi32(vol->data_pad); | 755 | vid_hdr->data_pad = cpu_to_be32(vol->data_pad); |
756 | 756 | ||
757 | crc = crc32(UBI_CRC32_INIT, buf, data_size); | 757 | crc = crc32(UBI_CRC32_INIT, buf, data_size); |
758 | vid_hdr->vol_type = UBI_VID_STATIC; | 758 | vid_hdr->vol_type = UBI_VID_STATIC; |
759 | vid_hdr->data_size = cpu_to_ubi32(data_size); | 759 | vid_hdr->data_size = cpu_to_be32(data_size); |
760 | vid_hdr->used_ebs = cpu_to_ubi32(used_ebs); | 760 | vid_hdr->used_ebs = cpu_to_be32(used_ebs); |
761 | vid_hdr->data_crc = cpu_to_ubi32(crc); | 761 | vid_hdr->data_crc = cpu_to_be32(crc); |
762 | 762 | ||
763 | retry: | 763 | retry: |
764 | pnum = ubi_wl_get_peb(ubi, dtype); | 764 | pnum = ubi_wl_get_peb(ubi, dtype); |
@@ -813,7 +813,7 @@ write_error: | |||
813 | return err; | 813 | return err; |
814 | } | 814 | } |
815 | 815 | ||
816 | vid_hdr->sqnum = cpu_to_ubi64(next_sqnum(ubi)); | 816 | vid_hdr->sqnum = cpu_to_be64(next_sqnum(ubi)); |
817 | ubi_msg("try another PEB"); | 817 | ubi_msg("try another PEB"); |
818 | goto retry; | 818 | goto retry; |
819 | } | 819 | } |
@@ -854,17 +854,17 @@ int ubi_eba_atomic_leb_change(struct ubi_device *ubi, int vol_id, int lnum, | |||
854 | return err; | 854 | return err; |
855 | } | 855 | } |
856 | 856 | ||
857 | vid_hdr->sqnum = cpu_to_ubi64(next_sqnum(ubi)); | 857 | vid_hdr->sqnum = cpu_to_be64(next_sqnum(ubi)); |
858 | vid_hdr->vol_id = cpu_to_ubi32(vol_id); | 858 | vid_hdr->vol_id = cpu_to_be32(vol_id); |
859 | vid_hdr->lnum = cpu_to_ubi32(lnum); | 859 | vid_hdr->lnum = cpu_to_be32(lnum); |
860 | vid_hdr->compat = ubi_get_compat(ubi, vol_id); | 860 | vid_hdr->compat = ubi_get_compat(ubi, vol_id); |
861 | vid_hdr->data_pad = cpu_to_ubi32(vol->data_pad); | 861 | vid_hdr->data_pad = cpu_to_be32(vol->data_pad); |
862 | 862 | ||
863 | crc = crc32(UBI_CRC32_INIT, buf, len); | 863 | crc = crc32(UBI_CRC32_INIT, buf, len); |
864 | vid_hdr->vol_type = UBI_VID_STATIC; | 864 | vid_hdr->vol_type = UBI_VID_DYNAMIC; |
865 | vid_hdr->data_size = cpu_to_ubi32(len); | 865 | vid_hdr->data_size = cpu_to_be32(len); |
866 | vid_hdr->copy_flag = 1; | 866 | vid_hdr->copy_flag = 1; |
867 | vid_hdr->data_crc = cpu_to_ubi32(crc); | 867 | vid_hdr->data_crc = cpu_to_be32(crc); |
868 | 868 | ||
869 | retry: | 869 | retry: |
870 | pnum = ubi_wl_get_peb(ubi, dtype); | 870 | pnum = ubi_wl_get_peb(ubi, dtype); |
@@ -891,11 +891,13 @@ retry: | |||
891 | goto write_error; | 891 | goto write_error; |
892 | } | 892 | } |
893 | 893 | ||
894 | err = ubi_wl_put_peb(ubi, vol->eba_tbl[lnum], 1); | 894 | if (vol->eba_tbl[lnum] >= 0) { |
895 | if (err) { | 895 | err = ubi_wl_put_peb(ubi, vol->eba_tbl[lnum], 1); |
896 | ubi_free_vid_hdr(ubi, vid_hdr); | 896 | if (err) { |
897 | leb_write_unlock(ubi, vol_id, lnum); | 897 | ubi_free_vid_hdr(ubi, vid_hdr); |
898 | return err; | 898 | leb_write_unlock(ubi, vol_id, lnum); |
899 | return err; | ||
900 | } | ||
899 | } | 901 | } |
900 | 902 | ||
901 | vol->eba_tbl[lnum] = pnum; | 903 | vol->eba_tbl[lnum] = pnum; |
@@ -924,7 +926,7 @@ write_error: | |||
924 | return err; | 926 | return err; |
925 | } | 927 | } |
926 | 928 | ||
927 | vid_hdr->sqnum = cpu_to_ubi64(next_sqnum(ubi)); | 929 | vid_hdr->sqnum = cpu_to_be64(next_sqnum(ubi)); |
928 | ubi_msg("try another PEB"); | 930 | ubi_msg("try another PEB"); |
929 | goto retry; | 931 | goto retry; |
930 | } | 932 | } |
@@ -965,19 +967,19 @@ int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to, | |||
965 | uint32_t crc; | 967 | uint32_t crc; |
966 | void *buf, *buf1 = NULL; | 968 | void *buf, *buf1 = NULL; |
967 | 969 | ||
968 | vol_id = ubi32_to_cpu(vid_hdr->vol_id); | 970 | vol_id = be32_to_cpu(vid_hdr->vol_id); |
969 | lnum = ubi32_to_cpu(vid_hdr->lnum); | 971 | lnum = be32_to_cpu(vid_hdr->lnum); |
970 | 972 | ||
971 | dbg_eba("copy LEB %d:%d, PEB %d to PEB %d", vol_id, lnum, from, to); | 973 | dbg_eba("copy LEB %d:%d, PEB %d to PEB %d", vol_id, lnum, from, to); |
972 | 974 | ||
973 | if (vid_hdr->vol_type == UBI_VID_STATIC) { | 975 | if (vid_hdr->vol_type == UBI_VID_STATIC) { |
974 | data_size = ubi32_to_cpu(vid_hdr->data_size); | 976 | data_size = be32_to_cpu(vid_hdr->data_size); |
975 | aldata_size = ALIGN(data_size, ubi->min_io_size); | 977 | aldata_size = ALIGN(data_size, ubi->min_io_size); |
976 | } else | 978 | } else |
977 | data_size = aldata_size = | 979 | data_size = aldata_size = |
978 | ubi->leb_size - ubi32_to_cpu(vid_hdr->data_pad); | 980 | ubi->leb_size - be32_to_cpu(vid_hdr->data_pad); |
979 | 981 | ||
980 | buf = kmalloc(aldata_size, GFP_KERNEL); | 982 | buf = vmalloc(aldata_size); |
981 | if (!buf) | 983 | if (!buf) |
982 | return -ENOMEM; | 984 | return -ENOMEM; |
983 | 985 | ||
@@ -987,7 +989,7 @@ int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to, | |||
987 | */ | 989 | */ |
988 | err = leb_write_lock(ubi, vol_id, lnum); | 990 | err = leb_write_lock(ubi, vol_id, lnum); |
989 | if (err) { | 991 | if (err) { |
990 | kfree(buf); | 992 | vfree(buf); |
991 | return err; | 993 | return err; |
992 | } | 994 | } |
993 | 995 | ||
@@ -1054,10 +1056,10 @@ int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to, | |||
1054 | */ | 1056 | */ |
1055 | if (data_size > 0) { | 1057 | if (data_size > 0) { |
1056 | vid_hdr->copy_flag = 1; | 1058 | vid_hdr->copy_flag = 1; |
1057 | vid_hdr->data_size = cpu_to_ubi32(data_size); | 1059 | vid_hdr->data_size = cpu_to_be32(data_size); |
1058 | vid_hdr->data_crc = cpu_to_ubi32(crc); | 1060 | vid_hdr->data_crc = cpu_to_be32(crc); |
1059 | } | 1061 | } |
1060 | vid_hdr->sqnum = cpu_to_ubi64(next_sqnum(ubi)); | 1062 | vid_hdr->sqnum = cpu_to_be64(next_sqnum(ubi)); |
1061 | 1063 | ||
1062 | err = ubi_io_write_vid_hdr(ubi, to, vid_hdr); | 1064 | err = ubi_io_write_vid_hdr(ubi, to, vid_hdr); |
1063 | if (err) | 1065 | if (err) |
@@ -1082,7 +1084,7 @@ int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to, | |||
1082 | * We've written the data and are going to read it back to make | 1084 | * We've written the data and are going to read it back to make |
1083 | * sure it was written correctly. | 1085 | * sure it was written correctly. |
1084 | */ | 1086 | */ |
1085 | buf1 = kmalloc(aldata_size, GFP_KERNEL); | 1087 | buf1 = vmalloc(aldata_size); |
1086 | if (!buf1) { | 1088 | if (!buf1) { |
1087 | err = -ENOMEM; | 1089 | err = -ENOMEM; |
1088 | goto out_unlock; | 1090 | goto out_unlock; |
@@ -1111,15 +1113,15 @@ int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to, | |||
1111 | vol->eba_tbl[lnum] = to; | 1113 | vol->eba_tbl[lnum] = to; |
1112 | 1114 | ||
1113 | leb_write_unlock(ubi, vol_id, lnum); | 1115 | leb_write_unlock(ubi, vol_id, lnum); |
1114 | kfree(buf); | 1116 | vfree(buf); |
1115 | kfree(buf1); | 1117 | vfree(buf1); |
1116 | 1118 | ||
1117 | return 0; | 1119 | return 0; |
1118 | 1120 | ||
1119 | out_unlock: | 1121 | out_unlock: |
1120 | leb_write_unlock(ubi, vol_id, lnum); | 1122 | leb_write_unlock(ubi, vol_id, lnum); |
1121 | kfree(buf); | 1123 | vfree(buf); |
1122 | kfree(buf1); | 1124 | vfree(buf1); |
1123 | return err; | 1125 | return err; |
1124 | } | 1126 | } |
1125 | 1127 | ||