[bug report] mtd: bad block counter inflated when repeatedly marking the same block
Wang Zhaolong
wangzhaolong at huaweicloud.com
Mon Sep 1 07:14:12 PDT 2025
>>
>> Possible fixes (high level)
>> - Core-side conservative fix (minimal ABI change):
>> * In mtd_block_markbad(), probe _block_isbad(master, ofs) before
>> calling _block_markbad(), and (if available) probe again after success.
>> * Only increment ecc_stats.badblocks if the state transitioned from
>> “good” to “bad”.
>
> IMHO, the return value of _block_markbad() is used to identify whether the block becomes bad successfully after the operation, the extra message(eg. whether the block is already bad or newly marked as bad) could be passed out from a pointer-type function parameter.
> Since there is only one place (mtd_block_markbad) invokes the _block_markbad(), I prefer the conservative(simple) fix.
>
Thanks for the clarification!
I agree with your interpretation of _block_markbad()’s return value
(0 = success, <0 = error).
Given there is only one caller (mtd_block_markbad), I’ll proceed with
the conservative fix.
Thanks again!
Best regards,
Wang Zhaolong
More information about the linux-mtd
mailing list