diff options
author | Artem Bityutskiy <Artem.Bityutskiy@nokia.com> | 2010-09-03 14:40:55 +0300 |
---|---|---|
committer | Artem Bityutskiy <Artem.Bityutskiy@nokia.com> | 2010-10-19 17:19:56 +0300 |
commit | b33215084c1c06258a2d9deb035d343aafa4066e (patch) | |
tree | fd93b1b76a871e85b680c83de2ec4a81c3444025 /drivers/mtd | |
parent | e0e718c281ce1dd4006681e1255535cc6f2857d4 (diff) | |
download | linux-b33215084c1c06258a2d9deb035d343aafa4066e.tar.gz |
UBI: change cascade of ifs to switch statements
This patch improves readability and simplifies scanning code by changing a
long cascade of 'if' statements to a switch statement. This should presumably
be a little faster as well.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Diffstat (limited to 'drivers/mtd')
-rw-r--r-- | drivers/mtd/ubi/scan.c | 45 |
1 files changed, 32 insertions, 13 deletions
diff --git a/drivers/mtd/ubi/scan.c b/drivers/mtd/ubi/scan.c index a15e9bcb6e77..9405e2420055 100644 --- a/drivers/mtd/ubi/scan.c +++ b/drivers/mtd/ubi/scan.c @@ -746,11 +746,18 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si, err = ubi_io_read_ec_hdr(ubi, pnum, ech, 0); if (err < 0) return err; - else if (err == UBI_IO_BITFLIPS) + switch (err) { + case 0: + break; + case UBI_IO_BITFLIPS: bitflips = 1; - else if (err == UBI_IO_FF || err == UBI_IO_FF_BITFLIPS) + break; + case UBI_IO_FF: + case UBI_IO_FF_BITFLIPS: return add_to_list(si, pnum, UBI_SCAN_UNKNOWN_EC, &si->erase); - else if (err == UBI_IO_BAD_HDR_EBADMSG || err == UBI_IO_BAD_HDR) { + case UBI_IO_BAD_HDR_EBADMSG: + si->read_err_count += 1; + case UBI_IO_BAD_HDR: /* * We have to also look at the VID header, possibly it is not * corrupted. Set %bitflips flag in order to make this PEB be @@ -759,6 +766,10 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si, ec_err = err; ec = UBI_SCAN_UNKNOWN_EC; bitflips = 1; + break; + default: + ubi_err("'ubi_io_read_ec_hdr()' returned unknown code %d", err); + return -EINVAL; } if (!ec_err) { @@ -814,24 +825,32 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si, err = ubi_io_read_vid_hdr(ubi, pnum, vidh, 0); if (err < 0) return err; - else if (err == UBI_IO_BITFLIPS) + switch (err) { + case 0: + break; + case UBI_IO_BITFLIPS: bitflips = 1; - else if (err == UBI_IO_BAD_HDR_EBADMSG || err == UBI_IO_BAD_HDR || - (err == UBI_IO_FF && ec_err) || err == UBI_IO_FF_BITFLIPS) { - /* VID header is corrupted */ - if (err == UBI_IO_BAD_HDR_EBADMSG || - ec_err == UBI_IO_BAD_HDR_EBADMSG) - si->read_err_count += 1; + break; + case UBI_IO_BAD_HDR_EBADMSG: + si->read_err_count += 1; + case UBI_IO_BAD_HDR: + case UBI_IO_FF_BITFLIPS: err = add_to_list(si, pnum, ec, &si->corr); if (err) return err; goto adjust_mean_ec; - } else if (err == UBI_IO_FF) { - /* No VID header - the physical eraseblock is free */ - err = add_to_list(si, pnum, ec, &si->free); + case UBI_IO_FF: + if (ec_err) + err = add_to_list(si, pnum, ec, &si->corr); + else + err = add_to_list(si, pnum, ec, &si->free); if (err) return err; goto adjust_mean_ec; + default: + ubi_err("'ubi_io_read_vid_hdr()' returned unknown code %d", + err); + return -EINVAL; } vol_id = be32_to_cpu(vidh->vol_id); |