diff options
author | Felix Fietkau <nbd@nbd.name> | 2022-03-09 15:54:52 +0100 |
---|---|---|
committer | Felix Fietkau <nbd@nbd.name> | 2022-10-10 12:58:18 +0200 |
commit | 0c21f06ef7544d7492537369b5c4c1ae3b87c935 (patch) | |
tree | 272527fe1d398845bab910bc6f8c3dd61fa56006 /target/linux | |
parent | a2ce32579f37cc19a99b02ab84bc95a9b6729390 (diff) | |
download | upstream-0c21f06ef7544d7492537369b5c4c1ae3b87c935.tar.gz upstream-0c21f06ef7544d7492537369b5c4c1ae3b87c935.tar.bz2 upstream-0c21f06ef7544d7492537369b5c4c1ae3b87c935.zip |
kernel: mtk_bmt: allow get_mapping_block to return an error
Used by the mapping implementation to indicate that no backing block is
available
Signed-off-by: Felix Fietkau <nbd@nbd.name>
(cherry-picked from commit b4c7f8c5f7a2dab76fe90849e112c6bd8f80ab19)
Diffstat (limited to 'target/linux')
4 files changed, 25 insertions, 8 deletions
diff --git a/target/linux/generic/files/drivers/mtd/nand/mtk_bmt.c b/target/linux/generic/files/drivers/mtd/nand/mtk_bmt.c index e7238ee62b..721eb0e6f0 100644 --- a/target/linux/generic/files/drivers/mtd/nand/mtk_bmt.c +++ b/target/linux/generic/files/drivers/mtd/nand/mtk_bmt.c @@ -111,9 +111,12 @@ mtk_bmt_read(struct mtd_info *mtd, loff_t from, u32 offset = from & (bmtd.blk_size - 1); u32 block = from >> bmtd.blk_shift; - u32 cur_block; + int cur_block; cur_block = bmtd.ops->get_mapping_block(block); + if (cur_block < 0) + return -EIO; + cur_from = ((loff_t)cur_block << bmtd.blk_shift) + offset; cur_ops.oobretlen = 0; @@ -174,9 +177,12 @@ mtk_bmt_write(struct mtd_info *mtd, loff_t to, while (ops->retlen < ops->len || ops->oobretlen < ops->ooblen) { u32 offset = to & (bmtd.blk_size - 1); u32 block = to >> bmtd.blk_shift; - u32 cur_block; + int cur_block; cur_block = bmtd.ops->get_mapping_block(block); + if (cur_block < 0) + return -EIO; + cur_to = ((loff_t)cur_block << bmtd.blk_shift) + offset; cur_ops.oobretlen = 0; @@ -219,7 +225,8 @@ mtk_bmt_mtd_erase(struct mtd_info *mtd, struct erase_info *instr) int retry_count = 0; u64 start_addr, end_addr; int ret; - u16 orig_block, block; + u16 orig_block; + int block; start_addr = instr->addr & (~mtd->erasesize_mask); end_addr = instr->addr + instr->len; @@ -227,6 +234,8 @@ mtk_bmt_mtd_erase(struct mtd_info *mtd, struct erase_info *instr) while (start_addr < end_addr) { orig_block = start_addr >> bmtd.blk_shift; block = bmtd.ops->get_mapping_block(orig_block); + if (block < 0) + return -EIO; mapped_instr.addr = (loff_t)block << bmtd.blk_shift; ret = bmtd._erase(mtd, &mapped_instr); if (ret) { @@ -265,7 +274,11 @@ static int mtk_bmt_block_markbad(struct mtd_info *mtd, loff_t ofs) { u16 orig_block = ofs >> bmtd.blk_shift; - u16 block = bmtd.ops->get_mapping_block(orig_block); + int block; + + block = bmtd.ops->get_mapping_block(orig_block); + if (block < 0) + return -EIO; bmtd.ops->remap_block(orig_block, block, bmtd.blk_size); @@ -298,7 +311,11 @@ static int mtk_bmt_debug_mark_good(void *data, u64 val) static int mtk_bmt_debug_mark_bad(void *data, u64 val) { u32 block = val >> bmtd.blk_shift; - u16 cur_block = bmtd.ops->get_mapping_block(block); + int cur_block; + + cur_block = bmtd.ops->get_mapping_block(block); + if (cur_block < 0) + return -EIO; bmtd.ops->remap_block(block, cur_block, bmtd.blk_size); diff --git a/target/linux/generic/files/drivers/mtd/nand/mtk_bmt.h b/target/linux/generic/files/drivers/mtd/nand/mtk_bmt.h index 25bdb40d9b..cea23f9207 100644 --- a/target/linux/generic/files/drivers/mtd/nand/mtk_bmt.h +++ b/target/linux/generic/files/drivers/mtd/nand/mtk_bmt.h @@ -19,7 +19,7 @@ struct mtk_bmt_ops { int (*init)(struct device_node *np); bool (*remap_block)(u16 block, u16 mapped_block, int copy_len); void (*unmap_block)(u16 block); - u16 (*get_mapping_block)(int block); + int (*get_mapping_block)(int block); int (*debug)(void *data, u64 val); }; diff --git a/target/linux/generic/files/drivers/mtd/nand/mtk_bmt_bbt.c b/target/linux/generic/files/drivers/mtd/nand/mtk_bmt_bbt.c index fe1040802e..3a58f52277 100644 --- a/target/linux/generic/files/drivers/mtd/nand/mtk_bmt_bbt.c +++ b/target/linux/generic/files/drivers/mtd/nand/mtk_bmt_bbt.c @@ -39,7 +39,7 @@ bbt_set_block_state(u16 block, bool bad) write_bmt(bmtd.bmt_blk_idx, bmtd.bbt_buf); } -static u16 +static int get_mapping_block_index_bbt(int block) { int start, end, ofs; diff --git a/target/linux/generic/files/drivers/mtd/nand/mtk_bmt_v2.c b/target/linux/generic/files/drivers/mtd/nand/mtk_bmt_v2.c index b7ce7e2ca8..f2dc05be2b 100644 --- a/target/linux/generic/files/drivers/mtd/nand/mtk_bmt_v2.c +++ b/target/linux/generic/files/drivers/mtd/nand/mtk_bmt_v2.c @@ -306,7 +306,7 @@ static bool remap_block_v2(u16 block, u16 mapped_block, int copy_len) return true; } -static u16 get_mapping_block_index_v2(int block) +static int get_mapping_block_index_v2(int block) { int start, end; |