aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/ubi/io.c
diff options
context:
space:
mode:
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2010-09-02 19:11:20 -0400
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2010-10-19 10:19:56 -0400
commit74d82d2660058e32644f0c673656b2a1d01d3688 (patch)
tree8b90af4d6014ea50d74c504dc832cf3a9c3fff10 /drivers/mtd/ubi/io.c
parent756e1df1d2b8b572a92dd1b82d2a432d5b280b1c (diff)
UBI: remove duplicate IO error codes
The 'UBI_IO_PEB_EMPTY' and 'UBI_IO_PEB_FREE' are essentially the same and mean that there are only 0xFF bytes instead of headers. Simplify UBI a little by turning them into a single 'UBI_IO_FF' error code. Also, stop maintaining commentaries in 'ubi_io_read_vid_hdr()' which are almost identical to commentaries in 'ubi_io_read_ec_hdr()'. Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Diffstat (limited to 'drivers/mtd/ubi/io.c')
-rw-r--r--drivers/mtd/ubi/io.c45
1 files changed, 7 insertions, 38 deletions
diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c
index 05774da4abca..1677a215af64 100644
--- a/drivers/mtd/ubi/io.c
+++ b/drivers/mtd/ubi/io.c
@@ -714,7 +714,7 @@ bad:
714 * o %UBI_IO_BAD_HDR if the erase counter header is corrupted (a CRC error); 714 * o %UBI_IO_BAD_HDR if the erase counter header is corrupted (a CRC error);
715 * o %UBI_IO_BAD_HDR_EBADMSG is the same as %UBI_IO_BAD_HDR, but there also was 715 * o %UBI_IO_BAD_HDR_EBADMSG is the same as %UBI_IO_BAD_HDR, but there also was
716 * a data integrity error (uncorrectable ECC error in case of NAND); 716 * a data integrity error (uncorrectable ECC error in case of NAND);
717 * o %UBI_IO_PEB_EMPTY if the physical eraseblock is empty; 717 * o %UBI_IO_FF if only 0xFF bytes were read (the PEB is supposedly empty)
718 * o a negative error code in case of failure. 718 * o a negative error code in case of failure.
719 */ 719 */
720int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum, 720int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum,
@@ -762,7 +762,7 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum,
762 else if (UBI_IO_DEBUG) 762 else if (UBI_IO_DEBUG)
763 dbg_msg("no EC header found at PEB %d, " 763 dbg_msg("no EC header found at PEB %d, "
764 "only 0xFF bytes", pnum); 764 "only 0xFF bytes", pnum);
765 return UBI_IO_PEB_EMPTY; 765 return UBI_IO_FF;
766 } 766 }
767 767
768 /* 768 /*
@@ -977,19 +977,11 @@ bad:
977 * 977 *
978 * This function reads the volume identifier header from physical eraseblock 978 * This function reads the volume identifier header from physical eraseblock
979 * @pnum and stores it in @vid_hdr. It also checks CRC checksum of the read 979 * @pnum and stores it in @vid_hdr. It also checks CRC checksum of the read
980 * volume identifier header. The following codes may be returned: 980 * volume identifier header. The error codes are the same as in
981 * 'ubi_io_read_ec_hdr()'.
981 * 982 *
982 * o %0 if the CRC checksum is correct and the header was successfully read; 983 * Note, the implementation of this function is also very similar to
983 * o %UBI_IO_BITFLIPS if the CRC is correct, but bit-flips were detected 984 * 'ubi_io_read_ec_hdr()', so refer commentaries in 'ubi_io_read_ec_hdr()'.
984 * and corrected by the flash driver; this is harmless but may indicate that
985 * this eraseblock may become bad soon;
986 * o %UBI_IO_BAD_HDR if the volume identifier header is corrupted (a CRC
987 * error detected);
988 * o %UBI_IO_BAD_HDR_EBADMSG is the same as %UBI_IO_BAD_HDR, but there also was
989 * a data integrity error (uncorrectable ECC error in case of NAND);
990 * o %UBI_IO_PEB_FREE if the physical eraseblock is free (i.e., there is no VID
991 * header there);
992 * o a negative error code in case of failure.
993 */ 985 */
994int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum, 986int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum,
995 struct ubi_vid_hdr *vid_hdr, int verbose) 987 struct ubi_vid_hdr *vid_hdr, int verbose)
@@ -1008,15 +1000,6 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum,
1008 if (err != UBI_IO_BITFLIPS && err != -EBADMSG) 1000 if (err != UBI_IO_BITFLIPS && err != -EBADMSG)
1009 return err; 1001 return err;
1010 1002
1011 /*
1012 * We read all the data, but either a correctable bit-flip
1013 * occurred, or MTD reported a data integrity error
1014 * (uncorrectable ECC error in case of NAND). The former is
1015 * harmless, the later may mean that the read data is
1016 * corrupted. But we have a CRC check-sum and we will detect
1017 * this. If the VID header is still OK, we just report this as
1018 * there was a bit-flip, to force scrubbing.
1019 */
1020 if (err == -EBADMSG) 1003 if (err == -EBADMSG)
1021 read_err = UBI_IO_BAD_HDR_EBADMSG; 1004 read_err = UBI_IO_BAD_HDR_EBADMSG;
1022 } 1005 }
@@ -1026,25 +1009,16 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum,
1026 if (read_err) 1009 if (read_err)
1027 return read_err; 1010 return read_err;
1028 1011
1029 /*
1030 * If we have read all 0xFF bytes, the VID header probably does
1031 * not exist and the physical eraseblock is assumed to be free.
1032 */
1033 if (check_pattern(vid_hdr, 0xFF, UBI_VID_HDR_SIZE)) { 1012 if (check_pattern(vid_hdr, 0xFF, UBI_VID_HDR_SIZE)) {
1034 /* The physical eraseblock is supposedly free */
1035 if (verbose) 1013 if (verbose)
1036 ubi_warn("no VID header found at PEB %d, " 1014 ubi_warn("no VID header found at PEB %d, "
1037 "only 0xFF bytes", pnum); 1015 "only 0xFF bytes", pnum);
1038 else if (UBI_IO_DEBUG) 1016 else if (UBI_IO_DEBUG)
1039 dbg_msg("no VID header found at PEB %d, " 1017 dbg_msg("no VID header found at PEB %d, "
1040 "only 0xFF bytes", pnum); 1018 "only 0xFF bytes", pnum);
1041 return UBI_IO_PEB_FREE; 1019 return UBI_IO_FF;
1042 } 1020 }
1043 1021
1044 /*
1045 * This is not a valid VID header, and these are not 0xFF
1046 * bytes. Report that the header is corrupted.
1047 */
1048 if (verbose) { 1022 if (verbose) {
1049 ubi_warn("bad magic number at PEB %d: %08x instead of " 1023 ubi_warn("bad magic number at PEB %d: %08x instead of "
1050 "%08x", pnum, magic, UBI_VID_HDR_MAGIC); 1024 "%08x", pnum, magic, UBI_VID_HDR_MAGIC);
@@ -1069,17 +1043,12 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum,
1069 return read_err ?: UBI_IO_BAD_HDR; 1043 return read_err ?: UBI_IO_BAD_HDR;
1070 } 1044 }
1071 1045
1072 /* Validate the VID header that we have just read */
1073 err = validate_vid_hdr(ubi, vid_hdr); 1046 err = validate_vid_hdr(ubi, vid_hdr);
1074 if (err) { 1047 if (err) {
1075 ubi_err("validation failed for PEB %d", pnum); 1048 ubi_err("validation failed for PEB %d", pnum);
1076 return -EINVAL; 1049 return -EINVAL;
1077 } 1050 }
1078 1051
1079 /*
1080 * If there was a read error (%-EBADMSG), but the header CRC is still
1081 * OK, report about a bit-flip to force scrubbing on this PEB.
1082 */
1083 return read_err ? UBI_IO_BITFLIPS : 0; 1052 return read_err ? UBI_IO_BITFLIPS : 0;
1084} 1053}
1085 1054