kernel: mtdsplit_minor: return 0 if not fatal

Introduced with Linux 6.7, in commit:
5c2f7727d437 ("mtd: mtdpart: check for subpartitions parsing result"),
when a parser returns an error, this will be passed up, and
consequently, all parent mtd partitions get torn down.

Adjust the MiNOR mtdsplit driver to only return an error if there is a
critical problem in reading from the mtd device or allocating memory.
Otherwise return 0 to indicate that no partitions were found.
Also add logging to indicate what went wrong.

This mtdsplit parser makes a very limited check of the first YAFFS
header. For example, this will not match expectations when initially booting
an initramfs image with OEM on MTD.

Signed-off-by: John Thomson <git@johnthomson.fastmail.com.au>
Acked-by: Thibaut VARENE <hacks@slashdirt.org>
Link: https://github.com/openwrt/openwrt/pull/16780
Signed-off-by: Robert Marko <robimarko@gmail.com>
This commit is contained in:
John Thomson 2024-10-16 07:13:25 +10:00 committed by Robert Marko
parent a6a44f94bf
commit ade045084b
1 changed files with 26 additions and 12 deletions

View File

@ -61,29 +61,43 @@ static int mtdsplit_parse_minor(struct mtd_info *master,
hdr_len = sizeof(hdr);
err = mtd_read(master, 0, hdr_len, &retlen, (void *) &hdr);
if (err)
if (err) {
pr_err("MiNOR mtd_read error: %d\n", err);
return err;
}
if (retlen != hdr_len)
if (retlen != hdr_len) {
pr_err("MiNOR mtd_read too short\n");
return -EIO;
}
/* match header */
if (hdr.yaffs_type != YAFFS_OBJECT_TYPE_FILE)
return -EINVAL;
if (hdr.yaffs_type != YAFFS_OBJECT_TYPE_FILE) {
pr_info("MiNOR YAFFS first type not matched\n");
return 0;
}
if (hdr.yaffs_obj_id != YAFFS_OBJECTID_ROOT)
return -EINVAL;
if (hdr.yaffs_obj_id != YAFFS_OBJECTID_ROOT) {
pr_info("MiNOR YAFFS first objectid not matched\n");
return 0;
}
if (hdr.yaffs_sum_unused != YAFFS_SUM_UNUSED)
return -EINVAL;
if (hdr.yaffs_sum_unused != YAFFS_SUM_UNUSED) {
pr_info("MiNOR YAFFS first sum not matched\n");
return 0;
}
if (memcmp(hdr.yaffs_name, YAFFS_NAME, sizeof(YAFFS_NAME)))
return -EINVAL;
if (memcmp(hdr.yaffs_name, YAFFS_NAME, sizeof(YAFFS_NAME))) {
pr_info("MiNOR YAFFS first name not matched\n");
return 0;
}
err = mtd_find_rootfs_from(master, master->erasesize, master->size,
&rootfs_offset, NULL);
if (err)
return err;
if (err) {
pr_info("MiNOR mtd_find_rootfs_from error: %d\n", err);
return 0;
}
parts = kzalloc(MINOR_NR_PARTS * sizeof(*parts), GFP_KERNEL);
if (!parts)