[PATCH v2 09/62] UBI: Fix double free after do_sync_erase()

Teresa Remmet t.remmet at phytec.de
Fri May 27 00:44:02 PDT 2016


From: Richard Weinberger <richard at nod.at>

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 at vger.kernel.org>
Signed-off-by: Richard Weinberger <richard at nod.at>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy at linux.intel.com>

Conflicts:
	drivers/mtd/ubi/wl.c

Fixed small conflict.

Signed-off-by: Teresa Remmet <t.remmet at phytec.de>
---
 drivers/mtd/ubi/wl.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index fa8f019..dcc012c 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -1160,7 +1160,6 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk,
 
 	err = do_sync_erase(ubi, e1, vol_id, lnum, 0);
 	if (err) {
-		kfree(e1);
 		if (e2)
 			kfree(e2);
 		goto out_ro;
@@ -1174,10 +1173,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",
 		       e2->pnum, vol_id, lnum);
 		err = do_sync_erase(ubi, e2, vol_id, lnum, 0);
-		if (err) {
-			kfree(e2);
+		if (err)
 			goto out_ro;
-		}
 	}
 
 	dbg_wl("done");
@@ -1210,10 +1207,9 @@ out_not_moved:
 
 	ubi_free_vid_hdr(ubi, vid_hdr);
 	err = do_sync_erase(ubi, e2, vol_id, lnum, torture);
-	if (err) {
-		kfree(e2);
+	if (err)
 		goto out_ro;
-	}
+
 	return 0;
 
 out_error:
-- 
1.9.1




More information about the barebox mailing list