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>
This commit is contained in:
parent
e0e718c281
commit
b33215084c
1 changed files with 32 additions and 13 deletions
|
@ -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);
|
err = ubi_io_read_ec_hdr(ubi, pnum, ech, 0);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
return err;
|
||||||
else if (err == UBI_IO_BITFLIPS)
|
switch (err) {
|
||||||
|
case 0:
|
||||||
|
break;
|
||||||
|
case UBI_IO_BITFLIPS:
|
||||||
bitflips = 1;
|
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);
|
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
|
* 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
|
||||||
|
@ -759,6 +766,10 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si,
|
||||||
ec_err = err;
|
ec_err = err;
|
||||||
ec = UBI_SCAN_UNKNOWN_EC;
|
ec = UBI_SCAN_UNKNOWN_EC;
|
||||||
bitflips = 1;
|
bitflips = 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ubi_err("'ubi_io_read_ec_hdr()' returned unknown code %d", err);
|
||||||
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ec_err) {
|
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);
|
err = ubi_io_read_vid_hdr(ubi, pnum, vidh, 0);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
return err;
|
||||||
else if (err == UBI_IO_BITFLIPS)
|
switch (err) {
|
||||||
|
case 0:
|
||||||
|
break;
|
||||||
|
case UBI_IO_BITFLIPS:
|
||||||
bitflips = 1;
|
bitflips = 1;
|
||||||
else if (err == UBI_IO_BAD_HDR_EBADMSG || err == UBI_IO_BAD_HDR ||
|
break;
|
||||||
(err == UBI_IO_FF && ec_err) || err == UBI_IO_FF_BITFLIPS) {
|
case UBI_IO_BAD_HDR_EBADMSG:
|
||||||
/* VID header is corrupted */
|
si->read_err_count += 1;
|
||||||
if (err == UBI_IO_BAD_HDR_EBADMSG ||
|
case UBI_IO_BAD_HDR:
|
||||||
ec_err == UBI_IO_BAD_HDR_EBADMSG)
|
case UBI_IO_FF_BITFLIPS:
|
||||||
si->read_err_count += 1;
|
|
||||||
err = add_to_list(si, pnum, ec, &si->corr);
|
err = add_to_list(si, pnum, ec, &si->corr);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
goto adjust_mean_ec;
|
goto adjust_mean_ec;
|
||||||
} else if (err == UBI_IO_FF) {
|
case UBI_IO_FF:
|
||||||
/* No VID header - the physical eraseblock is free */
|
if (ec_err)
|
||||||
err = add_to_list(si, pnum, ec, &si->free);
|
err = add_to_list(si, pnum, ec, &si->corr);
|
||||||
|
else
|
||||||
|
err = add_to_list(si, pnum, ec, &si->free);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
goto adjust_mean_ec;
|
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);
|
vol_id = be32_to_cpu(vidh->vol_id);
|
||||||
|
|
Loading…
Reference in a new issue