[PATCH 1/1] mtd: ubi: skip programming unused bits in ubi headers
Cheng Ming Lin
linchengming884 at gmail.com
Fri Nov 7 00:28:23 PST 2025
Hi Miquel,
Miquel Raynal <miquel.raynal at bootlin.com> 於 2025年11月7日 週五 下午4:23寫道:
>
> Hello,
>
> >> > + if (ubi->vid_hdr_shift)
> >> > + memset((char *)p, 0xFF, ubi->vid_hdr_alsize - UBI_VID_HDR_SIZE);
> >> > + else
> >> > + memset((char *)p + UBI_VID_HDR_SIZE, 0xFF, ubi->vid_hdr_alsize - UBI_VID_HDR_SIZE);
> >>
> >> Here I am reaching the limits of my UBI knowledge, so I would prefer
> >> Richard to (in)validate what I am saying, but AFAIU, the VID header can
> >> be literally anywhere in the page, not just at the start or end of a
> >> subpage, so in the vid_hdr_shift I would expect some extra maths to
> >> happen, no?
> >
> > I understand your point now. If the VID header is not guaranteed to be
> > at the start or end of a subpage, then yes, my current logic needs to be
> > reworked to cover that case.
>
> I don't know if this is easy to do, but maybe you can memset the whole
> buffer before filling it. That would avoid the need to know where the
> VID header will be.
At this point I have two possible directions.
The first approach is to keep doing it in two parts, like:
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));
The second approach would be to modify ubi_init_vid_buf() in ubi/ubi.h,
so that its memset fills the buffer with 0xFF from the beginning.
The second one is cleaner, but ubi_init_vid_buf() is not always called
before ubi_io_write_vid_hdr(), so I am checking right now whether this
would affect other paths.
>
> Thanks,
> Miquèl
Thanks,
Cheng Ming Lin
More information about the linux-mtd
mailing list