aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/ubi/eba.c
diff options
context:
space:
mode:
authorRichard Weinberger <richard@nod.at>2014-10-07 10:31:22 -0400
committerRichard Weinberger <richard@nod.at>2015-03-26 17:45:58 -0400
commit36a87e44f642966442fd0d23f2ec536851e00236 (patch)
tree5450192a84593b98bcefbddd59dbb394397bee27 /drivers/mtd/ubi/eba.c
parentd2158f69a7d469c21c37f7028c18aa8c54707de3 (diff)
UBI: Fastmap: Fix race in ubi_eba_atomic_leb_change()
This function a) requests a new PEB, b) writes data to it, c) returns the old PEB and d) registers the new PEB in the EBA table. For the non-fastmap case this works perfectly fine and is powercut safe. Is fastmap enabled this can lead to issues. If a new fastmap is written between a) and c) the freshly requested PEB is no longer in a pool and will not be scanned upon attaching. If now a powercut happens between c) and d) the freshly requested PEB will not be scanned and the old one got already scheduled for erase. After attaching the EBA table will point to a erased PEB. Fix this issue by swapping steps c) and d). Signed-off-by: Richard Weinberger <richard@nod.at>
Diffstat (limited to 'drivers/mtd/ubi/eba.c')
-rw-r--r--drivers/mtd/ubi/eba.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/drivers/mtd/ubi/eba.c b/drivers/mtd/ubi/eba.c
index 8c9a710def99..e0a06e4b95a4 100644
--- a/drivers/mtd/ubi/eba.c
+++ b/drivers/mtd/ubi/eba.c
@@ -900,7 +900,7 @@ write_error:
900int ubi_eba_atomic_leb_change(struct ubi_device *ubi, struct ubi_volume *vol, 900int ubi_eba_atomic_leb_change(struct ubi_device *ubi, struct ubi_volume *vol,
901 int lnum, const void *buf, int len) 901 int lnum, const void *buf, int len)
902{ 902{
903 int err, pnum, tries = 0, vol_id = vol->vol_id; 903 int err, pnum, old_pnum, tries = 0, vol_id = vol->vol_id;
904 struct ubi_vid_hdr *vid_hdr; 904 struct ubi_vid_hdr *vid_hdr;
905 uint32_t crc; 905 uint32_t crc;
906 906
@@ -963,16 +963,17 @@ retry:
963 goto write_error; 963 goto write_error;
964 } 964 }
965 965
966 if (vol->eba_tbl[lnum] >= 0) {
967 err = ubi_wl_put_peb(ubi, vol_id, lnum, vol->eba_tbl[lnum], 0);
968 if (err)
969 goto out_leb_unlock;
970 }
971
972 down_read(&ubi->fm_sem); 966 down_read(&ubi->fm_sem);
967 old_pnum = vol->eba_tbl[lnum];
973 vol->eba_tbl[lnum] = pnum; 968 vol->eba_tbl[lnum] = pnum;
974 up_read(&ubi->fm_sem); 969 up_read(&ubi->fm_sem);
975 970
971 if (old_pnum >= 0) {
972 err = ubi_wl_put_peb(ubi, vol_id, lnum, old_pnum, 0);
973 if (err)
974 goto out_leb_unlock;
975 }
976
976out_leb_unlock: 977out_leb_unlock:
977 leb_write_unlock(ubi, vol_id, lnum); 978 leb_write_unlock(ubi, vol_id, lnum);
978out_mutex: 979out_mutex: