UBI: Fix double free after do_sync_erase()

If the erase worker is unable to erase a PEB it will
free the ubi_wl_entry itself.
The failing ubi_wl_entry must not free()'d again after
do_sync_erase() returns.

Cc: <stable@vger.kernel.org>
Signed-off-by: Richard Weinberger <richard@nod.at>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
This commit is contained in:
Richard Weinberger 2014-11-06 16:47:49 +01:00 коммит произвёл Artem Bityutskiy
Родитель a76284e6f8
Коммит aa5ad3b6eb
1 изменённых файлов: 3 добавлений и 7 удалений

Просмотреть файл

@ -1216,7 +1216,6 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk,
err = do_sync_erase(ubi, e1, vol_id, lnum, 0); err = do_sync_erase(ubi, e1, vol_id, lnum, 0);
if (err) { if (err) {
kmem_cache_free(ubi_wl_entry_slab, e1);
if (e2) if (e2)
kmem_cache_free(ubi_wl_entry_slab, e2); kmem_cache_free(ubi_wl_entry_slab, e2);
goto out_ro; goto out_ro;
@ -1230,10 +1229,8 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk,
dbg_wl("PEB %d (LEB %d:%d) was put meanwhile, erase", dbg_wl("PEB %d (LEB %d:%d) was put meanwhile, erase",
e2->pnum, vol_id, lnum); e2->pnum, vol_id, lnum);
err = do_sync_erase(ubi, e2, vol_id, lnum, 0); err = do_sync_erase(ubi, e2, vol_id, lnum, 0);
if (err) { if (err)
kmem_cache_free(ubi_wl_entry_slab, e2);
goto out_ro; goto out_ro;
}
} }
dbg_wl("done"); dbg_wl("done");
@ -1269,10 +1266,9 @@ out_not_moved:
ubi_free_vid_hdr(ubi, vid_hdr); ubi_free_vid_hdr(ubi, vid_hdr);
err = do_sync_erase(ubi, e2, vol_id, lnum, torture); err = do_sync_erase(ubi, e2, vol_id, lnum, torture);
if (err) { if (err)
kmem_cache_free(ubi_wl_entry_slab, e2);
goto out_ro; goto out_ro;
}
mutex_unlock(&ubi->move_mutex); mutex_unlock(&ubi->move_mutex);
return 0; return 0;