Merge "[Bugfix][API-640][Data]fix datalist without output info" into MR3.0
diff --git a/src/kernel/linux/v4.19/drivers/mtd/nandx/core/nand_chip.c b/src/kernel/linux/v4.19/drivers/mtd/nandx/core/nand_chip.c
index acb1445..702da05 100644
--- a/src/kernel/linux/v4.19/drivers/mtd/nandx/core/nand_chip.c
+++ b/src/kernel/linux/v4.19/drivers/mtd/nandx/core/nand_chip.c
@@ -63,7 +63,10 @@
 		}
 		nand->performance->read_data_time = (int)time_cons;
 #endif
-
+		/*jb.qi change for ubi problem on 20221026 start*/
+		if (ops[i].status < 0)
+			pr_err("%s, row:0x%x, status: %d\n", __func__, row, ops[i].status);
+		/*jb.qi change for ubi problem on 20221026 end*/
 		ret_max = max_t(int, ret_max, ops[i].status);
 		ret_min = min_t(int, ret_min, ops[i].status);
 #if NANDX_PAGE_PERFORMANCE_TRACE
@@ -99,6 +102,8 @@
 		row = ops[i].row;
 		col = ops[i].col;
 
+		pr_err("%s, row:0x%x\n", __func__, row);//jb.qi change for ubi problem on 20221026 start
+
 		nand->addressing(nand, &row, &col);
 
 		ops[i].status = nand->write_enable(nand);
@@ -176,6 +181,8 @@
 
 		nand->addressing(nand, &row, &col);
 
+		pr_err("%s, row:0x%x\n", __func__, row);//jb.qi change for ubi problem on 20221026 start
+
 		ops[i].status = nand->write_enable(nand);
 		if (ops[i].status) {
 			pr_debug("Write Protect at %x!\n", row);
diff --git a/src/kernel/linux/v4.19/drivers/mtd/ubi/io.c b/src/kernel/linux/v4.19/drivers/mtd/ubi/io.c
index 0e3a76a..b55b6d0 100644
--- a/src/kernel/linux/v4.19/drivers/mtd/ubi/io.c
+++ b/src/kernel/linux/v4.19/drivers/mtd/ubi/io.c
@@ -466,16 +466,8 @@
 	loff_t addr;
 	uint32_t data = 0;
 	struct ubi_ec_hdr ec_hdr;
-	struct ubi_vid_io_buf vidb;
-
-	/*
-	 * Note, we cannot generally define VID header buffers on stack,
-	 * because of the way we deal with these buffers (see the header
-	 * comment in this file). But we know this is a NOR-specific piece of
-	 * code, so we can do this. But yes, this is error-prone and we should
-	 * (pre-)allocate VID header buffer instead.
-	 */
-	struct ubi_vid_hdr vid_hdr;
+        /*jb.qi change for ubi problem on 20221026 start*/
+	struct ubi_vid_io_buf *vidb;
 
 	/*
 	 * If VID or EC is valid, we have to corrupt them before erasing.
@@ -485,25 +477,33 @@
 	 * corrupted and will try to preserve it, and print scary warnings.
 	 */
 	addr = (loff_t)pnum * ubi->peb_size;
-	err = ubi_io_read_ec_hdr(ubi, pnum, &ec_hdr, 0);
-	if (err != UBI_IO_BAD_HDR_EBADMSG && err != UBI_IO_BAD_HDR &&
-	    err != UBI_IO_FF){
-		err = mtd_write(ubi->mtd, addr, 4, &written, (void *)&data);
-		if(err)
+	vidb = ubi_alloc_vid_buf(ubi, GFP_NOFS);
+	if (!vidb)
+		return -ENOMEM;
+
+	ec_err = ubi_io_read_ec_hdr(ubi, pnum, &ec_hdr, 0);
+	vid_err = ubi_io_read_ec_hdr(ubi, pnum, vidb, 0);
+	if (ec_err != UBI_IO_BAD_HDR_EBADMSG && ec_err != UBI_IO_BAD_HDR &&
+	    ec_err != UBI_IO_FF){
+		ec_err = mtd_write(ubi->mtd, addr, 4, &written, (void *)&data);
+		if(ec_err) {
+			err = ec_err;
 			goto error;
+		}
 	}
 
-	ubi_init_vid_buf(ubi, &vidb, &vid_hdr);
-	ubi_assert(&vid_hdr == ubi_get_vid_hdr(&vidb));
-
-	err = ubi_io_read_vid_hdr(ubi, pnum, &vidb, 0);
-	if (err != UBI_IO_BAD_HDR_EBADMSG && err != UBI_IO_BAD_HDR &&
-	    err != UBI_IO_FF){
+	if (vid_err != UBI_IO_BAD_HDR_EBADMSG && vid_err != UBI_IO_BAD_HDR &&
+	    vid_err != UBI_IO_FF){
 		addr += ubi->vid_hdr_aloffset;
-		err = mtd_write(ubi->mtd, addr, 4, &written, (void *)&data);
-		if (err)
-			goto error;
+		vid_err = mtd_write(ubi->mtd, addr, 4, &written, (void *)&data);
+		if(vid_err) {
+			err = vid_err;
+ 			goto error;
+		}
 	}
+
+	ubi_free_vid_buf(vidb);
+        /*jb.qi change for ubi problem on 20221026 end*/
 	return 0;
 
 error:
@@ -514,6 +514,7 @@
 	 */
 	ubi_err(ubi, "cannot invalidate PEB %d, write returned %d", pnum, err);
 	ubi_dump_flash(ubi, pnum, 0, ubi->peb_size);
+	ubi_free_vid_buf(vidb);//jb.qi change for ubi problem on 20221026 
 	return -EIO;
 }
 
@@ -547,13 +548,11 @@
 		ubi_err(ubi, "read-only mode");
 		return -EROFS;
 	}
-
-	if (ubi->nor_flash) {
-		err = nor_erase_prepare(ubi, pnum);
-		if (err)
-			return err;
-	}
-
+	/*jb.qi change for ubi problem on 20221026 start*/
+	err = erase_prepare(ubi, pnum);
+	if (err)
+		return err;
+	/*jb.qi change for ubi problem on 20221026 end*/
 	if (torture) {
 		ret = torture_peb(ubi, pnum);
 		if (ret < 0)
diff --git a/src/kernel/linux/v4.19/fs/ubifs/lpt.c b/src/kernel/linux/v4.19/fs/ubifs/lpt.c
index 3139337..22ba82e 100644
--- a/src/kernel/linux/v4.19/fs/ubifs/lpt.c
+++ b/src/kernel/linux/v4.19/fs/ubifs/lpt.c
@@ -1334,6 +1334,11 @@
 	buf = vmalloc(c->ltab_sz);
 	if (!buf)
 		return -ENOMEM;
+	/*jb.qi change for ubi problem on 20221026 start*/
+	/* check the whole LEB */
+	ubifs_err(c, "check the LEB of ltab!\n");
+	ubifs_leb_read(c, c->ltab_lnum, c->sbuf, 0, c->leb_size, 1);
+	/*jb.qi change for ubi problem on 20221026 end*/
 	err = ubifs_leb_read(c, c->ltab_lnum, buf, c->ltab_offs, c->ltab_sz, 1);
 	if (err)
 		goto out;
diff --git a/src/kernel/linux/v4.19/fs/ubifs/recovery.c b/src/kernel/linux/v4.19/fs/ubifs/recovery.c
index 984e30e..36107ee 100644
--- a/src/kernel/linux/v4.19/fs/ubifs/recovery.c
+++ b/src/kernel/linux/v4.19/fs/ubifs/recovery.c
@@ -933,7 +933,7 @@
 	/* Read at the head location and check it is empty flash */
 	err = ubifs_leb_read(c, lnum, sbuf, offs, len, 1);
 	if (err || !is_empty(sbuf, len)) {
-		dbg_rcvry("cleaning head at %d:%d", lnum, offs);
+		ubifs_err(c, "cleaning head at %d:%d", lnum, offs); //jb.qi change for ubi problem on 20221026
 		if (offs == 0)
 			return ubifs_leb_unmap(c, lnum);
 		err = ubifs_leb_read(c, lnum, sbuf, 0, offs, 1);
@@ -968,12 +968,12 @@
 
 	ubifs_assert(c, !c->ro_mount || c->remounting_rw);
 
-	dbg_rcvry("checking index head at %d:%d", c->ihead_lnum, c->ihead_offs);
+	ubifs_err(c, "checking index head at %d:%d", c->ihead_lnum, c->ihead_offs);//jb.qi change for ubi problem on 20221026
 	err = recover_head(c, c->ihead_lnum, c->ihead_offs, sbuf);
 	if (err)
 		return err;
 
-	dbg_rcvry("checking LPT head at %d:%d", c->nhead_lnum, c->nhead_offs);
+	ubifs_err(c, "checking LPT head at %d:%d", c->nhead_lnum, c->nhead_offs);//jb.qi change for ubi problem on 20221026
 
 	return recover_head(c, c->nhead_lnum, c->nhead_offs, sbuf);
 }