[openwrt/openwrt] mediatek: mtk-snand: check request size against chip info

LEDE Commits lede-commits at lists.infradead.org
Thu Aug 26 20:31:42 PDT 2021


981213 pushed a commit to openwrt/openwrt.git, branch master:
https://git.openwrt.org/388127abd139d3ebbe761392403d58d58f5957cd

commit 388127abd139d3ebbe761392403d58d58f5957cd
Author: Chuanhong Guo <gch981213 at gmail.com>
AuthorDate: Tue Aug 24 00:31:17 2021 +0800

    mediatek: mtk-snand: check request size against chip info
    
    mtd->size will be overrided by BMT which makes all mtd requests made by
    bmt fail in request size checking.
    this commit changes the driver to check against actual chip size in chip
    info as a workaround.
    
    Signed-off-by: Chuanhong Guo <gch981213 at gmail.com>
---
 .../drivers/mtd/mtk-snand/mtk-snand-mtd.c          | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/target/linux/mediatek/files-5.10/drivers/mtd/mtk-snand/mtk-snand-mtd.c b/target/linux/mediatek/files-5.10/drivers/mtd/mtk-snand/mtk-snand-mtd.c
index b0fcda446d..7e5baf0369 100644
--- a/target/linux/mediatek/files-5.10/drivers/mtd/mtk-snand/mtk-snand-mtd.c
+++ b/target/linux/mediatek/files-5.10/drivers/mtd/mtk-snand/mtk-snand-mtd.c
@@ -57,7 +57,7 @@ static int mtk_snand_mtd_erase(struct mtd_info *mtd, struct erase_info *instr)
 	int ret;
 
 	/* Do not allow write past end of device */
-	if ((instr->addr + instr->len) > mtd->size) {
+	if ((instr->addr + instr->len) > msm->cinfo.chipsize) {
 		dev_err(msm->pdev.dev,
 			"attempt to erase beyond end of device\n");
 		return -EINVAL;
@@ -194,7 +194,7 @@ static int mtk_snand_mtd_read_oob(struct mtd_info *mtd, loff_t from,
 	maxooblen = mtd_oobavail(mtd, ops);
 
 	/* Do not allow read past end of device */
-	if (ops->datbuf && (from + ops->len) > mtd->size) {
+	if (ops->datbuf && (from + ops->len) > msm->cinfo.chipsize) {
 		dev_err(msm->pdev.dev,
 			"attempt to read beyond end of device\n");
 		return -EINVAL;
@@ -205,9 +205,11 @@ static int mtk_snand_mtd_read_oob(struct mtd_info *mtd, loff_t from,
 		return -EINVAL;
 	}
 
-	if (unlikely(from >= mtd->size ||
-	    ops->ooboffs + ops->ooblen > ((mtd->size >> mtd->writesize_shift) -
-	    (from >> mtd->writesize_shift)) * maxooblen)) {
+	if (unlikely(from >= msm->cinfo.chipsize ||
+		     ops->ooboffs + ops->ooblen >
+			     ((msm->cinfo.chipsize >> mtd->writesize_shift) -
+			      (from >> mtd->writesize_shift)) *
+				     maxooblen)) {
 		dev_err(msm->pdev.dev,
 			"attempt to read beyond end of device\n");
 		return -EINVAL;
@@ -321,7 +323,7 @@ static int mtk_snand_mtd_write_oob(struct mtd_info *mtd, loff_t to,
 	maxooblen = mtd_oobavail(mtd, ops);
 
 	/* Do not allow write past end of device */
-	if (ops->datbuf && (to + ops->len) > mtd->size) {
+	if (ops->datbuf && (to + ops->len) > msm->cinfo.chipsize) {
 		dev_err(msm->pdev.dev,
 			"attempt to write beyond end of device\n");
 		return -EINVAL;
@@ -333,9 +335,11 @@ static int mtk_snand_mtd_write_oob(struct mtd_info *mtd, loff_t to,
 		return -EINVAL;
 	}
 
-	if (unlikely(to >= mtd->size ||
-	    ops->ooboffs + ops->ooblen > ((mtd->size >> mtd->writesize_shift) -
-	    (to >> mtd->writesize_shift)) * maxooblen)) {
+	if (unlikely(to >= msm->cinfo.chipsize ||
+		     ops->ooboffs + ops->ooblen >
+			     ((msm->cinfo.chipsize >> mtd->writesize_shift) -
+			      (to >> mtd->writesize_shift)) *
+				     maxooblen)) {
 		dev_err(msm->pdev.dev,
 			"attempt to write beyond end of device\n");
 		return -EINVAL;



More information about the lede-commits mailing list