Skip to content

Commit 9781c38

Browse files
Wang Zhaolongmiquelraynal
authored andcommitted
mtd: core: skip badblocks increment for blocks already known bad
Repeatedly marking the same eraseblock bad inflates mtd->ecc_stats.badblocks because mtd_block_markbad() unconditionally increments the counter on success, while some implementations (e.g. NAND) return 0 both when the block was already bad and when it has just been marked[1]. Fix by checking if the block is already bad before calling ->_block_markbad() when _block_isbad is available. Only skip the counter increment when we can confirm the block was already bad. In all other cases continue incrementing the counter. This keeps the logic centralized in mtdcore without requiring driver changes. Link: https://lore.kernel.org/all/ef573188-9815-4a6b-bad1-3d8ff7c9b16f@huaweicloud.com/ [1] Signed-off-by: Wang Zhaolong <wangzhaolong@huaweicloud.com> Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
1 parent 81eb13a commit 9781c38

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

drivers/mtd/mtdcore.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2389,6 +2389,7 @@ EXPORT_SYMBOL_GPL(mtd_block_isbad);
23892389
int mtd_block_markbad(struct mtd_info *mtd, loff_t ofs)
23902390
{
23912391
struct mtd_info *master = mtd_get_master(mtd);
2392+
loff_t moffs;
23922393
int ret;
23932394

23942395
if (!master->_block_markbad)
@@ -2401,7 +2402,15 @@ int mtd_block_markbad(struct mtd_info *mtd, loff_t ofs)
24012402
if (mtd->flags & MTD_SLC_ON_MLC_EMULATION)
24022403
ofs = (loff_t)mtd_div_by_eb(ofs, mtd) * master->erasesize;
24032404

2404-
ret = master->_block_markbad(master, mtd_get_master_ofs(mtd, ofs));
2405+
moffs = mtd_get_master_ofs(mtd, ofs);
2406+
2407+
if (master->_block_isbad) {
2408+
ret = master->_block_isbad(master, moffs);
2409+
if (ret > 0)
2410+
return 0;
2411+
}
2412+
2413+
ret = master->_block_markbad(master, moffs);
24052414
if (ret)
24062415
return ret;
24072416

0 commit comments

Comments
 (0)