From fcfd9cc47f1b8765b725c8bcc2a43435e50ccc4b Mon Sep 17 00:00:00 2001 From: "xianjun.liu" Date: Wed, 12 Sep 2018 11:00:52 +0800 Subject: [PATCH] mtd: fix recoverity isuue PD#172180: fix coverity issue for mtd Change-Id: I00725b398edbee55863868c53ed901fb80607bd1 Signed-off-by: xianjun.liu --- drivers/amlogic/mtd/aml_nand.c | 10 +++++++--- drivers/amlogic/mtd/boot.c | 6 +++--- drivers/amlogic/mtd/new_nand.c | 4 ++-- drivers/amlogic/mtd/rsv_manage.c | 11 ++++++----- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/drivers/amlogic/mtd/aml_nand.c b/drivers/amlogic/mtd/aml_nand.c index f8318ea69..7251fff 100644 --- a/drivers/amlogic/mtd/aml_nand.c +++ b/drivers/amlogic/mtd/aml_nand.c @@ -343,10 +343,15 @@ static int aml_nand_add_partition(struct aml_nand_chip *aml_chip) uint64_t start_blk = 0, part_blk = 0; loff_t offset; int phys_erase_shift, error = 0; + int plane_num_shift = 0; if (!mtd->erasesize) return -EINVAL; phys_erase_shift = fls(mtd->erasesize) - 1; + + if (!aml_chip->plane_num) + return -EINVAL; + plane_num_shift = fls(aml_chip->plane_num) - 1; #endif parts = plat->platform_nand_data.chip.partitions; @@ -370,9 +375,8 @@ static int aml_nand_add_partition(struct aml_nand_chip *aml_chip) return -ENOMEM; } if (nand_boot_flag) - adjust_offset = - (loff_t)(1024 * mtd->writesize / - aml_chip->plane_num); + adjust_offset = (1024 * ((loff_t)mtd->writesize) >> + plane_num_shift); bl_mode = aml_chip->bl_mode; if (bl_mode == NAND_FIPMODE_DISCRETE) { /* descrete bootloader mode */ diff --git a/drivers/amlogic/mtd/boot.c b/drivers/amlogic/mtd/boot.c index 6a9ca2c..457547ce 100644 --- a/drivers/amlogic/mtd/boot.c +++ b/drivers/amlogic/mtd/boot.c @@ -183,7 +183,7 @@ int m3_nand_boot_erase_cmd(struct mtd_info *mtd, int page) struct nand_chip *chip = mtd->priv; loff_t ofs; - ofs = (loff_t)(page << chip->page_shift); + ofs = ((loff_t)page << chip->page_shift); if (chip->block_bad(mtd, ofs)) return -1; @@ -337,7 +337,7 @@ int m3_nand_boot_read_page_hwecc(struct mtd_info *mtd, read_page = page; read_page++; READ_BAD_BLOCK: - ofs = (uint64_t)(read_page << chip->page_shift); + ofs = ((uint64_t)read_page << chip->page_shift); tmp = ofs; div_u64_rem(tmp, mtd->erasesize, &remainder); if (!remainder) { @@ -592,7 +592,7 @@ int m3_nand_boot_write_page(struct mtd_info *mtd, struct nand_chip *chip, write_page++; WRITE_BAD_BLOCK: - ofs = (uint64_t)(write_page << chip->page_shift); + ofs = ((uint64_t)write_page << chip->page_shift); tmp = ofs; div_u64_rem(tmp, mtd->erasesize, &remainder); if (!remainder) { diff --git a/drivers/amlogic/mtd/new_nand.c b/drivers/amlogic/mtd/new_nand.c index 32389ff..88cf04c 100644 --- a/drivers/amlogic/mtd/new_nand.c +++ b/drivers/amlogic/mtd/new_nand.c @@ -452,7 +452,7 @@ int aml_nand_slcprog_1ynm_hynix(struct mtd_info *mtd, aml_oob_ops.ooboffs = 0;/*fixme! all layout offs is zero*/ aml_oob_ops.datbuf = data_buf; aml_oob_ops.oobbuf = oob_buf; - op_add = (loff_t)(next_msb_page*mtd->writesize); + op_add = ((loff_t)next_msb_page*mtd->writesize); mtd->_write_oob(mtd, op_add, &aml_oob_ops); pr_info("Eneter 1y nm SLC mode ,must fill 0xff data into %d\n", next_msb_page); @@ -464,7 +464,7 @@ int aml_nand_slcprog_1ynm_hynix(struct mtd_info *mtd, aml_oob_ops.ooboffs = 0;/*fixme! all layout offs is zero*/ aml_oob_ops.datbuf = buf; aml_oob_ops.oobbuf = oob_buf; - op_add = (loff_t)(op_page_add*mtd->writesize); + op_add = ((loff_t)op_page_add*mtd->writesize); error = mtd->_write_oob(mtd, op_add, &aml_oob_ops); pr_info("Eneter 1y nm SLC mode ,write systerm data into %d\n", op_page_add); diff --git a/drivers/amlogic/mtd/rsv_manage.c b/drivers/amlogic/mtd/rsv_manage.c index 4ef1b92..343a7f5 100644 --- a/drivers/amlogic/mtd/rsv_manage.c +++ b/drivers/amlogic/mtd/rsv_manage.c @@ -144,11 +144,12 @@ int aml_nand_scan_shipped_bbt(struct mtd_info *mtd) struct aml_nand_platform *plat = aml_chip->platform; unsigned char *data_buf; int32_t read_cnt, page, pages_per_blk; - loff_t addr, offset; + loff_t addr; int start_blk = 0, total_blk = 0, bad_blk_cnt = 0, phys_erase_shift; int realpage, col0_data = 0, col0_oob = 0, valid_page_num = 1; int col_data_sandisk[6] = {0}, bad_sandisk_flag = 0; int i, j; + uint32_t offset; if (!mtd->erasesize) return -EINVAL; @@ -166,8 +167,8 @@ int aml_nand_scan_shipped_bbt(struct mtd_info *mtd) memset(&aml_chip->nand_bbt_info->nand_bbt[0], 0, MAX_BAD_BLK_NUM); if (nand_boot_flag) - offset = - (loff_t)(1024 * mtd->writesize / aml_chip->plane_num); + offset = (1024 * mtd->writesize / + aml_chip->plane_num); else offset = 0; @@ -185,9 +186,9 @@ int aml_nand_scan_shipped_bbt(struct mtd_info *mtd) /* if (aml_chip->valid_chip[i]) { */ for (read_cnt = 0; read_cnt < 2; read_cnt++) { if (aml_chip->mfr_type == NAND_MFR_SANDISK) { - addr = offset + read_cnt*mtd->writesize; + addr = (loff_t)offset + read_cnt*mtd->writesize; } else - addr = offset + + addr = (loff_t)offset + (pages_per_blk - 1) * read_cnt * mtd->writesize; realpage = (int)(addr >> chip->page_shift); -- 2.7.4