Browse Source

kernel: mtdsplit: rework and make use of -ENOENT error

Rework each affected mtdsplit driver to make use of -ENOENT error
instead of -ENODEV to handle new kernel that checks error from parser on
subpartitions.

The only acceptable error is -ENOENT that skip the parser. This follow
pattern used upstream and also by an mtdsplit parser, mtdsplit_bcm_wfi,
and also by a workaround currently implemented for mtdsplit_mstc_boot.

Signed-off-by: Christian Marangi <[email protected]>
Christian Marangi 3 months ago
parent
commit
e5ad92c588

+ 2 - 2
target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit.c

@@ -53,7 +53,7 @@ int mtd_get_squashfs_len(struct mtd_info *master,
 	retlen = le64_to_cpu(sb.bytes_used);
 	if (retlen <= 0) {
 		pr_alert("squashfs is empty in \"%s\"\n", master->name);
-		return -ENODEV;
+		return -ENOENT;
 	}
 
 	if (offset + retlen > master->size) {
@@ -124,7 +124,7 @@ int mtd_find_rootfs_from(struct mtd_info *mtd,
 		return 0;
 	}
 
-	return -ENODEV;
+	return -ENOENT;
 }
 EXPORT_SYMBOL_GPL(mtd_find_rootfs_from);
 

+ 2 - 2
target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit.h

@@ -45,7 +45,7 @@ static inline int mtd_get_squashfs_len(struct mtd_info *master,
 				       size_t offset,
 				       size_t *squashfs_len)
 {
-	return -ENODEV;
+	return -ENOENT;
 }
 
 static inline int mtd_check_rootfs_magic(struct mtd_info *mtd, size_t offset,
@@ -60,7 +60,7 @@ static inline int mtd_find_rootfs_from(struct mtd_info *mtd,
 				       size_t *ret_offset,
 				       enum mtdsplit_part_type *type)
 {
-	return -ENODEV;
+	return -ENOENT;
 }
 #endif /* CONFIG_MTD_SPLIT */
 

+ 1 - 1
target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_elf.c

@@ -241,7 +241,7 @@ static int mtdsplit_parse_elf(struct mtd_info *mtd,
 
 	if (rootfs_offset == mtd->size) {
 		pr_debug("no rootfs found in \"%s\"\n", mtd->name);
-		return -ENODEV;
+		return -ENOENT;
 	}
 
 	parts = kzalloc(ELF_NR_PARTS * sizeof(*parts), GFP_KERNEL);

+ 3 - 3
target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_fit.c

@@ -210,7 +210,7 @@ mtdsplit_fit_parse(struct mtd_info *mtd,
 
 	of_property_read_string(np, "openwrt,cmdline-match", &cmdline_match);
 	if (cmdline_match && !strstr(saved_command_line, cmdline_match))
-		return -ENODEV;
+		return -ENOENT;
 
 	of_property_read_u32(np, "openwrt,fit-offset", &offset_start);
 
@@ -247,7 +247,7 @@ mtdsplit_fit_parse(struct mtd_info *mtd,
 	if (fit_size == 0) {
 		pr_err("FIT image in \"%s\" at offset %llx has null size\n",
 		       mtd->name, (unsigned long long) fit_offset);
-		return -ENODEV;
+		return -ENOENT;
 	}
 
 	/*
@@ -304,7 +304,7 @@ mtdsplit_fit_parse(struct mtd_info *mtd,
 		if (images_noffset < 0) {
 			pr_err("Can't find images parent node '%s' (%s)\n",
 			FIT_IMAGES_PATH, fdt_strerror(images_noffset));
-			return -ENODEV;
+			return -ENOENT;
 		}
 
 		for (ndepth = 0,

+ 2 - 2
target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_jimage.c

@@ -147,7 +147,7 @@ static int __mtdsplit_parse_jimage(struct mtd_info *master,
 
 	if (jimage_size == 0) {
 		pr_debug("no jImage found in \"%s\"\n", master->name);
-		ret = -ENODEV;
+		ret = -ENOENT;
 		goto err_free_buf;
 	}
 
@@ -186,7 +186,7 @@ static int __mtdsplit_parse_jimage(struct mtd_info *master,
 
 	if (rootfs_size == 0) {
 		pr_debug("no rootfs found in \"%s\"\n", master->name);
-		ret = -ENODEV;
+		ret = -ENOENT;
 		goto err_free_buf;
 	}
 

+ 1 - 5
target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_mstc_boot.c

@@ -247,11 +247,7 @@ mtdsplit_mstcboot_parse(struct mtd_info *mtd,
 		ret = mstcboot_parse_image_parts(mtd, pparts);
 
 exit:
-	/*
-	 * return 0 when ret=-ENODEV, to prevent deletion of
-	 * parent mtd partitions on Linux 6.7 and later
-	 */
-	return ret == -ENODEV ? 0 : ret;
+	return ret;
 }
 
 static const struct of_device_id mtdsplit_mstcboot_of_match_table[] = {

+ 2 - 2
target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_trx.c

@@ -100,7 +100,7 @@ mtdsplit_parse_trx(struct mtd_info *master,
 
 	if (trx_size == 0) {
 		pr_debug("no trx header found in \"%s\"\n", master->name);
-		ret = -ENODEV;
+		ret = -ENOENT;
 		goto err;
 	}
 
@@ -111,7 +111,7 @@ mtdsplit_parse_trx(struct mtd_info *master,
 
 	if (rootfs_size == 0) {
 		pr_debug("no rootfs found in \"%s\"\n", master->name);
-		ret = -ENODEV;
+		ret = -ENOENT;
 		goto err;
 	}
 

+ 1 - 1
target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_uimage.c

@@ -226,7 +226,7 @@ static int __mtdsplit_parse_uimage(struct mtd_info *master,
 
 	if (rootfs_size == 0) {
 		pr_debug("no rootfs found in \"%s\"\n", master->name);
-		ret = -ENODEV;
+		ret = -ENOENT;
 		goto err_free_buf;
 	}