Commit 786d7831 authored by Artem Bityutskiy's avatar Artem Bityutskiy

UBI: simplify IO error codes

We do not really need 2 separate error codes for indicating bad VID
and bad EC headers (UBI_IO_BAD_EC_HDR, UBI_IO_BAD_VID_HDR), it is
enough to have only one UBI_IO_BAD_HDR return code.

This patch does not introduce any functional change, only some
code simplification.
Signed-off-by: default avatarArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Reviewed-by: default avatarSebastian Andrzej Siewior <sebastian@breakpoint.cc>
Tested-by: default avatarSebastian Andrzej Siewior <sebastian@breakpoint.cc>
parent 67a3e12b
...@@ -418,7 +418,7 @@ int ubi_eba_read_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum, ...@@ -418,7 +418,7 @@ int ubi_eba_read_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum,
* may try to recover data. FIXME: but this is * may try to recover data. FIXME: but this is
* not implemented. * not implemented.
*/ */
if (err == UBI_IO_BAD_VID_HDR) { if (err == UBI_IO_BAD_HDR) {
ubi_warn("corrupted VID header at PEB " ubi_warn("corrupted VID header at PEB "
"%d, LEB %d:%d", pnum, vol_id, "%d, LEB %d:%d", pnum, vol_id,
lnum); lnum);
...@@ -961,7 +961,7 @@ int ubi_eba_atomic_leb_change(struct ubi_device *ubi, struct ubi_volume *vol, ...@@ -961,7 +961,7 @@ int ubi_eba_atomic_leb_change(struct ubi_device *ubi, struct ubi_volume *vol,
*/ */
static int is_error_sane(int err) static int is_error_sane(int err)
{ {
if (err == -EIO || err == -ENOMEM || err == UBI_IO_BAD_VID_HDR || if (err == -EIO || err == -ENOMEM || err == UBI_IO_BAD_HDR ||
err == -ETIMEDOUT) err == -ETIMEDOUT)
return 0; return 0;
return 1; return 1;
......
...@@ -515,7 +515,7 @@ static int nor_erase_prepare(struct ubi_device *ubi, int pnum) ...@@ -515,7 +515,7 @@ static int nor_erase_prepare(struct ubi_device *ubi, int pnum)
* In this case we probably anyway have garbage in this PEB. * In this case we probably anyway have garbage in this PEB.
*/ */
err1 = ubi_io_read_vid_hdr(ubi, pnum, &vid_hdr, 0); err1 = ubi_io_read_vid_hdr(ubi, pnum, &vid_hdr, 0);
if (err1 == UBI_IO_BAD_VID_HDR) if (err1 == UBI_IO_BAD_HDR)
/* /*
* The VID header is corrupted, so we can safely erase this * The VID header is corrupted, so we can safely erase this
* PEB and not afraid that it will be treated as a valid PEB in * PEB and not afraid that it will be treated as a valid PEB in
...@@ -709,7 +709,7 @@ static int validate_ec_hdr(const struct ubi_device *ubi, ...@@ -709,7 +709,7 @@ static int validate_ec_hdr(const struct ubi_device *ubi,
* o %UBI_IO_BITFLIPS if the CRC is correct, but bit-flips were detected * o %UBI_IO_BITFLIPS if the CRC is correct, but bit-flips were detected
* and corrected by the flash driver; this is harmless but may indicate that * and corrected by the flash driver; this is harmless but may indicate that
* this eraseblock may become bad soon (but may be not); * this eraseblock may become bad soon (but may be not);
* o %UBI_IO_BAD_EC_HDR if the erase counter header is corrupted (a CRC error); * o %UBI_IO_BAD_HDR if the erase counter header is corrupted (a CRC error);
* o %UBI_IO_PEB_EMPTY if the physical eraseblock is empty; * o %UBI_IO_PEB_EMPTY if the physical eraseblock is empty;
* o a negative error code in case of failure. * o a negative error code in case of failure.
*/ */
...@@ -774,7 +774,7 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum, ...@@ -774,7 +774,7 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum,
} else if (UBI_IO_DEBUG) } else if (UBI_IO_DEBUG)
dbg_msg("bad magic number at PEB %d: %08x instead of " dbg_msg("bad magic number at PEB %d: %08x instead of "
"%08x", pnum, magic, UBI_EC_HDR_MAGIC); "%08x", pnum, magic, UBI_EC_HDR_MAGIC);
return UBI_IO_BAD_EC_HDR; return UBI_IO_BAD_HDR;
} }
crc = crc32(UBI_CRC32_INIT, ec_hdr, UBI_EC_HDR_SIZE_CRC); crc = crc32(UBI_CRC32_INIT, ec_hdr, UBI_EC_HDR_SIZE_CRC);
...@@ -788,7 +788,7 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum, ...@@ -788,7 +788,7 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum,
} else if (UBI_IO_DEBUG) } else if (UBI_IO_DEBUG)
dbg_msg("bad EC header CRC at PEB %d, calculated " dbg_msg("bad EC header CRC at PEB %d, calculated "
"%#08x, read %#08x", pnum, crc, hdr_crc); "%#08x, read %#08x", pnum, crc, hdr_crc);
return UBI_IO_BAD_EC_HDR; return UBI_IO_BAD_HDR;
} }
/* And of course validate what has just been read from the media */ /* And of course validate what has just been read from the media */
...@@ -977,7 +977,7 @@ static int validate_vid_hdr(const struct ubi_device *ubi, ...@@ -977,7 +977,7 @@ static int validate_vid_hdr(const struct ubi_device *ubi,
* o %UBI_IO_BITFLIPS if the CRC is correct, but bit-flips were detected * o %UBI_IO_BITFLIPS if the CRC is correct, but bit-flips were detected
* and corrected by the flash driver; this is harmless but may indicate that * and corrected by the flash driver; this is harmless but may indicate that
* this eraseblock may become bad soon; * this eraseblock may become bad soon;
* o %UBI_IO_BAD_VID_HDR if the volume identifier header is corrupted (a CRC * o %UBI_IO_BAD_HDR if the volume identifier header is corrupted (a CRC
* error detected); * error detected);
* o %UBI_IO_PEB_FREE if the physical eraseblock is free (i.e., there is no VID * o %UBI_IO_PEB_FREE if the physical eraseblock is free (i.e., there is no VID
* header there); * header there);
...@@ -1045,7 +1045,7 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum, ...@@ -1045,7 +1045,7 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum,
} else if (UBI_IO_DEBUG) } else if (UBI_IO_DEBUG)
dbg_msg("bad magic number at PEB %d: %08x instead of " dbg_msg("bad magic number at PEB %d: %08x instead of "
"%08x", pnum, magic, UBI_VID_HDR_MAGIC); "%08x", pnum, magic, UBI_VID_HDR_MAGIC);
return UBI_IO_BAD_VID_HDR; return UBI_IO_BAD_HDR;
} }
crc = crc32(UBI_CRC32_INIT, vid_hdr, UBI_VID_HDR_SIZE_CRC); crc = crc32(UBI_CRC32_INIT, vid_hdr, UBI_VID_HDR_SIZE_CRC);
...@@ -1059,7 +1059,7 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum, ...@@ -1059,7 +1059,7 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum,
} else if (UBI_IO_DEBUG) } else if (UBI_IO_DEBUG)
dbg_msg("bad CRC at PEB %d, calculated %#08x, " dbg_msg("bad CRC at PEB %d, calculated %#08x, "
"read %#08x", pnum, crc, hdr_crc); "read %#08x", pnum, crc, hdr_crc);
return UBI_IO_BAD_VID_HDR; return UBI_IO_BAD_HDR;
} }
/* Validate the VID header that we have just read */ /* Validate the VID header that we have just read */
......
...@@ -745,7 +745,7 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si, ...@@ -745,7 +745,7 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si,
bitflips = 1; bitflips = 1;
else if (err == UBI_IO_PEB_EMPTY) else if (err == UBI_IO_PEB_EMPTY)
return add_to_list(si, pnum, UBI_SCAN_UNKNOWN_EC, &si->erase); return add_to_list(si, pnum, UBI_SCAN_UNKNOWN_EC, &si->erase);
else if (err == UBI_IO_BAD_EC_HDR) { else if (err == UBI_IO_BAD_HDR) {
/* /*
* We have to also look at the VID header, possibly it is not * We have to also look at the VID header, possibly it is not
* corrupted. Set %bitflips flag in order to make this PEB be * corrupted. Set %bitflips flag in order to make this PEB be
...@@ -813,7 +813,7 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si, ...@@ -813,7 +813,7 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si,
return err; return err;
else if (err == UBI_IO_BITFLIPS) else if (err == UBI_IO_BITFLIPS)
bitflips = 1; bitflips = 1;
else if (err == UBI_IO_BAD_VID_HDR || else if (err == UBI_IO_BAD_HDR ||
(err == UBI_IO_PEB_FREE && ec_corr)) { (err == UBI_IO_PEB_FREE && ec_corr)) {
/* VID header is corrupted */ /* VID header is corrupted */
err = add_to_list(si, pnum, ec, &si->corr); err = add_to_list(si, pnum, ec, &si->corr);
......
...@@ -89,16 +89,13 @@ ...@@ -89,16 +89,13 @@
* %0xFF bytes * %0xFF bytes
* UBI_IO_PEB_FREE: the physical eraseblock is free, i.e. it contains only a * UBI_IO_PEB_FREE: the physical eraseblock is free, i.e. it contains only a
* valid erase counter header, and the rest are %0xFF bytes * valid erase counter header, and the rest are %0xFF bytes
* UBI_IO_BAD_EC_HDR: the erase counter header is corrupted (bad magic or CRC) * UBI_IO_BAD_HDR: the EC or VID header is corrupted (bad magic or CRC)
* UBI_IO_BAD_VID_HDR: the volume identifier header is corrupted (bad magic or
* CRC)
* UBI_IO_BITFLIPS: bit-flips were detected and corrected * UBI_IO_BITFLIPS: bit-flips were detected and corrected
*/ */
enum { enum {
UBI_IO_PEB_EMPTY = 1, UBI_IO_PEB_EMPTY = 1,
UBI_IO_PEB_FREE, UBI_IO_PEB_FREE,
UBI_IO_BAD_EC_HDR, UBI_IO_BAD_HDR,
UBI_IO_BAD_VID_HDR,
UBI_IO_BITFLIPS UBI_IO_BITFLIPS
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment