kernel: mtk_bmt: allow get_mapping_block to return an error
authorFelix Fietkau <nbd@nbd.name>
Wed, 9 Mar 2022 14:54:52 +0000 (15:54 +0100)
committerFelix Fietkau <nbd@nbd.name>
Fri, 25 Mar 2022 20:11:09 +0000 (21:11 +0100)
Used by the mapping implementation to indicate that no backing block is
available

Signed-off-by: Felix Fietkau <nbd@nbd.name>
target/linux/generic/files/drivers/mtd/nand/mtk_bmt.c
target/linux/generic/files/drivers/mtd/nand/mtk_bmt.h
target/linux/generic/files/drivers/mtd/nand/mtk_bmt_bbt.c
target/linux/generic/files/drivers/mtd/nand/mtk_bmt_v2.c

index e7238ee62b322705fbeabcc075c482a483675345..721eb0e6f0507df1c74e356abafa1282bd8715a8 100644 (file)
@@ -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);
 
index 25bdb40d9b1e1ab253341c6feb8cc48137130c64..cea23f9207f5fc18d9bedde418b6a516f5c7c0b7 100644 (file)
@@ -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);
 };
 
index fe1040802ecc21122cb62ac62272e4335228b627..3a58f522776d09b4e5ade4cbaca551db5c98657d 100644 (file)
@@ -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;
index b7ce7e2ca8dda3a9e38567163959e126959632ab..f2dc05be2bc475dc1799216374dcda8d114a3137 100644 (file)
@@ -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;