Skip to content

Commit

Permalink
kernel: mtk_bmt: allow get_mapping_block to return an error
Browse files Browse the repository at this point in the history
Used by the mapping implementation to indicate that no backing block is
available

Signed-off-by: Felix Fietkau <nbd@nbd.name>
  • Loading branch information
nbd168 committed Mar 25, 2022
1 parent 601c7b4 commit b4c7f8c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
27 changes: 22 additions & 5 deletions target/linux/generic/files/drivers/mtd/nand/mtk_bmt.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -219,14 +225,17 @@ 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;

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) {
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion target/linux/generic/files/drivers/mtd/nand/mtk_bmt.h
Expand Up @@ -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);
};

Expand Down
2 changes: 1 addition & 1 deletion target/linux/generic/files/drivers/mtd/nand/mtk_bmt_bbt.c
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion target/linux/generic/files/drivers/mtd/nand/mtk_bmt_v2.c
Expand Up @@ -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;

Expand Down

0 comments on commit b4c7f8c

Please sign in to comment.