[PATCH v2 1/1] mtd: ubi: skip programming unused bits in ubi headers
Zhihao Cheng
chengzhihao1 at huawei.com
Fri Nov 14 01:24:56 PST 2025
在 2025/11/14 16:47, Cheng Ming Lin 写道:
> Hi Miquel,
>
> Miquel Raynal <miquel.raynal at bootlin.com> 於 2025年11月14日 週五 下午4:31寫道:
>>
>> Hi Cheng Ming,
>>
>>> @@ -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);
>>> + }
>>> +
>>
>> Is it not possible to memset() the buffer before writing the VID header?
>> I haven't found quickly a good place to do that, so in any case,
>
> If we want to memset() the buffer before writing the VID header, one
> possible option is to modify ubi_init_vid_buf() in
> drivers/mtd/ubi/ubi.h.
The ubi_init_vid_buf() is called in many reading processes, the solution
improves flash wearing for write situation, so I think doing memset in
ubi_io_write_vid_hdr() is fine.
>
> Specifically, we could replace the existing
> memset(buf, 0, ubi->vid_hdr_alsize) inside the "if (buf)" block with
> memset(buf, 0xff, ubi->vid_hdr_alsize). After the VID header
> position has been determined, we can then apply a second memset() on
> vidh->hdr to zero-initialize UBI_VID_HDR_SIZE. This approach should
> provide the same effect while ensuring that all fields inside the VID
> header are properly initialized to zero.
>
> Does this make sense to you? If this direction is preferable, I can
> prepare a v3 reflecting this change, and I will also run ubi-tests to
> verify the behavior. Thanks!
>
>>
>> Reviewed-by: Miquel Raynal <miquel.raynal at bootlin.com>
>>
>> Thanks,
>> Miquèl
>
> Thanks,
> Cheng Ming Lin
> .
>
More information about the linux-mtd
mailing list