From: Dominique Martinet <dominique.martinet@atmark-techno.com>
To: stable@vger.kernel.org
Cc: Richard Weinberger <richard@nod.at>,
Zhihao Cheng <chengzhihao1@huawei.com>,
Miquel Raynal <miquel.raynal@bootlin.com>,
linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org,
Dominique Martinet <dominique.martinet@atmark-techno.com>,
Cheng Ming Lin <chengminglin@mxic.com.tw>
Subject: [PATCH v6.12.y 1/2] mtd: ubi: skip programming unused bits in ubi headers
Date: Tue, 18 Aug 2026 02:09:34 +0000 [thread overview]
Message-ID: <20260818-ubi-backports-v1-1-324d6816d2ae@atmark-techno.com> (raw)
In-Reply-To: <20260818-ubi-backports-v1-0-324d6816d2ae@atmark-techno.com>
From: Cheng Ming Lin <chengminglin@mxic.com.tw>
This patch prevents unnecessary programming of bits in ec_hdr and
vid_hdr that are not used or read during normal UBI operation. These
unused bits are typcially already set to 1 in erased flash and do not
need to be explicitly programmed to 0 if they are not used.
Programming such unused areas offers no functional benefit and may
result in unnecessary flash wear, reducing the overall lifetime of the
device. By skipping these writes, we preserve the flash state as much as
possible and minimize wear caused by redundant operations.
This change ensures that only necessary fields are written when preparing
UBI headers, improving flash efficiency without affecting functionality.
Additionally, the Kioxia TC58NVG1S3HTA00 datasheet (page 63) also notes
that continuous program/erase cycling with a high percentage of '0' bits
in the data pattern can accelerate block endurance degradation.
This further supports avoiding large 0x00 patterns.
Link: https://europe.kioxia.com/content/dam/kioxia/newidr/productinfo/datasheet/201910/DST_TC58NVG1S3HTA00-TDE_EN_31442.pdf
Signed-off-by: Cheng Ming Lin <chengminglin@mxic.com.tw>
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
(cherry picked from commit 77530d1a78ca5c274e37d6494a965223672630b2)
Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com>
---
drivers/mtd/ubi/io.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c
index a4999bce435f..915eb64cb001 100644
--- a/drivers/mtd/ubi/io.c
+++ b/drivers/mtd/ubi/io.c
@@ -868,6 +868,8 @@ int ubi_io_write_ec_hdr(struct ubi_device *ubi, int pnum,
return -EROFS;
}
+ memset((char *)ec_hdr + UBI_EC_HDR_SIZE, 0xFF, ubi->ec_hdr_alsize - UBI_EC_HDR_SIZE);
+
err = ubi_io_write(ubi, ec_hdr, pnum, 0, ubi->ec_hdr_alsize);
return err;
}
@@ -1150,6 +1152,14 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum,
return -EROFS;
}
+ if (ubi->vid_hdr_shift) {
+ memset((char *)p, 0xFF, ubi->vid_hdr_shift);
+ memset((char *)p + ubi->vid_hdr_shift + UBI_VID_HDR_SIZE, 0xFF,
+ ubi->vid_hdr_alsize - (ubi->vid_hdr_shift + UBI_VID_HDR_SIZE));
+ } else {
+ memset((char *)p + UBI_VID_HDR_SIZE, 0xFF, ubi->vid_hdr_alsize - UBI_VID_HDR_SIZE);
+ }
+
err = ubi_io_write(ubi, p, pnum, ubi->vid_hdr_aloffset,
ubi->vid_hdr_alsize);
return err;
--
2.55.0.dirty
next prev parent reply other threads:[~2026-08-18 2:10 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-18 2:09 [PATCH 0/2] Backport fixes for UBI Dominique Martinet
2026-08-18 2:09 ` Dominique Martinet [this message]
2026-08-18 4:46 ` [PATCH v6.12.y 1/2] mtd: ubi: skip programming unused bits in ubi headers Zhihao Cheng
2026-08-18 2:09 ` [PATCH v6.12.y 2/2] ubi: fastmap: fix ubi->fm memory leak Dominique Martinet
2026-08-18 4:47 ` Zhihao Cheng
2026-08-19 3:32 ` [PATCH 0/2] Backport fixes for UBI Sasha Levin
2026-08-19 10:48 ` Richard Weinberger
2026-08-20 0:57 ` Dominique Martinet
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=20260818-ubi-backports-v1-1-324d6816d2ae@atmark-techno.com \
--to=dominique.martinet@atmark-techno.com \
--cc=chengminglin@mxic.com.tw \
--cc=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=stable@vger.kernel.org \
/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®