1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-17 05:12:57 +01:00
19252: mtd: add fast path to mtd_write_page() r=benpicco a=benpicco




Co-authored-by: Benjamin Valentin <benjamin.valentin@ml-pa.com>
This commit is contained in:
bors[bot] 2023-02-08 00:52:25 +00:00 committed by GitHub
commit f22ce155bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -183,6 +183,12 @@ static size_t _write_sector(mtd_dev_t *mtd, const void *data, uint32_t sector,
len = sector_size - offset;
}
/* fast path: skip reading the sector if we overwrite it completely */
if (offset == 0 && len == sector_size) {
work = (void *)data;
goto write;
}
/* copy sector to RAM */
res = mtd_read_page(mtd, work, sector_page, 0, sector_size);
if (res < 0) {
@ -198,6 +204,7 @@ static size_t _write_sector(mtd_dev_t *mtd, const void *data, uint32_t sector,
/* modify sector in RAM */
memcpy(work + offset, data, len);
write:
/* write back modified sector copy */
res = mtd_write_page_raw(mtd, work, sector_page, 0, sector_size);
if (res < 0) {