diff options
author | Artem Bityutskiy <Artem.Bityutskiy@nokia.com> | 2010-09-03 07:40:55 -0400 |
---|---|---|
committer | Artem Bityutskiy <Artem.Bityutskiy@nokia.com> | 2010-10-19 10:19:56 -0400 |
commit | b33215084c1c06258a2d9deb035d343aafa4066e (patch) | |
tree | fd93b1b76a871e85b680c83de2ec4a81c3444025 /drivers | |
parent | e0e718c281ce1dd4006681e1255535cc6f2857d4 (diff) |
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')
-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, | |||
746 | err = ubi_io_read_ec_hdr(ubi, pnum, ech, 0); | 746 | err = ubi_io_read_ec_hdr(ubi, pnum, ech, 0); |
747 | if (err < 0) | 747 | if (err < 0) |
748 | return err; | 748 | return err; |
749 | else if (err == UBI_IO_BITFLIPS) | 749 | switch (err) { |
750 | case 0: | ||
751 | break; | ||
752 | case UBI_IO_BITFLIPS: | ||
750 | bitflips = 1; | 753 | bitflips = 1; |
751 | else if (err == UBI_IO_FF || err == UBI_IO_FF_BITFLIPS) | 754 | break; |
755 | case UBI_IO_FF: | ||
756 | case UBI_IO_FF_BITFLIPS: | ||
752 | return add_to_list(si, pnum, UBI_SCAN_UNKNOWN_EC, &si->erase); | 757 | return add_to_list(si, pnum, UBI_SCAN_UNKNOWN_EC, &si->erase); |
753 | else if (err == UBI_IO_BAD_HDR_EBADMSG || err == UBI_IO_BAD_HDR) { | 758 | case UBI_IO_BAD_HDR_EBADMSG: |
759 | si->read_err_count += 1; | ||
760 | case UBI_IO_BAD_HDR: | ||
754 | /* | 761 | /* |
755 | * We have to also look at the VID header, possibly it is not | 762 | * We have to also look at the VID header, possibly it is not |
756 | * corrupted. Set %bitflips flag in order to make this PEB be | 763 | * 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, | |||
759 | ec_err = err; | 766 | ec_err = err; |
760 | ec = UBI_SCAN_UNKNOWN_EC; | 767 | ec = UBI_SCAN_UNKNOWN_EC; |
761 | bitflips = 1; | 768 | bitflips = 1; |
769 | break; | ||
770 | default: | ||
771 | ubi_err("'ubi_io_read_ec_hdr()' returned unknown code %d", err); | ||
772 | return -EINVAL; | ||
762 | } | 773 | } |
763 | 774 | ||
764 | if (!ec_err) { | 775 | if (!ec_err) { |
@@ -814,24 +825,32 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si, | |||
814 | err = ubi_io_read_vid_hdr(ubi, pnum, vidh, 0); | 825 | err = ubi_io_read_vid_hdr(ubi, pnum, vidh, 0); |
815 | if (err < 0) | 826 | if (err < 0) |
816 | return err; | 827 | return err; |
817 | else if (err == UBI_IO_BITFLIPS) | 828 | switch (err) { |
829 | case 0: | ||
830 | break; | ||
831 | case UBI_IO_BITFLIPS: | ||
818 | bitflips = 1; | 832 | bitflips = 1; |
819 | else if (err == UBI_IO_BAD_HDR_EBADMSG || err == UBI_IO_BAD_HDR || | 833 | break; |
820 | (err == UBI_IO_FF && ec_err) || err == UBI_IO_FF_BITFLIPS) { | 834 | case UBI_IO_BAD_HDR_EBADMSG: |
821 | /* VID header is corrupted */ | 835 | si->read_err_count += 1; |
822 | if (err == UBI_IO_BAD_HDR_EBADMSG || | 836 | case UBI_IO_BAD_HDR: |
823 | ec_err == UBI_IO_BAD_HDR_EBADMSG) | 837 | case UBI_IO_FF_BITFLIPS: |
824 | si->read_err_count += 1; | ||
825 | err = add_to_list(si, pnum, ec, &si->corr); | 838 | err = add_to_list(si, pnum, ec, &si->corr); |
826 | if (err) | 839 | if (err) |
827 | return err; | 840 | return err; |
828 | goto adjust_mean_ec; | 841 | goto adjust_mean_ec; |
829 | } else if (err == UBI_IO_FF) { | 842 | case UBI_IO_FF: |
830 | /* No VID header - the physical eraseblock is free */ | 843 | if (ec_err) |
831 | err = add_to_list(si, pnum, ec, &si->free); | 844 | err = add_to_list(si, pnum, ec, &si->corr); |
845 | else | ||
846 | err = add_to_list(si, pnum, ec, &si->free); | ||
832 | if (err) | 847 | if (err) |
833 | return err; | 848 | return err; |
834 | goto adjust_mean_ec; | 849 | goto adjust_mean_ec; |
850 | default: | ||
851 | ubi_err("'ubi_io_read_vid_hdr()' returned unknown code %d", | ||
852 | err); | ||
853 | return -EINVAL; | ||
835 | } | 854 | } |
836 | 855 | ||
837 | vol_id = be32_to_cpu(vidh->vol_id); | 856 | vol_id = be32_to_cpu(vidh->vol_id); |