From: Zhihao Cheng <chengzhihao1@huawei.com>
To: Wang Zhaolong <wangzhaolong@huaweicloud.com>,
<miquel.raynal@bootlin.com>, <richard@nod.at>, <vigneshr@ti.com>
Cc: <linux-mtd@lists.infradead.org>, <linux-kernel@vger.kernel.org>,
<yi.zhang@huawei.com>, <yangerkun@huawei.com>
Subject: Re: [PATCH V2] mtd: core: skip badblocks increment for blocks already known bad
Date: Tue, 2 Sep 2025 19:41:06 +0800 [thread overview]
Message-ID: <95bf5e07-7f03-efb0-da9b-cb50999c2524@huawei.com> (raw)
In-Reply-To: <20250902092732.2244544-1-wangzhaolong@huaweicloud.com>
在 2025/9/2 17:27, Wang Zhaolong 写道:
> 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>
> ---
>
> V2:
> - Checks old state when _block_isbad exists and bails out early if already bad
>
> drivers/mtd/mtdcore.c | 11 ++++++++++-
> 1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
> index 5ba9a741f5ac..096a3c94670f 100644
> --- a/drivers/mtd/mtdcore.c
> +++ b/drivers/mtd/mtdcore.c
> @@ -2337,10 +2337,11 @@ int mtd_block_isbad(struct mtd_info *mtd, loff_t ofs)
> EXPORT_SYMBOL_GPL(mtd_block_isbad);
>
> int mtd_block_markbad(struct mtd_info *mtd, loff_t ofs)
> {
> struct mtd_info *master = mtd_get_master(mtd);
> + loff_t moffs;
> int ret;
>
> if (!master->_block_markbad)
> return -EOPNOTSUPP;
> if (ofs < 0 || ofs >= mtd->size)
> @@ -2349,11 +2350,19 @@ int mtd_block_markbad(struct mtd_info *mtd, loff_t ofs)
> return -EROFS;
>
> if (mtd->flags & MTD_SLC_ON_MLC_EMULATION)
> ofs = (loff_t)mtd_div_by_eb(ofs, mtd) * master->erasesize;
>
> - ret = master->_block_markbad(master, mtd_get_master_ofs(mtd, ofs));
> + moffs = mtd_get_master_ofs(mtd, ofs);
> +
> + if (master->_block_isbad) {
> + ret = master->_block_isbad(master, moffs);
> + if (ret > 0)
> + return 0;
Hi, Miquèl.
Here, should we keep the same logic with the lower level(eg.
nand_block_markbad, onenand_block_markbad) when 'ret < 0' is returned by
master->_block_isbad. Many specific nand drivers(markbad) return the
negative code when 'isbad' fails.
> + }
> +
> + ret = master->_block_markbad(master, moffs);
> if (ret)
> return ret;
>
> while (mtd->parent) {
> mtd->ecc_stats.badblocks++;
>
next prev parent reply other threads:[~2025-09-02 11:41 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-02 9:27 Wang Zhaolong
2025-09-02 11:41 ` Zhihao Cheng [this message]
2025-09-02 13:16 ` Miquel Raynal
2025-09-03 2:11 ` Zhihao Cheng
2025-09-05 14:56 ` Miquel Raynal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=95bf5e07-7f03-efb0-da9b-cb50999c2524@huawei.com \
--to=chengzhihao1@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=miquel.raynal@bootlin.com \
--cc=richard@nod.at \
--cc=vigneshr@ti.com \
--cc=wangzhaolong@huaweicloud.com \
--cc=yangerkun@huawei.com \
--cc=yi.zhang@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®