Attention is currently required from: Nico Huber, Edward O'Callaghan, Anastasia Klimchuk, Peter Marheine. Angel Pons has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/56413 )
Change subject: tests: Mock file i/o for linux_mtd and linux_spi tests ......................................................................
Patch Set 5:
(3 comments)
File tests/init_shutdown.c:
https://review.coreboot.org/c/flashrom/+/56413/comment/0dbb5e43_d3c4e469 PS4, Line 214: int num_bytes = 0; Hmmm, I'd like to get rid of `num_bytes`:
size_t linux_mtd_fread(void *state, void *buf, size_t size, size_t len, FILE *fp) { struct linux_mtd_fread_mock_entry { const char *path; const char *data; }; const struct linux_mtd_fread_mock_entry fread_mock_map[] = { { "/sys/class/mtd/mtd0//type", "nor" }, { "/sys/class/mtd/mtd0//name", "Device" }, { "/sys/class/mtd/mtd0//flags", "" }, { "/sys/class/mtd/mtd0//size", "1024" }, { "/sys/class/mtd/mtd0//erasesize", "512" }, { "/sys/class/mtd/mtd0//numeraseregions", "0" }, };
struct linux_mtd_io_state *io_state = state; const char *data = NULL; unsigned int i;
if (!io_state->fopen_path) return 0;
for (i = 0; i < ARRAY_SIZE(fread_mock_map); i++) { const struct linux_mtd_fread_mock_entry *entry = fread_mock_map[i]; if (!strcmp(io_state->fopen_path, entry->path)) { strcpy(buf, entry->data); return strlen(entry->data); } } return 0; }
https://review.coreboot.org/c/flashrom/+/56413/comment/22613ca1_811fe928 PS4, Line 221: memcpy(buf, "nor", num_bytes); Use strcpy instead?
https://review.coreboot.org/c/flashrom/+/56413/comment/26fc4e9b_ce63184e PS4, Line 275: memcpy(buf, "1048576", len);
just, `return memcpy(buf, "1048576", len);` memcpy returns the ptr to dest (buf in this case).
Hmmm, why use `len` here? If its value is larger than the length of "1048576", undefined behavior would happen.