summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2015-10-15 09:08:47 -0400
committerBrian Norris <computersforpeace@gmail.com>2015-11-10 20:56:06 -0500
commitd2fd05bb6769d53ab98a11b080b3fb889276049d (patch)
treed2b8dbf4520e444d2c37d6d174250b060085c75f
parent9498440fff21649cabe529f1d9d4e3bc668fc125 (diff)
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>
-rw-r--r--drivers/mtd/afs.c37
1 files changed, 17 insertions, 20 deletions
diff --git a/drivers/mtd/afs.c b/drivers/mtd/afs.c
index d09280ae12bd..a1eea50ce180 100644
--- a/drivers/mtd/afs.c
+++ b/drivers/mtd/afs.c
@@ -87,25 +87,23 @@ afs_read_footer_v1(struct mtd_info *mtd, u_int *img_start, u_int *iis_start,
87 return ret; 87 return ret;
88 } 88 }
89 89
90 ret = 1;
91
92 /* 90 /*
93 * Does it contain the magic number? 91 * Does it contain the magic number?
94 */ 92 */
95 if (fs.signature != AFSV1_FOOTER_MAGIC) 93 if (fs.signature != AFSV1_FOOTER_MAGIC)
96 ret = 0; 94 return 0;
97 95
98 /* 96 /*
99 * Check the checksum. 97 * Check the checksum.
100 */ 98 */
101 if (word_sum(&fs, sizeof(fs) / sizeof(u32)) != 0xffffffff) 99 if (word_sum(&fs, sizeof(fs) / sizeof(u32)) != 0xffffffff)
102 ret = 0; 100 return 0;
103 101
104 /* 102 /*
105 * Don't touch the SIB. 103 * Don't touch the SIB.
106 */ 104 */
107 if (fs.type == 2) 105 if (fs.type == 2)
108 ret = 0; 106 return 0;
109 107
110 *iis_start = fs.image_info_base & mask; 108 *iis_start = fs.image_info_base & mask;
111 *img_start = fs.image_start & mask; 109 *img_start = fs.image_start & mask;
@@ -115,16 +113,16 @@ afs_read_footer_v1(struct mtd_info *mtd, u_int *img_start, u_int *iis_start,
115 * be located after the footer structure. 113 * be located after the footer structure.
116 */ 114 */
117 if (*iis_start >= ptr) 115 if (*iis_start >= ptr)
118 ret = 0; 116 return 0;
119 117
120 /* 118 /*
121 * Check the start of this image. The image 119 * Check the start of this image. The image
122 * data can not be located after this block. 120 * data can not be located after this block.
123 */ 121 */
124 if (*img_start > off) 122 if (*img_start > off)
125 ret = 0; 123 return 0;
126 124
127 return ret; 125 return 1;
128} 126}
129 127
130static int 128static int
@@ -190,18 +188,17 @@ static int parse_afs_partitions(struct mtd_info *mtd,
190 ret = afs_read_footer_v1(mtd, &img_ptr, &iis_ptr, off, mask); 188 ret = afs_read_footer_v1(mtd, &img_ptr, &iis_ptr, off, mask);
191 if (ret < 0) 189 if (ret < 0)
192 break; 190 break;
193 if (ret == 0) 191 if (ret) {
194 continue; 192 ret = afs_read_iis_v1(mtd, &iis, iis_ptr);
195 193 if (ret < 0)
196 ret = afs_read_iis_v1(mtd, &iis, iis_ptr); 194 break;
197 if (ret < 0) 195 if (ret == 0)
198 break; 196 continue;
199 if (ret == 0) 197
200 continue; 198 sz += sizeof(struct mtd_partition);
201 199 sz += strlen(iis.name) + 1;
202 sz += sizeof(struct mtd_partition); 200 idx += 1;
203 sz += strlen(iis.name) + 1; 201 }
204 idx += 1;
205 } 202 }
206 203
207 if (!sz) 204 if (!sz)