Skip to content

Commit 31a149d

Browse files
wyqkprichardweinberger
authored andcommitted
ubi: Fix return value overwrite issue in try_write_vid_and_data()
The commit 2d78aee ("UBI: simplify LEB write and atomic LEB change code") adds helper function, try_write_vid_and_data(), to simplify the code, but this helper function has bug, it will return 0 (success) when ubi_io_write_vid_hdr() or the ubi_io_write_data() return error number (-EIO, etc), because the return value of ubi_wl_put_peb() will overwrite the original return value. This issue will cause unexpected data loss issue, because the caller of this function and UBIFS willn't know the data is lost. Fixes: 2d78aee ("UBI: simplify LEB write and atomic LEB change code") Cc: stable@vger.kernel.org Signed-off-by: Wang YanQing <udknight@gmail.com> Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com> Signed-off-by: Richard Weinberger <richard@nod.at>
1 parent c477d83 commit 31a149d

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

drivers/mtd/ubi/eba.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ static int try_write_vid_and_data(struct ubi_volume *vol, int lnum,
946946
int offset, int len)
947947
{
948948
struct ubi_device *ubi = vol->ubi;
949-
int pnum, opnum, err, vol_id = vol->vol_id;
949+
int pnum, opnum, err, err2, vol_id = vol->vol_id;
950950

951951
pnum = ubi_wl_get_peb(ubi);
952952
if (pnum < 0) {
@@ -981,10 +981,19 @@ static int try_write_vid_and_data(struct ubi_volume *vol, int lnum,
981981
out_put:
982982
up_read(&ubi->fm_eba_sem);
983983

984-
if (err && pnum >= 0)
985-
err = ubi_wl_put_peb(ubi, vol_id, lnum, pnum, 1);
986-
else if (!err && opnum >= 0)
987-
err = ubi_wl_put_peb(ubi, vol_id, lnum, opnum, 0);
984+
if (err && pnum >= 0) {
985+
err2 = ubi_wl_put_peb(ubi, vol_id, lnum, pnum, 1);
986+
if (err2) {
987+
ubi_warn(ubi, "failed to return physical eraseblock %d, error %d",
988+
pnum, err2);
989+
}
990+
} else if (!err && opnum >= 0) {
991+
err2 = ubi_wl_put_peb(ubi, vol_id, lnum, opnum, 0);
992+
if (err2) {
993+
ubi_warn(ubi, "failed to return physical eraseblock %d, error %d",
994+
opnum, err2);
995+
}
996+
}
988997

989998
return err;
990999
}

0 commit comments

Comments
 (0)