linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC] mtd: ubi: skip programming unused bits in ubi headers
@ 2025-08-12  5:19 Cheng Ming Lin
  2025-08-12  6:57 ` Richard Weinberger
  0 siblings, 1 reply; 9+ messages in thread
From: Cheng Ming Lin @ 2025-08-12  5:19 UTC (permalink / raw)
  To: richard, chengzhihao1, miquel.raynal, vigneshr, linux-mtd,
	linux-kernel
  Cc: alvinzhou, leoyu, Cheng Ming Lin

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 typically 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.

Signed-off-by: Cheng Ming Lin <chengminglin@mxic.com.tw>
---
 drivers/mtd/ubi/io.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c
index a4999bce435f..ccab4691b338 100644
--- a/drivers/mtd/ubi/io.c
+++ b/drivers/mtd/ubi/io.c
@@ -868,6 +868,7 @@ 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 +1151,7 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum,
 		return -EROFS;
 	}
 
+	memset((char *)p + ubi->vid_hdr_shift, 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.25.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-09-12  8:22 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-12  5:19 [RFC] mtd: ubi: skip programming unused bits in ubi headers Cheng Ming Lin
2025-08-12  6:57 ` Richard Weinberger
2025-08-14 10:11   ` Cheng Ming Lin
2025-08-14 11:30     ` Richard Weinberger
2025-09-05  3:21       ` Cheng Ming Lin
2025-09-12  7:57         ` Richard Weinberger
2025-09-12  7:57           ` Cheng Ming Lin
2025-09-12  8:04             ` Richard Weinberger
2025-09-12  8:19               ` Cheng Ming Lin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).