Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mtd: afs: refactor v1 partition parsing

Return immediately if we are not finding a valid v1 partition
in afs_read_footer_v1(), invert scanning logic so we continue
to read image information on v1 if we found a footer. This is
needed for the logic we introduce to parse v2 footers.

Cc: Ryan Harkin <ryan.harkin@linaro.org>
Cc: Liviu Dudau <liviu.dudau@arm.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>

authored by

Linus Walleij and committed by
Brian Norris
d2fd05bb 9498440f

+16 -19
+16 -19
drivers/mtd/afs.c
··· 87 87 return ret; 88 88 } 89 89 90 - ret = 1; 91 - 92 90 /* 93 91 * Does it contain the magic number? 94 92 */ 95 93 if (fs.signature != AFSV1_FOOTER_MAGIC) 96 - ret = 0; 94 + return 0; 97 95 98 96 /* 99 97 * Check the checksum. 100 98 */ 101 99 if (word_sum(&fs, sizeof(fs) / sizeof(u32)) != 0xffffffff) 102 - ret = 0; 100 + return 0; 103 101 104 102 /* 105 103 * Don't touch the SIB. 106 104 */ 107 105 if (fs.type == 2) 108 - ret = 0; 106 + return 0; 109 107 110 108 *iis_start = fs.image_info_base & mask; 111 109 *img_start = fs.image_start & mask; ··· 113 115 * be located after the footer structure. 114 116 */ 115 117 if (*iis_start >= ptr) 116 - ret = 0; 118 + return 0; 117 119 118 120 /* 119 121 * Check the start of this image. The image 120 122 * data can not be located after this block. 121 123 */ 122 124 if (*img_start > off) 123 - ret = 0; 125 + return 0; 124 126 125 - return ret; 127 + return 1; 126 128 } 127 129 128 130 static int ··· 188 190 ret = afs_read_footer_v1(mtd, &img_ptr, &iis_ptr, off, mask); 189 191 if (ret < 0) 190 192 break; 191 - if (ret == 0) 192 - continue; 193 + if (ret) { 194 + ret = afs_read_iis_v1(mtd, &iis, iis_ptr); 195 + if (ret < 0) 196 + break; 197 + if (ret == 0) 198 + continue; 193 199 194 - ret = afs_read_iis_v1(mtd, &iis, iis_ptr); 195 - if (ret < 0) 196 - break; 197 - if (ret == 0) 198 - continue; 199 - 200 - sz += sizeof(struct mtd_partition); 201 - sz += strlen(iis.name) + 1; 202 - idx += 1; 200 + sz += sizeof(struct mtd_partition); 201 + sz += strlen(iis.name) + 1; 202 + idx += 1; 203 + } 203 204 } 204 205 205 206 if (!sz)