* @ec: erase counter of the physical eraseblock
* @list: the list to add to
*
- * This function adds physical eraseblock @pnum to free, erase, corrupted or
- * alien lists. Returns zero in case of success and a negative error code in
- * case of failure.
+ * This function adds physical eraseblock @pnum to free, erase, or alien lists.
+ * Returns zero in case of success and a negative error code in case of
+ * failure.
*/
static int add_to_list(struct ubi_scan_info *si, int pnum, int ec,
struct list_head *list)
} else if (list == &si->erase) {
dbg_bld("add to erase: PEB %d, EC %d", pnum, ec);
si->erase_peb_count += 1;
- } else if (list == &si->corr) {
- dbg_bld("add to corrupted: PEB %d, EC %d", pnum, ec);
- si->corr_peb_count += 1;
} else if (list == &si->alien) {
dbg_bld("add to alien: PEB %d, EC %d", pnum, ec);
si->alien_peb_count += 1;
return 0;
}
+/**
+ * add_corrupted - add a corrupted physical eraseblock.
+ * @si: scanning information
+ * @pnum: physical eraseblock number to add
+ * @ec: erase counter of the physical eraseblock
+ *
+ * This function adds corrupted physical eraseblock @pnum to the 'corr' list.
+ * Returns zero in case of success and a negative error code in case of
+ * failure.
+ */
+static int add_corrupted(struct ubi_scan_info *si, int pnum, int ec)
+{
+ struct ubi_scan_leb *seb;
+
+ dbg_bld("add to corrupted: PEB %d, EC %d", pnum, ec);
+
+ seb = kmalloc(sizeof(struct ubi_scan_leb), GFP_KERNEL);
+ if (!seb)
+ return -ENOMEM;
+
+ si->corr_peb_count += 1;
+ seb->pnum = pnum;
+ seb->ec = ec;
+ list_add(&seb->u.list, &si->corr);
+ return 0;
+}
+
/**
* validate_vid_hdr - check volume identifier header.
* @vid_hdr: the volume identifier header to check
return err;
if (cmp_res & 4)
- err = add_to_list(si, seb->pnum, seb->ec,
- &si->corr);
+ err = add_corrupted(si, seb->pnum, seb->ec);
else
err = add_to_list(si, seb->pnum, seb->ec,
&si->erase);
* previously.
*/
if (cmp_res & 4)
- return add_to_list(si, pnum, ec, &si->corr);
+ return add_corrupted(si, pnum, ec);
else
return add_to_list(si, pnum, ec, &si->erase);
}
si->read_err_count += 1;
case UBI_IO_BAD_HDR:
case UBI_IO_FF_BITFLIPS:
- err = add_to_list(si, pnum, ec, &si->corr);
+ err = add_corrupted(si, pnum, ec);
if (err)
return err;
goto adjust_mean_ec;
case UBI_IO_FF:
if (ec_err)
- err = add_to_list(si, pnum, ec, &si->corr);
+ err = add_corrupted(si, pnum, ec);
else
err = add_to_list(si, pnum, ec, &si->free);
if (err)