Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

UBI: kill homegrown endian macros

Kill UBI's homegrown endianess handling and replace it with
the standard kernel endianess handling.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>

authored by

Christoph Hellwig and committed by
Artem Bityutskiy
3261ebd7 bf07803a

+168 -197
+19 -19
drivers/mtd/ubi/debug.c
··· 35 35 void ubi_dbg_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr) 36 36 { 37 37 dbg_msg("erase counter header dump:"); 38 - dbg_msg("magic %#08x", ubi32_to_cpu(ec_hdr->magic)); 38 + dbg_msg("magic %#08x", be32_to_cpu(ec_hdr->magic)); 39 39 dbg_msg("version %d", (int)ec_hdr->version); 40 - dbg_msg("ec %llu", (long long)ubi64_to_cpu(ec_hdr->ec)); 41 - dbg_msg("vid_hdr_offset %d", ubi32_to_cpu(ec_hdr->vid_hdr_offset)); 42 - dbg_msg("data_offset %d", ubi32_to_cpu(ec_hdr->data_offset)); 43 - dbg_msg("hdr_crc %#08x", ubi32_to_cpu(ec_hdr->hdr_crc)); 40 + dbg_msg("ec %llu", (long long)be64_to_cpu(ec_hdr->ec)); 41 + dbg_msg("vid_hdr_offset %d", be32_to_cpu(ec_hdr->vid_hdr_offset)); 42 + dbg_msg("data_offset %d", be32_to_cpu(ec_hdr->data_offset)); 43 + dbg_msg("hdr_crc %#08x", be32_to_cpu(ec_hdr->hdr_crc)); 44 44 dbg_msg("erase counter header hexdump:"); 45 45 ubi_dbg_hexdump(ec_hdr, UBI_EC_HDR_SIZE); 46 46 } ··· 52 52 void ubi_dbg_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr) 53 53 { 54 54 dbg_msg("volume identifier header dump:"); 55 - dbg_msg("magic %08x", ubi32_to_cpu(vid_hdr->magic)); 55 + dbg_msg("magic %08x", be32_to_cpu(vid_hdr->magic)); 56 56 dbg_msg("version %d", (int)vid_hdr->version); 57 57 dbg_msg("vol_type %d", (int)vid_hdr->vol_type); 58 58 dbg_msg("copy_flag %d", (int)vid_hdr->copy_flag); 59 59 dbg_msg("compat %d", (int)vid_hdr->compat); 60 - dbg_msg("vol_id %d", ubi32_to_cpu(vid_hdr->vol_id)); 61 - dbg_msg("lnum %d", ubi32_to_cpu(vid_hdr->lnum)); 62 - dbg_msg("leb_ver %u", ubi32_to_cpu(vid_hdr->leb_ver)); 63 - dbg_msg("data_size %d", ubi32_to_cpu(vid_hdr->data_size)); 64 - dbg_msg("used_ebs %d", ubi32_to_cpu(vid_hdr->used_ebs)); 65 - dbg_msg("data_pad %d", ubi32_to_cpu(vid_hdr->data_pad)); 60 + dbg_msg("vol_id %d", be32_to_cpu(vid_hdr->vol_id)); 61 + dbg_msg("lnum %d", be32_to_cpu(vid_hdr->lnum)); 62 + dbg_msg("leb_ver %u", be32_to_cpu(vid_hdr->leb_ver)); 63 + dbg_msg("data_size %d", be32_to_cpu(vid_hdr->data_size)); 64 + dbg_msg("used_ebs %d", be32_to_cpu(vid_hdr->used_ebs)); 65 + dbg_msg("data_pad %d", be32_to_cpu(vid_hdr->data_pad)); 66 66 dbg_msg("sqnum %llu", 67 - (unsigned long long)ubi64_to_cpu(vid_hdr->sqnum)); 68 - dbg_msg("hdr_crc %08x", ubi32_to_cpu(vid_hdr->hdr_crc)); 67 + (unsigned long long)be64_to_cpu(vid_hdr->sqnum)); 68 + dbg_msg("hdr_crc %08x", be32_to_cpu(vid_hdr->hdr_crc)); 69 69 dbg_msg("volume identifier header hexdump:"); 70 70 } 71 71 ··· 106 106 */ 107 107 void ubi_dbg_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx) 108 108 { 109 - int name_len = ubi16_to_cpu(r->name_len); 109 + int name_len = be16_to_cpu(r->name_len); 110 110 111 111 dbg_msg("volume table record %d dump:", idx); 112 - dbg_msg("reserved_pebs %d", ubi32_to_cpu(r->reserved_pebs)); 113 - dbg_msg("alignment %d", ubi32_to_cpu(r->alignment)); 114 - dbg_msg("data_pad %d", ubi32_to_cpu(r->data_pad)); 112 + dbg_msg("reserved_pebs %d", be32_to_cpu(r->reserved_pebs)); 113 + dbg_msg("alignment %d", be32_to_cpu(r->alignment)); 114 + dbg_msg("data_pad %d", be32_to_cpu(r->data_pad)); 115 115 dbg_msg("vol_type %d", (int)r->vol_type); 116 116 dbg_msg("upd_marker %d", (int)r->upd_marker); 117 117 dbg_msg("name_len %d", name_len); ··· 129 129 r->name[0], r->name[1], r->name[2], r->name[3], 130 130 r->name[4]); 131 131 } 132 - dbg_msg("crc %#08x", ubi32_to_cpu(r->crc)); 132 + dbg_msg("crc %#08x", be32_to_cpu(r->crc)); 133 133 } 134 134 135 135 /**
+31 -31
drivers/mtd/ubi/eba.c
··· 425 425 } else if (err == UBI_IO_BITFLIPS) 426 426 scrub = 1; 427 427 428 - ubi_assert(lnum < ubi32_to_cpu(vid_hdr->used_ebs)); 429 - ubi_assert(len == ubi32_to_cpu(vid_hdr->data_size)); 428 + ubi_assert(lnum < be32_to_cpu(vid_hdr->used_ebs)); 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 432 ubi_free_vid_hdr(ubi, vid_hdr); 433 433 } 434 434 ··· 518 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 522 err = ubi_io_write_vid_hdr(ubi, new_pnum, vid_hdr); 523 523 if (err) 524 524 goto write_error; ··· 634 634 } 635 635 636 636 vid_hdr->vol_type = UBI_VID_DYNAMIC; 637 - vid_hdr->sqnum = cpu_to_ubi64(next_sqnum(ubi)); 638 - vid_hdr->vol_id = cpu_to_ubi32(vol_id); 639 - vid_hdr->lnum = cpu_to_ubi32(lnum); 637 + vid_hdr->sqnum = cpu_to_be64(next_sqnum(ubi)); 638 + vid_hdr->vol_id = cpu_to_be32(vol_id); 639 + vid_hdr->lnum = cpu_to_be32(lnum); 640 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 643 retry: 644 644 pnum = ubi_wl_get_peb(ubi, dtype); ··· 692 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 696 ubi_msg("try another PEB"); 697 697 goto retry; 698 698 } ··· 748 748 return err; 749 749 } 750 750 751 - vid_hdr->sqnum = cpu_to_ubi64(next_sqnum(ubi)); 752 - vid_hdr->vol_id = cpu_to_ubi32(vol_id); 753 - vid_hdr->lnum = cpu_to_ubi32(lnum); 751 + vid_hdr->sqnum = cpu_to_be64(next_sqnum(ubi)); 752 + vid_hdr->vol_id = cpu_to_be32(vol_id); 753 + vid_hdr->lnum = cpu_to_be32(lnum); 754 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 757 crc = crc32(UBI_CRC32_INIT, buf, data_size); 758 758 vid_hdr->vol_type = UBI_VID_STATIC; 759 - vid_hdr->data_size = cpu_to_ubi32(data_size); 760 - vid_hdr->used_ebs = cpu_to_ubi32(used_ebs); 761 - vid_hdr->data_crc = cpu_to_ubi32(crc); 759 + vid_hdr->data_size = cpu_to_be32(data_size); 760 + vid_hdr->used_ebs = cpu_to_be32(used_ebs); 761 + vid_hdr->data_crc = cpu_to_be32(crc); 762 762 763 763 retry: 764 764 pnum = ubi_wl_get_peb(ubi, dtype); ··· 813 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 817 ubi_msg("try another PEB"); 818 818 goto retry; 819 819 } ··· 854 854 return err; 855 855 } 856 856 857 - vid_hdr->sqnum = cpu_to_ubi64(next_sqnum(ubi)); 858 - vid_hdr->vol_id = cpu_to_ubi32(vol_id); 859 - vid_hdr->lnum = cpu_to_ubi32(lnum); 857 + vid_hdr->sqnum = cpu_to_be64(next_sqnum(ubi)); 858 + vid_hdr->vol_id = cpu_to_be32(vol_id); 859 + vid_hdr->lnum = cpu_to_be32(lnum); 860 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 863 crc = crc32(UBI_CRC32_INIT, buf, len); 864 864 vid_hdr->vol_type = UBI_VID_STATIC; 865 - vid_hdr->data_size = cpu_to_ubi32(len); 865 + vid_hdr->data_size = cpu_to_be32(len); 866 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 869 retry: 870 870 pnum = ubi_wl_get_peb(ubi, dtype); ··· 924 924 return err; 925 925 } 926 926 927 - vid_hdr->sqnum = cpu_to_ubi64(next_sqnum(ubi)); 927 + vid_hdr->sqnum = cpu_to_be64(next_sqnum(ubi)); 928 928 ubi_msg("try another PEB"); 929 929 goto retry; 930 930 } ··· 965 965 uint32_t crc; 966 966 void *buf, *buf1 = NULL; 967 967 968 - vol_id = ubi32_to_cpu(vid_hdr->vol_id); 969 - lnum = ubi32_to_cpu(vid_hdr->lnum); 968 + vol_id = be32_to_cpu(vid_hdr->vol_id); 969 + lnum = be32_to_cpu(vid_hdr->lnum); 970 970 971 971 dbg_eba("copy LEB %d:%d, PEB %d to PEB %d", vol_id, lnum, from, to); 972 972 973 973 if (vid_hdr->vol_type == UBI_VID_STATIC) { 974 - data_size = ubi32_to_cpu(vid_hdr->data_size); 974 + data_size = be32_to_cpu(vid_hdr->data_size); 975 975 aldata_size = ALIGN(data_size, ubi->min_io_size); 976 976 } else 977 977 data_size = aldata_size = 978 - ubi->leb_size - ubi32_to_cpu(vid_hdr->data_pad); 978 + ubi->leb_size - be32_to_cpu(vid_hdr->data_pad); 979 979 980 980 buf = vmalloc(aldata_size); 981 981 if (!buf) ··· 1054 1054 */ 1055 1055 if (data_size > 0) { 1056 1056 vid_hdr->copy_flag = 1; 1057 - vid_hdr->data_size = cpu_to_ubi32(data_size); 1058 - vid_hdr->data_crc = cpu_to_ubi32(crc); 1057 + vid_hdr->data_size = cpu_to_be32(data_size); 1058 + vid_hdr->data_crc = cpu_to_be32(crc); 1059 1059 } 1060 - vid_hdr->sqnum = cpu_to_ubi64(next_sqnum(ubi)); 1060 + vid_hdr->sqnum = cpu_to_be64(next_sqnum(ubi)); 1061 1061 1062 1062 err = ubi_io_write_vid_hdr(ubi, to, vid_hdr); 1063 1063 if (err)
+23 -23
drivers/mtd/ubi/io.c
··· 557 557 long long ec; 558 558 int vid_hdr_offset, leb_start; 559 559 560 - ec = ubi64_to_cpu(ec_hdr->ec); 561 - vid_hdr_offset = ubi32_to_cpu(ec_hdr->vid_hdr_offset); 562 - leb_start = ubi32_to_cpu(ec_hdr->data_offset); 560 + ec = be64_to_cpu(ec_hdr->ec); 561 + vid_hdr_offset = be32_to_cpu(ec_hdr->vid_hdr_offset); 562 + leb_start = be32_to_cpu(ec_hdr->data_offset); 563 563 564 564 if (ec_hdr->version != UBI_VERSION) { 565 565 ubi_err("node with incompatible UBI version found: " ··· 640 640 read_err = err; 641 641 } 642 642 643 - magic = ubi32_to_cpu(ec_hdr->magic); 643 + magic = be32_to_cpu(ec_hdr->magic); 644 644 if (magic != UBI_EC_HDR_MAGIC) { 645 645 /* 646 646 * The magic field is wrong. Let's check if we have read all ··· 684 684 } 685 685 686 686 crc = crc32(UBI_CRC32_INIT, ec_hdr, UBI_EC_HDR_SIZE_CRC); 687 - hdr_crc = ubi32_to_cpu(ec_hdr->hdr_crc); 687 + hdr_crc = be32_to_cpu(ec_hdr->hdr_crc); 688 688 689 689 if (hdr_crc != crc) { 690 690 if (verbose) { ··· 729 729 dbg_io("write EC header to PEB %d", pnum); 730 730 ubi_assert(pnum >= 0 && pnum < ubi->peb_count); 731 731 732 - ec_hdr->magic = cpu_to_ubi32(UBI_EC_HDR_MAGIC); 732 + ec_hdr->magic = cpu_to_be32(UBI_EC_HDR_MAGIC); 733 733 ec_hdr->version = UBI_VERSION; 734 - ec_hdr->vid_hdr_offset = cpu_to_ubi32(ubi->vid_hdr_offset); 735 - ec_hdr->data_offset = cpu_to_ubi32(ubi->leb_start); 734 + ec_hdr->vid_hdr_offset = cpu_to_be32(ubi->vid_hdr_offset); 735 + ec_hdr->data_offset = cpu_to_be32(ubi->leb_start); 736 736 crc = crc32(UBI_CRC32_INIT, ec_hdr, UBI_EC_HDR_SIZE_CRC); 737 - ec_hdr->hdr_crc = cpu_to_ubi32(crc); 737 + ec_hdr->hdr_crc = cpu_to_be32(crc); 738 738 739 739 err = paranoid_check_ec_hdr(ubi, pnum, ec_hdr); 740 740 if (err) ··· 757 757 { 758 758 int vol_type = vid_hdr->vol_type; 759 759 int copy_flag = vid_hdr->copy_flag; 760 - int vol_id = ubi32_to_cpu(vid_hdr->vol_id); 761 - int lnum = ubi32_to_cpu(vid_hdr->lnum); 760 + int vol_id = be32_to_cpu(vid_hdr->vol_id); 761 + int lnum = be32_to_cpu(vid_hdr->lnum); 762 762 int compat = vid_hdr->compat; 763 - int data_size = ubi32_to_cpu(vid_hdr->data_size); 764 - int used_ebs = ubi32_to_cpu(vid_hdr->used_ebs); 765 - int data_pad = ubi32_to_cpu(vid_hdr->data_pad); 766 - int data_crc = ubi32_to_cpu(vid_hdr->data_crc); 763 + int data_size = be32_to_cpu(vid_hdr->data_size); 764 + int used_ebs = be32_to_cpu(vid_hdr->used_ebs); 765 + int data_pad = be32_to_cpu(vid_hdr->data_pad); 766 + int data_crc = be32_to_cpu(vid_hdr->data_crc); 767 767 int usable_leb_size = ubi->leb_size - data_pad; 768 768 769 769 if (copy_flag != 0 && copy_flag != 1) { ··· 914 914 read_err = err; 915 915 } 916 916 917 - magic = ubi32_to_cpu(vid_hdr->magic); 917 + magic = be32_to_cpu(vid_hdr->magic); 918 918 if (magic != UBI_VID_HDR_MAGIC) { 919 919 /* 920 920 * If we have read all 0xFF bytes, the VID header probably does ··· 957 957 } 958 958 959 959 crc = crc32(UBI_CRC32_INIT, vid_hdr, UBI_VID_HDR_SIZE_CRC); 960 - hdr_crc = ubi32_to_cpu(vid_hdr->hdr_crc); 960 + hdr_crc = be32_to_cpu(vid_hdr->hdr_crc); 961 961 962 962 if (hdr_crc != crc) { 963 963 if (verbose) { ··· 1007 1007 if (err) 1008 1008 return err > 0 ? -EINVAL: err; 1009 1009 1010 - vid_hdr->magic = cpu_to_ubi32(UBI_VID_HDR_MAGIC); 1010 + vid_hdr->magic = cpu_to_be32(UBI_VID_HDR_MAGIC); 1011 1011 vid_hdr->version = UBI_VERSION; 1012 1012 crc = crc32(UBI_CRC32_INIT, vid_hdr, UBI_VID_HDR_SIZE_CRC); 1013 - vid_hdr->hdr_crc = cpu_to_ubi32(crc); 1013 + vid_hdr->hdr_crc = cpu_to_be32(crc); 1014 1014 1015 1015 err = paranoid_check_vid_hdr(ubi, pnum, vid_hdr); 1016 1016 if (err) ··· 1060 1060 int err; 1061 1061 uint32_t magic; 1062 1062 1063 - magic = ubi32_to_cpu(ec_hdr->magic); 1063 + magic = be32_to_cpu(ec_hdr->magic); 1064 1064 if (magic != UBI_EC_HDR_MAGIC) { 1065 1065 ubi_err("bad magic %#08x, must be %#08x", 1066 1066 magic, UBI_EC_HDR_MAGIC); ··· 1105 1105 goto exit; 1106 1106 1107 1107 crc = crc32(UBI_CRC32_INIT, ec_hdr, UBI_EC_HDR_SIZE_CRC); 1108 - hdr_crc = ubi32_to_cpu(ec_hdr->hdr_crc); 1108 + hdr_crc = be32_to_cpu(ec_hdr->hdr_crc); 1109 1109 if (hdr_crc != crc) { 1110 1110 ubi_err("bad CRC, calculated %#08x, read %#08x", crc, hdr_crc); 1111 1111 ubi_err("paranoid check failed for PEB %d", pnum); ··· 1137 1137 int err; 1138 1138 uint32_t magic; 1139 1139 1140 - magic = ubi32_to_cpu(vid_hdr->magic); 1140 + magic = be32_to_cpu(vid_hdr->magic); 1141 1141 if (magic != UBI_VID_HDR_MAGIC) { 1142 1142 ubi_err("bad VID header magic %#08x at PEB %d, must be %#08x", 1143 1143 magic, pnum, UBI_VID_HDR_MAGIC); ··· 1187 1187 goto exit; 1188 1188 1189 1189 crc = crc32(UBI_CRC32_INIT, vid_hdr, UBI_EC_HDR_SIZE_CRC); 1190 - hdr_crc = ubi32_to_cpu(vid_hdr->hdr_crc); 1190 + hdr_crc = be32_to_cpu(vid_hdr->hdr_crc); 1191 1191 if (hdr_crc != crc) { 1192 1192 ubi_err("bad VID header CRC at PEB %d, calculated %#08x, " 1193 1193 "read %#08x", pnum, crc, hdr_crc);
+28 -28
drivers/mtd/ubi/scan.c
··· 132 132 const struct ubi_scan_volume *sv, int pnum) 133 133 { 134 134 int vol_type = vid_hdr->vol_type; 135 - int vol_id = ubi32_to_cpu(vid_hdr->vol_id); 136 - int used_ebs = ubi32_to_cpu(vid_hdr->used_ebs); 137 - int data_pad = ubi32_to_cpu(vid_hdr->data_pad); 135 + int vol_id = be32_to_cpu(vid_hdr->vol_id); 136 + int used_ebs = be32_to_cpu(vid_hdr->used_ebs); 137 + int data_pad = be32_to_cpu(vid_hdr->data_pad); 138 138 139 139 if (sv->leb_count != 0) { 140 140 int sv_vol_type; ··· 200 200 struct ubi_scan_volume *sv; 201 201 struct rb_node **p = &si->volumes.rb_node, *parent = NULL; 202 202 203 - ubi_assert(vol_id == ubi32_to_cpu(vid_hdr->vol_id)); 203 + ubi_assert(vol_id == be32_to_cpu(vid_hdr->vol_id)); 204 204 205 205 /* Walk the volume RB-tree to look if this volume is already present */ 206 206 while (*p) { ··· 225 225 si->max_sqnum = 0; 226 226 sv->vol_id = vol_id; 227 227 sv->root = RB_ROOT; 228 - sv->used_ebs = ubi32_to_cpu(vid_hdr->used_ebs); 229 - sv->data_pad = ubi32_to_cpu(vid_hdr->data_pad); 228 + sv->used_ebs = be32_to_cpu(vid_hdr->used_ebs); 229 + sv->data_pad = be32_to_cpu(vid_hdr->data_pad); 230 230 sv->compat = vid_hdr->compat; 231 231 sv->vol_type = vid_hdr->vol_type == UBI_VID_DYNAMIC ? UBI_DYNAMIC_VOLUME 232 232 : UBI_STATIC_VOLUME; ··· 268 268 int len, err, second_is_newer, bitflips = 0, corrupted = 0; 269 269 uint32_t data_crc, crc; 270 270 struct ubi_vid_hdr *vidh = NULL; 271 - unsigned long long sqnum2 = ubi64_to_cpu(vid_hdr->sqnum); 271 + unsigned long long sqnum2 = be64_to_cpu(vid_hdr->sqnum); 272 272 273 273 if (seb->sqnum == 0 && sqnum2 == 0) { 274 - long long abs, v1 = seb->leb_ver, v2 = ubi32_to_cpu(vid_hdr->leb_ver); 274 + long long abs, v1 = seb->leb_ver, v2 = be32_to_cpu(vid_hdr->leb_ver); 275 275 276 276 /* 277 277 * UBI constantly increases the logical eraseblock version ··· 355 355 356 356 /* Read the data of the copy and check the CRC */ 357 357 358 - len = ubi32_to_cpu(vid_hdr->data_size); 358 + len = be32_to_cpu(vid_hdr->data_size); 359 359 buf = vmalloc(len); 360 360 if (!buf) { 361 361 err = -ENOMEM; ··· 366 366 if (err && err != UBI_IO_BITFLIPS) 367 367 goto out_free_buf; 368 368 369 - data_crc = ubi32_to_cpu(vid_hdr->data_crc); 369 + data_crc = be32_to_cpu(vid_hdr->data_crc); 370 370 crc = crc32(UBI_CRC32_INIT, buf, len); 371 371 if (crc != data_crc) { 372 372 dbg_bld("PEB %d CRC error: calculated %#08x, must be %#08x", ··· 425 425 struct ubi_scan_leb *seb; 426 426 struct rb_node **p, *parent = NULL; 427 427 428 - vol_id = ubi32_to_cpu(vid_hdr->vol_id); 429 - lnum = ubi32_to_cpu(vid_hdr->lnum); 430 - sqnum = ubi64_to_cpu(vid_hdr->sqnum); 431 - leb_ver = ubi32_to_cpu(vid_hdr->leb_ver); 428 + vol_id = be32_to_cpu(vid_hdr->vol_id); 429 + lnum = be32_to_cpu(vid_hdr->lnum); 430 + sqnum = be64_to_cpu(vid_hdr->sqnum); 431 + leb_ver = be32_to_cpu(vid_hdr->leb_ver); 432 432 433 433 dbg_bld("PEB %d, LEB %d:%d, EC %d, sqnum %llu, ver %u, bitflips %d", 434 434 pnum, vol_id, lnum, ec, sqnum, leb_ver, bitflips); ··· 523 523 524 524 if (sv->highest_lnum == lnum) 525 525 sv->last_data_size = 526 - ubi32_to_cpu(vid_hdr->data_size); 526 + be32_to_cpu(vid_hdr->data_size); 527 527 528 528 return 0; 529 529 } else { ··· 560 560 561 561 if (sv->highest_lnum <= lnum) { 562 562 sv->highest_lnum = lnum; 563 - sv->last_data_size = ubi32_to_cpu(vid_hdr->data_size); 563 + sv->last_data_size = be32_to_cpu(vid_hdr->data_size); 564 564 } 565 565 566 566 if (si->max_sqnum < sqnum) ··· 687 687 return -EINVAL; 688 688 } 689 689 690 - ec_hdr->ec = cpu_to_ubi64(ec); 690 + ec_hdr->ec = cpu_to_be64(ec); 691 691 692 692 err = ubi_io_sync_erase(ubi, pnum, 0); 693 693 if (err < 0) ··· 818 818 return -EINVAL; 819 819 } 820 820 821 - ec = ubi64_to_cpu(ech->ec); 821 + ec = be64_to_cpu(ech->ec); 822 822 if (ec > UBI_MAX_ERASECOUNTER) { 823 823 /* 824 824 * Erase counter overflow. The EC headers have 64 bits ··· 856 856 goto adjust_mean_ec; 857 857 } 858 858 859 - vol_id = ubi32_to_cpu(vidh->vol_id); 859 + vol_id = be32_to_cpu(vidh->vol_id); 860 860 if (vol_id > UBI_MAX_VOLUMES && vol_id != UBI_LAYOUT_VOL_ID) { 861 - int lnum = ubi32_to_cpu(vidh->lnum); 861 + int lnum = be32_to_cpu(vidh->lnum); 862 862 863 863 /* Unsupported internal volume */ 864 864 switch (vidh->compat) { ··· 1261 1261 goto bad_vid_hdr; 1262 1262 } 1263 1263 1264 - if (seb->sqnum != ubi64_to_cpu(vidh->sqnum)) { 1264 + if (seb->sqnum != be64_to_cpu(vidh->sqnum)) { 1265 1265 ubi_err("bad sqnum %llu", seb->sqnum); 1266 1266 goto bad_vid_hdr; 1267 1267 } 1268 1268 1269 - if (sv->vol_id != ubi32_to_cpu(vidh->vol_id)) { 1269 + if (sv->vol_id != be32_to_cpu(vidh->vol_id)) { 1270 1270 ubi_err("bad vol_id %d", sv->vol_id); 1271 1271 goto bad_vid_hdr; 1272 1272 } ··· 1276 1276 goto bad_vid_hdr; 1277 1277 } 1278 1278 1279 - if (seb->lnum != ubi32_to_cpu(vidh->lnum)) { 1279 + if (seb->lnum != be32_to_cpu(vidh->lnum)) { 1280 1280 ubi_err("bad lnum %d", seb->lnum); 1281 1281 goto bad_vid_hdr; 1282 1282 } 1283 1283 1284 - if (sv->used_ebs != ubi32_to_cpu(vidh->used_ebs)) { 1284 + if (sv->used_ebs != be32_to_cpu(vidh->used_ebs)) { 1285 1285 ubi_err("bad used_ebs %d", sv->used_ebs); 1286 1286 goto bad_vid_hdr; 1287 1287 } 1288 1288 1289 - if (sv->data_pad != ubi32_to_cpu(vidh->data_pad)) { 1289 + if (sv->data_pad != be32_to_cpu(vidh->data_pad)) { 1290 1290 ubi_err("bad data_pad %d", sv->data_pad); 1291 1291 goto bad_vid_hdr; 1292 1292 } 1293 1293 1294 - if (seb->leb_ver != ubi32_to_cpu(vidh->leb_ver)) { 1294 + if (seb->leb_ver != be32_to_cpu(vidh->leb_ver)) { 1295 1295 ubi_err("bad leb_ver %u", seb->leb_ver); 1296 1296 goto bad_vid_hdr; 1297 1297 } ··· 1300 1300 if (!last_seb) 1301 1301 continue; 1302 1302 1303 - if (sv->highest_lnum != ubi32_to_cpu(vidh->lnum)) { 1303 + if (sv->highest_lnum != be32_to_cpu(vidh->lnum)) { 1304 1304 ubi_err("bad highest_lnum %d", sv->highest_lnum); 1305 1305 goto bad_vid_hdr; 1306 1306 } 1307 1307 1308 - if (sv->last_data_size != ubi32_to_cpu(vidh->data_size)) { 1308 + if (sv->last_data_size != be32_to_cpu(vidh->data_size)) { 1309 1309 ubi_err("bad last_data_size %d", sv->last_data_size); 1310 1310 goto bad_vid_hdr; 1311 1311 }
+9 -9
drivers/mtd/ubi/vmt.c
··· 319 319 320 320 /* Fill volume table record */ 321 321 memset(&vtbl_rec, 0, sizeof(struct ubi_vtbl_record)); 322 - vtbl_rec.reserved_pebs = cpu_to_ubi32(vol->reserved_pebs); 323 - vtbl_rec.alignment = cpu_to_ubi32(vol->alignment); 324 - vtbl_rec.data_pad = cpu_to_ubi32(vol->data_pad); 325 - vtbl_rec.name_len = cpu_to_ubi16(vol->name_len); 322 + vtbl_rec.reserved_pebs = cpu_to_be32(vol->reserved_pebs); 323 + vtbl_rec.alignment = cpu_to_be32(vol->alignment); 324 + vtbl_rec.data_pad = cpu_to_be32(vol->data_pad); 325 + vtbl_rec.name_len = cpu_to_be16(vol->name_len); 326 326 if (vol->vol_type == UBI_DYNAMIC_VOLUME) 327 327 vtbl_rec.vol_type = UBI_VID_DYNAMIC; 328 328 else ··· 502 502 503 503 /* Change volume table record */ 504 504 memcpy(&vtbl_rec, &ubi->vtbl[vol_id], sizeof(struct ubi_vtbl_record)); 505 - vtbl_rec.reserved_pebs = cpu_to_ubi32(reserved_pebs); 505 + vtbl_rec.reserved_pebs = cpu_to_be32(reserved_pebs); 506 506 err = ubi_change_vtbl_record(ubi, vol_id, &vtbl_rec); 507 507 if (err) 508 508 goto out_acc; ··· 650 650 long long n; 651 651 const char *name; 652 652 653 - reserved_pebs = ubi32_to_cpu(ubi->vtbl[vol_id].reserved_pebs); 653 + reserved_pebs = be32_to_cpu(ubi->vtbl[vol_id].reserved_pebs); 654 654 655 655 if (!vol) { 656 656 if (reserved_pebs) { ··· 764 764 } 765 765 } 766 766 767 - alignment = ubi32_to_cpu(ubi->vtbl[vol_id].alignment); 768 - data_pad = ubi32_to_cpu(ubi->vtbl[vol_id].data_pad); 769 - name_len = ubi16_to_cpu(ubi->vtbl[vol_id].name_len); 767 + alignment = be32_to_cpu(ubi->vtbl[vol_id].alignment); 768 + data_pad = be32_to_cpu(ubi->vtbl[vol_id].data_pad); 769 + name_len = be16_to_cpu(ubi->vtbl[vol_id].name_len); 770 770 upd_marker = ubi->vtbl[vol_id].upd_marker; 771 771 name = &ubi->vtbl[vol_id].name[0]; 772 772 if (ubi->vtbl[vol_id].vol_type == UBI_VID_DYNAMIC)
+20 -20
drivers/mtd/ubi/vtbl.c
··· 93 93 vtbl_rec = &empty_vtbl_record; 94 94 else { 95 95 crc = crc32(UBI_CRC32_INIT, vtbl_rec, UBI_VTBL_RECORD_SIZE_CRC); 96 - vtbl_rec->crc = cpu_to_ubi32(crc); 96 + vtbl_rec->crc = cpu_to_be32(crc); 97 97 } 98 98 99 99 dbg_msg("change record %d", idx); ··· 141 141 for (i = 0; i < ubi->vtbl_slots; i++) { 142 142 cond_resched(); 143 143 144 - reserved_pebs = ubi32_to_cpu(vtbl[i].reserved_pebs); 145 - alignment = ubi32_to_cpu(vtbl[i].alignment); 146 - data_pad = ubi32_to_cpu(vtbl[i].data_pad); 144 + reserved_pebs = be32_to_cpu(vtbl[i].reserved_pebs); 145 + alignment = be32_to_cpu(vtbl[i].alignment); 146 + data_pad = be32_to_cpu(vtbl[i].data_pad); 147 147 upd_marker = vtbl[i].upd_marker; 148 148 vol_type = vtbl[i].vol_type; 149 - name_len = ubi16_to_cpu(vtbl[i].name_len); 149 + name_len = be16_to_cpu(vtbl[i].name_len); 150 150 name = &vtbl[i].name[0]; 151 151 152 152 crc = crc32(UBI_CRC32_INIT, &vtbl[i], UBI_VTBL_RECORD_SIZE_CRC); 153 - if (ubi32_to_cpu(vtbl[i].crc) != crc) { 153 + if (be32_to_cpu(vtbl[i].crc) != crc) { 154 154 ubi_err("bad CRC at record %u: %#08x, not %#08x", 155 - i, crc, ubi32_to_cpu(vtbl[i].crc)); 155 + i, crc, be32_to_cpu(vtbl[i].crc)); 156 156 ubi_dbg_dump_vtbl_record(&vtbl[i], i); 157 157 return 1; 158 158 } ··· 225 225 /* Checks that all names are unique */ 226 226 for (i = 0; i < ubi->vtbl_slots - 1; i++) { 227 227 for (n = i + 1; n < ubi->vtbl_slots; n++) { 228 - int len1 = ubi16_to_cpu(vtbl[i].name_len); 229 - int len2 = ubi16_to_cpu(vtbl[n].name_len); 228 + int len1 = be16_to_cpu(vtbl[i].name_len); 229 + int len2 = be16_to_cpu(vtbl[n].name_len); 230 230 231 231 if (len1 > 0 && len1 == len2 && 232 232 !strncmp(vtbl[i].name, vtbl[n].name, len1)) { ··· 288 288 } 289 289 290 290 vid_hdr->vol_type = UBI_VID_DYNAMIC; 291 - vid_hdr->vol_id = cpu_to_ubi32(UBI_LAYOUT_VOL_ID); 291 + vid_hdr->vol_id = cpu_to_be32(UBI_LAYOUT_VOL_ID); 292 292 vid_hdr->compat = UBI_LAYOUT_VOLUME_COMPAT; 293 293 vid_hdr->data_size = vid_hdr->used_ebs = 294 - vid_hdr->data_pad = cpu_to_ubi32(0); 295 - vid_hdr->lnum = cpu_to_ubi32(copy); 296 - vid_hdr->sqnum = cpu_to_ubi64(++si->max_sqnum); 297 - vid_hdr->leb_ver = cpu_to_ubi32(old_seb ? old_seb->leb_ver + 1: 0); 294 + vid_hdr->data_pad = cpu_to_be32(0); 295 + vid_hdr->lnum = cpu_to_be32(copy); 296 + vid_hdr->sqnum = cpu_to_be64(++si->max_sqnum); 297 + vid_hdr->leb_ver = cpu_to_be32(old_seb ? old_seb->leb_ver + 1: 0); 298 298 299 299 /* The EC header is already there, write the VID header */ 300 300 err = ubi_io_write_vid_hdr(ubi, new_seb->pnum, vid_hdr); ··· 503 503 for (i = 0; i < ubi->vtbl_slots; i++) { 504 504 cond_resched(); 505 505 506 - if (ubi32_to_cpu(vtbl[i].reserved_pebs) == 0) 506 + if (be32_to_cpu(vtbl[i].reserved_pebs) == 0) 507 507 continue; /* Empty record */ 508 508 509 509 vol = kzalloc(sizeof(struct ubi_volume), GFP_KERNEL); 510 510 if (!vol) 511 511 return -ENOMEM; 512 512 513 - vol->reserved_pebs = ubi32_to_cpu(vtbl[i].reserved_pebs); 514 - vol->alignment = ubi32_to_cpu(vtbl[i].alignment); 515 - vol->data_pad = ubi32_to_cpu(vtbl[i].data_pad); 513 + vol->reserved_pebs = be32_to_cpu(vtbl[i].reserved_pebs); 514 + vol->alignment = be32_to_cpu(vtbl[i].alignment); 515 + vol->data_pad = be32_to_cpu(vtbl[i].data_pad); 516 516 vol->vol_type = vtbl[i].vol_type == UBI_VID_DYNAMIC ? 517 517 UBI_DYNAMIC_VOLUME : UBI_STATIC_VOLUME; 518 - vol->name_len = ubi16_to_cpu(vtbl[i].name_len); 518 + vol->name_len = be16_to_cpu(vtbl[i].name_len); 519 519 vol->usable_leb_size = ubi->leb_size - vol->data_pad; 520 520 memcpy(vol->name, vtbl[i].name, vol->name_len); 521 521 vol->name[vol->name_len] = '\0'; ··· 721 721 int i, err; 722 722 struct ubi_scan_volume *sv; 723 723 724 - empty_vtbl_record.crc = cpu_to_ubi32(0xf116c36b); 724 + empty_vtbl_record.crc = cpu_to_be32(0xf116c36b); 725 725 726 726 /* 727 727 * The number of supported volumes is limited by the eraseblock size
+2 -2
drivers/mtd/ubi/wl.c
··· 667 667 668 668 dbg_wl("erased PEB %d, new EC %llu", e->pnum, ec); 669 669 670 - ec_hdr->ec = cpu_to_ubi64(ec); 670 + ec_hdr->ec = cpu_to_be64(ec); 671 671 672 672 err = ubi_io_write_ec_hdr(ubi, e->pnum, ec_hdr); 673 673 if (err) ··· 1634 1634 goto out_free; 1635 1635 } 1636 1636 1637 - read_ec = ubi64_to_cpu(ec_hdr->ec); 1637 + read_ec = be64_to_cpu(ec_hdr->ec); 1638 1638 if (ec != read_ec) { 1639 1639 ubi_err("paranoid check failed for PEB %d", pnum); 1640 1640 ubi_err("read EC is %lld, should be %d", read_ec, ec);
+36 -65
include/mtd/ubi-header.h
··· 74 74 UBI_COMPAT_REJECT = 5 75 75 }; 76 76 77 - /* 78 - * ubi16_t/ubi32_t/ubi64_t - 16, 32, and 64-bit integers used in UBI on-flash 79 - * data structures. 80 - */ 81 - typedef struct { 82 - uint16_t int16; 83 - } __attribute__ ((packed)) ubi16_t; 84 - 85 - typedef struct { 86 - uint32_t int32; 87 - } __attribute__ ((packed)) ubi32_t; 88 - 89 - typedef struct { 90 - uint64_t int64; 91 - } __attribute__ ((packed)) ubi64_t; 92 - 93 - /* 94 - * In this implementation of UBI uses the big-endian format for on-flash 95 - * integers. The below are the corresponding conversion macros. 96 - */ 97 - #define cpu_to_ubi16(x) ((ubi16_t){__cpu_to_be16(x)}) 98 - #define ubi16_to_cpu(x) ((uint16_t)__be16_to_cpu((x).int16)) 99 - 100 - #define cpu_to_ubi32(x) ((ubi32_t){__cpu_to_be32(x)}) 101 - #define ubi32_to_cpu(x) ((uint32_t)__be32_to_cpu((x).int32)) 102 - 103 - #define cpu_to_ubi64(x) ((ubi64_t){__cpu_to_be64(x)}) 104 - #define ubi64_to_cpu(x) ((uint64_t)__be64_to_cpu((x).int64)) 105 - 106 77 /* Sizes of UBI headers */ 107 78 #define UBI_EC_HDR_SIZE sizeof(struct ubi_ec_hdr) 108 79 #define UBI_VID_HDR_SIZE sizeof(struct ubi_vid_hdr) 109 80 110 81 /* Sizes of UBI headers without the ending CRC */ 111 - #define UBI_EC_HDR_SIZE_CRC (UBI_EC_HDR_SIZE - sizeof(ubi32_t)) 112 - #define UBI_VID_HDR_SIZE_CRC (UBI_VID_HDR_SIZE - sizeof(ubi32_t)) 82 + #define UBI_EC_HDR_SIZE_CRC (UBI_EC_HDR_SIZE - sizeof(__be32)) 83 + #define UBI_VID_HDR_SIZE_CRC (UBI_VID_HDR_SIZE - sizeof(__be32)) 113 84 114 85 /** 115 86 * struct ubi_ec_hdr - UBI erase counter header. ··· 108 137 * eraseblocks. 109 138 */ 110 139 struct ubi_ec_hdr { 111 - ubi32_t magic; 112 - uint8_t version; 113 - uint8_t padding1[3]; 114 - ubi64_t ec; /* Warning: the current limit is 31-bit anyway! */ 115 - ubi32_t vid_hdr_offset; 116 - ubi32_t data_offset; 117 - uint8_t padding2[36]; 118 - ubi32_t hdr_crc; 140 + __be32 magic; 141 + __u8 version; 142 + __u8 padding1[3]; 143 + __be64 ec; /* Warning: the current limit is 31-bit anyway! */ 144 + __be32 vid_hdr_offset; 145 + __be32 data_offset; 146 + __u8 padding2[36]; 147 + __be32 hdr_crc; 119 148 } __attribute__ ((packed)); 120 149 121 150 /** ··· 233 262 * software (say, cramfs) on top of the UBI volume. 234 263 */ 235 264 struct ubi_vid_hdr { 236 - ubi32_t magic; 237 - uint8_t version; 238 - uint8_t vol_type; 239 - uint8_t copy_flag; 240 - uint8_t compat; 241 - ubi32_t vol_id; 242 - ubi32_t lnum; 243 - ubi32_t leb_ver; /* obsolete, to be removed, don't use */ 244 - ubi32_t data_size; 245 - ubi32_t used_ebs; 246 - ubi32_t data_pad; 247 - ubi32_t data_crc; 248 - uint8_t padding1[4]; 249 - ubi64_t sqnum; 250 - uint8_t padding2[12]; 251 - ubi32_t hdr_crc; 265 + __be32 magic; 266 + __u8 version; 267 + __u8 vol_type; 268 + __u8 copy_flag; 269 + __u8 compat; 270 + __be32 vol_id; 271 + __be32 lnum; 272 + __be32 leb_ver; /* obsolete, to be removed, don't use */ 273 + __be32 data_size; 274 + __be32 used_ebs; 275 + __be32 data_pad; 276 + __be32 data_crc; 277 + __u8 padding1[4]; 278 + __be64 sqnum; 279 + __u8 padding2[12]; 280 + __be32 hdr_crc; 252 281 } __attribute__ ((packed)); 253 282 254 283 /* Internal UBI volumes count */ ··· 277 306 #define UBI_VTBL_RECORD_SIZE sizeof(struct ubi_vtbl_record) 278 307 279 308 /* Size of the volume table record without the ending CRC */ 280 - #define UBI_VTBL_RECORD_SIZE_CRC (UBI_VTBL_RECORD_SIZE - sizeof(ubi32_t)) 309 + #define UBI_VTBL_RECORD_SIZE_CRC (UBI_VTBL_RECORD_SIZE - sizeof(__be32)) 281 310 282 311 /** 283 312 * struct ubi_vtbl_record - a record in the volume table. ··· 317 346 * Empty records contain all zeroes and the CRC checksum of those zeroes. 318 347 */ 319 348 struct ubi_vtbl_record { 320 - ubi32_t reserved_pebs; 321 - ubi32_t alignment; 322 - ubi32_t data_pad; 323 - uint8_t vol_type; 324 - uint8_t upd_marker; 325 - ubi16_t name_len; 326 - uint8_t name[UBI_VOL_NAME_MAX+1]; 327 - uint8_t padding2[24]; 328 - ubi32_t crc; 349 + __be32 reserved_pebs; 350 + __be32 alignment; 351 + __be32 data_pad; 352 + __u8 vol_type; 353 + __u8 upd_marker; 354 + __be16 name_len; 355 + __u8 name[UBI_VOL_NAME_MAX+1]; 356 + __u8 padding2[24]; 357 + __be32 crc; 329 358 } __attribute__ ((packed)); 330 359 331 360 #endif /* !__UBI_HEADER_H__ */