Merge tag 'folio-5.18d' of git://git.infradead.org/users/willy/pagecache
[linux-2.6-microblaze.git] / drivers / mtd / ubi / fastmap.c
index 53f448e..6b5f1ff 100644 (file)
@@ -468,7 +468,9 @@ static int scan_pool(struct ubi_device *ubi, struct ubi_attach_info *ai,
                        if (err == UBI_IO_FF_BITFLIPS)
                                scrub = 1;
 
-                       add_aeb(ai, free, pnum, ec, scrub);
+                       ret = add_aeb(ai, free, pnum, ec, scrub);
+                       if (ret)
+                               goto out;
                        continue;
                } else if (err == 0 || err == UBI_IO_BITFLIPS) {
                        dbg_bld("Found non empty PEB:%i in pool", pnum);
@@ -638,8 +640,10 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
                if (fm_pos >= fm_size)
                        goto fail_bad;
 
-               add_aeb(ai, &ai->free, be32_to_cpu(fmec->pnum),
-                       be32_to_cpu(fmec->ec), 0);
+               ret = add_aeb(ai, &ai->free, be32_to_cpu(fmec->pnum),
+                             be32_to_cpu(fmec->ec), 0);
+               if (ret)
+                       goto fail;
        }
 
        /* read EC values from used list */
@@ -649,8 +653,10 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
                if (fm_pos >= fm_size)
                        goto fail_bad;
 
-               add_aeb(ai, &used, be32_to_cpu(fmec->pnum),
-                       be32_to_cpu(fmec->ec), 0);
+               ret = add_aeb(ai, &used, be32_to_cpu(fmec->pnum),
+                             be32_to_cpu(fmec->ec), 0);
+               if (ret)
+                       goto fail;
        }
 
        /* read EC values from scrub list */
@@ -660,8 +666,10 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
                if (fm_pos >= fm_size)
                        goto fail_bad;
 
-               add_aeb(ai, &used, be32_to_cpu(fmec->pnum),
-                       be32_to_cpu(fmec->ec), 1);
+               ret = add_aeb(ai, &used, be32_to_cpu(fmec->pnum),
+                             be32_to_cpu(fmec->ec), 1);
+               if (ret)
+                       goto fail;
        }
 
        /* read EC values from erase list */
@@ -671,8 +679,10 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
                if (fm_pos >= fm_size)
                        goto fail_bad;
 
-               add_aeb(ai, &ai->erase, be32_to_cpu(fmec->pnum),
-                       be32_to_cpu(fmec->ec), 1);
+               ret = add_aeb(ai, &ai->erase, be32_to_cpu(fmec->pnum),
+                             be32_to_cpu(fmec->ec), 1);
+               if (ret)
+                       goto fail;
        }
 
        ai->mean_ec = div_u64(ai->ec_sum, ai->ec_count);
@@ -1220,6 +1230,17 @@ static int ubi_write_fastmap(struct ubi_device *ubi,
                fm_pos += sizeof(*fec);
                ubi_assert(fm_pos <= ubi->fm_size);
        }
+       if (ubi->fm_next_anchor) {
+               fec = (struct ubi_fm_ec *)(fm_raw + fm_pos);
+
+               fec->pnum = cpu_to_be32(ubi->fm_next_anchor->pnum);
+               set_seen(ubi, ubi->fm_next_anchor->pnum, seen_pebs);
+               fec->ec = cpu_to_be32(ubi->fm_next_anchor->ec);
+
+               free_peb_count++;
+               fm_pos += sizeof(*fec);
+               ubi_assert(fm_pos <= ubi->fm_size);
+       }
        fmh->free_peb_count = cpu_to_be32(free_peb_count);
 
        ubi_for_each_used_peb(ubi, wl_e, tmp_rb) {