diff options
| -rw-r--r-- | drivers/mtd/ubi/io.c | 76 |
1 files changed, 37 insertions, 39 deletions
diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c index c1628fc706c1..6843264840ad 100644 --- a/drivers/mtd/ubi/io.c +++ b/drivers/mtd/ubi/io.c | |||
| @@ -91,13 +91,13 @@ | |||
| 91 | #include <linux/slab.h> | 91 | #include <linux/slab.h> |
| 92 | #include "ubi.h" | 92 | #include "ubi.h" |
| 93 | 93 | ||
| 94 | static int paranoid_check_not_bad(const struct ubi_device *ubi, int pnum); | 94 | static int self_check_not_bad(const struct ubi_device *ubi, int pnum); |
| 95 | static int paranoid_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum); | 95 | static int self_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum); |
| 96 | static int paranoid_check_ec_hdr(const struct ubi_device *ubi, int pnum, | 96 | static int self_check_ec_hdr(const struct ubi_device *ubi, int pnum, |
| 97 | const struct ubi_ec_hdr *ec_hdr); | 97 | const struct ubi_ec_hdr *ec_hdr); |
| 98 | static int paranoid_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum); | 98 | static int self_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum); |
| 99 | static int paranoid_check_vid_hdr(const struct ubi_device *ubi, int pnum, | 99 | static int self_check_vid_hdr(const struct ubi_device *ubi, int pnum, |
| 100 | const struct ubi_vid_hdr *vid_hdr); | 100 | const struct ubi_vid_hdr *vid_hdr); |
| 101 | 101 | ||
| 102 | /** | 102 | /** |
| 103 | * ubi_io_read - read data from a physical eraseblock. | 103 | * ubi_io_read - read data from a physical eraseblock. |
| @@ -134,7 +134,7 @@ int ubi_io_read(const struct ubi_device *ubi, void *buf, int pnum, int offset, | |||
| 134 | ubi_assert(offset >= 0 && offset + len <= ubi->peb_size); | 134 | ubi_assert(offset >= 0 && offset + len <= ubi->peb_size); |
| 135 | ubi_assert(len > 0); | 135 | ubi_assert(len > 0); |
| 136 | 136 | ||
| 137 | err = paranoid_check_not_bad(ubi, pnum); | 137 | err = self_check_not_bad(ubi, pnum); |
| 138 | if (err) | 138 | if (err) |
| 139 | return err; | 139 | return err; |
| 140 | 140 | ||
| @@ -249,9 +249,7 @@ int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset, | |||
| 249 | return -EROFS; | 249 | return -EROFS; |
| 250 | } | 250 | } |
| 251 | 251 | ||
| 252 | /* The below has to be compiled out if paranoid checks are disabled */ | 252 | err = self_check_not_bad(ubi, pnum); |
| 253 | |||
| 254 | err = paranoid_check_not_bad(ubi, pnum); | ||
| 255 | if (err) | 253 | if (err) |
| 256 | return err; | 254 | return err; |
| 257 | 255 | ||
| @@ -265,10 +263,10 @@ int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset, | |||
| 265 | * We write to the data area of the physical eraseblock. Make | 263 | * We write to the data area of the physical eraseblock. Make |
| 266 | * sure it has valid EC and VID headers. | 264 | * sure it has valid EC and VID headers. |
| 267 | */ | 265 | */ |
| 268 | err = paranoid_check_peb_ec_hdr(ubi, pnum); | 266 | err = self_check_peb_ec_hdr(ubi, pnum); |
| 269 | if (err) | 267 | if (err) |
| 270 | return err; | 268 | return err; |
| 271 | err = paranoid_check_peb_vid_hdr(ubi, pnum); | 269 | err = self_check_peb_vid_hdr(ubi, pnum); |
| 272 | if (err) | 270 | if (err) |
| 273 | return err; | 271 | return err; |
| 274 | } | 272 | } |
| @@ -581,7 +579,7 @@ int ubi_io_sync_erase(struct ubi_device *ubi, int pnum, int torture) | |||
| 581 | 579 | ||
| 582 | ubi_assert(pnum >= 0 && pnum < ubi->peb_count); | 580 | ubi_assert(pnum >= 0 && pnum < ubi->peb_count); |
| 583 | 581 | ||
| 584 | err = paranoid_check_not_bad(ubi, pnum); | 582 | err = self_check_not_bad(ubi, pnum); |
| 585 | if (err != 0) | 583 | if (err != 0) |
| 586 | return err; | 584 | return err; |
| 587 | 585 | ||
| @@ -866,7 +864,7 @@ int ubi_io_write_ec_hdr(struct ubi_device *ubi, int pnum, | |||
| 866 | crc = crc32(UBI_CRC32_INIT, ec_hdr, UBI_EC_HDR_SIZE_CRC); | 864 | crc = crc32(UBI_CRC32_INIT, ec_hdr, UBI_EC_HDR_SIZE_CRC); |
| 867 | ec_hdr->hdr_crc = cpu_to_be32(crc); | 865 | ec_hdr->hdr_crc = cpu_to_be32(crc); |
| 868 | 866 | ||
| 869 | err = paranoid_check_ec_hdr(ubi, pnum, ec_hdr); | 867 | err = self_check_ec_hdr(ubi, pnum, ec_hdr); |
| 870 | if (err) | 868 | if (err) |
| 871 | return err; | 869 | return err; |
| 872 | 870 | ||
| @@ -1104,7 +1102,7 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum, | |||
| 1104 | dbg_io("write VID header to PEB %d", pnum); | 1102 | dbg_io("write VID header to PEB %d", pnum); |
| 1105 | ubi_assert(pnum >= 0 && pnum < ubi->peb_count); | 1103 | ubi_assert(pnum >= 0 && pnum < ubi->peb_count); |
| 1106 | 1104 | ||
| 1107 | err = paranoid_check_peb_ec_hdr(ubi, pnum); | 1105 | err = self_check_peb_ec_hdr(ubi, pnum); |
| 1108 | if (err) | 1106 | if (err) |
| 1109 | return err; | 1107 | return err; |
| 1110 | 1108 | ||
| @@ -1113,7 +1111,7 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum, | |||
| 1113 | crc = crc32(UBI_CRC32_INIT, vid_hdr, UBI_VID_HDR_SIZE_CRC); | 1111 | crc = crc32(UBI_CRC32_INIT, vid_hdr, UBI_VID_HDR_SIZE_CRC); |
| 1114 | vid_hdr->hdr_crc = cpu_to_be32(crc); | 1112 | vid_hdr->hdr_crc = cpu_to_be32(crc); |
| 1115 | 1113 | ||
| 1116 | err = paranoid_check_vid_hdr(ubi, pnum, vid_hdr); | 1114 | err = self_check_vid_hdr(ubi, pnum, vid_hdr); |
| 1117 | if (err) | 1115 | if (err) |
| 1118 | return err; | 1116 | return err; |
| 1119 | 1117 | ||
| @@ -1124,14 +1122,14 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum, | |||
| 1124 | } | 1122 | } |
| 1125 | 1123 | ||
| 1126 | /** | 1124 | /** |
| 1127 | * paranoid_check_not_bad - ensure that a physical eraseblock is not bad. | 1125 | * self_check_not_bad - ensure that a physical eraseblock is not bad. |
| 1128 | * @ubi: UBI device description object | 1126 | * @ubi: UBI device description object |
| 1129 | * @pnum: physical eraseblock number to check | 1127 | * @pnum: physical eraseblock number to check |
| 1130 | * | 1128 | * |
| 1131 | * This function returns zero if the physical eraseblock is good, %-EINVAL if | 1129 | * This function returns zero if the physical eraseblock is good, %-EINVAL if |
| 1132 | * it is bad and a negative error code if an error occurred. | 1130 | * it is bad and a negative error code if an error occurred. |
| 1133 | */ | 1131 | */ |
| 1134 | static int paranoid_check_not_bad(const struct ubi_device *ubi, int pnum) | 1132 | static int self_check_not_bad(const struct ubi_device *ubi, int pnum) |
| 1135 | { | 1133 | { |
| 1136 | int err; | 1134 | int err; |
| 1137 | 1135 | ||
| @@ -1142,13 +1140,13 @@ static int paranoid_check_not_bad(const struct ubi_device *ubi, int pnum) | |||
| 1142 | if (!err) | 1140 | if (!err) |
| 1143 | return err; | 1141 | return err; |
| 1144 | 1142 | ||
| 1145 | ubi_err("paranoid check failed for PEB %d", pnum); | 1143 | ubi_err("self-check failed for PEB %d", pnum); |
| 1146 | dump_stack(); | 1144 | dump_stack(); |
| 1147 | return err > 0 ? -EINVAL : err; | 1145 | return err > 0 ? -EINVAL : err; |
| 1148 | } | 1146 | } |
| 1149 | 1147 | ||
| 1150 | /** | 1148 | /** |
| 1151 | * paranoid_check_ec_hdr - check if an erase counter header is all right. | 1149 | * self_check_ec_hdr - check if an erase counter header is all right. |
| 1152 | * @ubi: UBI device description object | 1150 | * @ubi: UBI device description object |
| 1153 | * @pnum: physical eraseblock number the erase counter header belongs to | 1151 | * @pnum: physical eraseblock number the erase counter header belongs to |
| 1154 | * @ec_hdr: the erase counter header to check | 1152 | * @ec_hdr: the erase counter header to check |
| @@ -1156,8 +1154,8 @@ static int paranoid_check_not_bad(const struct ubi_device *ubi, int pnum) | |||
| 1156 | * This function returns zero if the erase counter header contains valid | 1154 | * This function returns zero if the erase counter header contains valid |
| 1157 | * values, and %-EINVAL if not. | 1155 | * values, and %-EINVAL if not. |
| 1158 | */ | 1156 | */ |
| 1159 | static int paranoid_check_ec_hdr(const struct ubi_device *ubi, int pnum, | 1157 | static int self_check_ec_hdr(const struct ubi_device *ubi, int pnum, |
| 1160 | const struct ubi_ec_hdr *ec_hdr) | 1158 | const struct ubi_ec_hdr *ec_hdr) |
| 1161 | { | 1159 | { |
| 1162 | int err; | 1160 | int err; |
| 1163 | uint32_t magic; | 1161 | uint32_t magic; |
| @@ -1174,7 +1172,7 @@ static int paranoid_check_ec_hdr(const struct ubi_device *ubi, int pnum, | |||
| 1174 | 1172 | ||
| 1175 | err = validate_ec_hdr(ubi, ec_hdr); | 1173 | err = validate_ec_hdr(ubi, ec_hdr); |
| 1176 | if (err) { | 1174 | if (err) { |
| 1177 | ubi_err("paranoid check failed for PEB %d", pnum); | 1175 | ubi_err("self-check failed for PEB %d", pnum); |
| 1178 | goto fail; | 1176 | goto fail; |
| 1179 | } | 1177 | } |
| 1180 | 1178 | ||
| @@ -1187,14 +1185,14 @@ fail: | |||
| 1187 | } | 1185 | } |
| 1188 | 1186 | ||
| 1189 | /** | 1187 | /** |
| 1190 | * paranoid_check_peb_ec_hdr - check erase counter header. | 1188 | * self_check_peb_ec_hdr - check erase counter header. |
| 1191 | * @ubi: UBI device description object | 1189 | * @ubi: UBI device description object |
| 1192 | * @pnum: the physical eraseblock number to check | 1190 | * @pnum: the physical eraseblock number to check |
| 1193 | * | 1191 | * |
| 1194 | * This function returns zero if the erase counter header is all right and and | 1192 | * This function returns zero if the erase counter header is all right and and |
| 1195 | * a negative error code if not or if an error occurred. | 1193 | * a negative error code if not or if an error occurred. |
| 1196 | */ | 1194 | */ |
| 1197 | static int paranoid_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum) | 1195 | static int self_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum) |
| 1198 | { | 1196 | { |
| 1199 | int err; | 1197 | int err; |
| 1200 | uint32_t crc, hdr_crc; | 1198 | uint32_t crc, hdr_crc; |
| @@ -1215,14 +1213,14 @@ static int paranoid_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum) | |||
| 1215 | hdr_crc = be32_to_cpu(ec_hdr->hdr_crc); | 1213 | hdr_crc = be32_to_cpu(ec_hdr->hdr_crc); |
| 1216 | if (hdr_crc != crc) { | 1214 | if (hdr_crc != crc) { |
| 1217 | ubi_err("bad CRC, calculated %#08x, read %#08x", crc, hdr_crc); | 1215 | ubi_err("bad CRC, calculated %#08x, read %#08x", crc, hdr_crc); |
| 1218 | ubi_err("paranoid check failed for PEB %d", pnum); | 1216 | ubi_err("self-check failed for PEB %d", pnum); |
| 1219 | ubi_dump_ec_hdr(ec_hdr); | 1217 | ubi_dump_ec_hdr(ec_hdr); |
| 1220 | dump_stack(); | 1218 | dump_stack(); |
| 1221 | err = -EINVAL; | 1219 | err = -EINVAL; |
| 1222 | goto exit; | 1220 | goto exit; |
| 1223 | } | 1221 | } |
| 1224 | 1222 | ||
| 1225 | err = paranoid_check_ec_hdr(ubi, pnum, ec_hdr); | 1223 | err = self_check_ec_hdr(ubi, pnum, ec_hdr); |
| 1226 | 1224 | ||
| 1227 | exit: | 1225 | exit: |
| 1228 | kfree(ec_hdr); | 1226 | kfree(ec_hdr); |
| @@ -1230,7 +1228,7 @@ exit: | |||
| 1230 | } | 1228 | } |
| 1231 | 1229 | ||
| 1232 | /** | 1230 | /** |
| 1233 | * paranoid_check_vid_hdr - check that a volume identifier header is all right. | 1231 | * self_check_vid_hdr - check that a volume identifier header is all right. |
| 1234 | * @ubi: UBI device description object | 1232 | * @ubi: UBI device description object |
| 1235 | * @pnum: physical eraseblock number the volume identifier header belongs to | 1233 | * @pnum: physical eraseblock number the volume identifier header belongs to |
| 1236 | * @vid_hdr: the volume identifier header to check | 1234 | * @vid_hdr: the volume identifier header to check |
| @@ -1238,8 +1236,8 @@ exit: | |||
| 1238 | * This function returns zero if the volume identifier header is all right, and | 1236 | * This function returns zero if the volume identifier header is all right, and |
| 1239 | * %-EINVAL if not. | 1237 | * %-EINVAL if not. |
| 1240 | */ | 1238 | */ |
| 1241 | static int paranoid_check_vid_hdr(const struct ubi_device *ubi, int pnum, | 1239 | static int self_check_vid_hdr(const struct ubi_device *ubi, int pnum, |
| 1242 | const struct ubi_vid_hdr *vid_hdr) | 1240 | const struct ubi_vid_hdr *vid_hdr) |
| 1243 | { | 1241 | { |
| 1244 | int err; | 1242 | int err; |
| 1245 | uint32_t magic; | 1243 | uint32_t magic; |
| @@ -1256,14 +1254,14 @@ static int paranoid_check_vid_hdr(const struct ubi_device *ubi, int pnum, | |||
| 1256 | 1254 | ||
| 1257 | err = validate_vid_hdr(ubi, vid_hdr); | 1255 | err = validate_vid_hdr(ubi, vid_hdr); |
| 1258 | if (err) { | 1256 | if (err) { |
| 1259 | ubi_err("paranoid check failed for PEB %d", pnum); | 1257 | ubi_err("self-check failed for PEB %d", pnum); |
| 1260 | goto fail; | 1258 | goto fail; |
| 1261 | } | 1259 | } |
| 1262 | 1260 | ||
| 1263 | return err; | 1261 | return err; |
| 1264 | 1262 | ||
| 1265 | fail: | 1263 | fail: |
| 1266 | ubi_err("paranoid check failed for PEB %d", pnum); | 1264 | ubi_err("self-check failed for PEB %d", pnum); |
| 1267 | ubi_dump_vid_hdr(vid_hdr); | 1265 | ubi_dump_vid_hdr(vid_hdr); |
| 1268 | dump_stack(); | 1266 | dump_stack(); |
| 1269 | return -EINVAL; | 1267 | return -EINVAL; |
| @@ -1271,14 +1269,14 @@ fail: | |||
| 1271 | } | 1269 | } |
| 1272 | 1270 | ||
| 1273 | /** | 1271 | /** |
| 1274 | * paranoid_check_peb_vid_hdr - check volume identifier header. | 1272 | * self_check_peb_vid_hdr - check volume identifier header. |
| 1275 | * @ubi: UBI device description object | 1273 | * @ubi: UBI device description object |
| 1276 | * @pnum: the physical eraseblock number to check | 1274 | * @pnum: the physical eraseblock number to check |
| 1277 | * | 1275 | * |
| 1278 | * This function returns zero if the volume identifier header is all right, | 1276 | * This function returns zero if the volume identifier header is all right, |
| 1279 | * and a negative error code if not or if an error occurred. | 1277 | * and a negative error code if not or if an error occurred. |
| 1280 | */ | 1278 | */ |
| 1281 | static int paranoid_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum) | 1279 | static int self_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum) |
| 1282 | { | 1280 | { |
| 1283 | int err; | 1281 | int err; |
| 1284 | uint32_t crc, hdr_crc; | 1282 | uint32_t crc, hdr_crc; |
| @@ -1303,14 +1301,14 @@ static int paranoid_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum) | |||
| 1303 | if (hdr_crc != crc) { | 1301 | if (hdr_crc != crc) { |
| 1304 | ubi_err("bad VID header CRC at PEB %d, calculated %#08x, " | 1302 | ubi_err("bad VID header CRC at PEB %d, calculated %#08x, " |
| 1305 | "read %#08x", pnum, crc, hdr_crc); | 1303 | "read %#08x", pnum, crc, hdr_crc); |
| 1306 | ubi_err("paranoid check failed for PEB %d", pnum); | 1304 | ubi_err("self-check failed for PEB %d", pnum); |
| 1307 | ubi_dump_vid_hdr(vid_hdr); | 1305 | ubi_dump_vid_hdr(vid_hdr); |
| 1308 | dump_stack(); | 1306 | dump_stack(); |
| 1309 | err = -EINVAL; | 1307 | err = -EINVAL; |
| 1310 | goto exit; | 1308 | goto exit; |
| 1311 | } | 1309 | } |
| 1312 | 1310 | ||
| 1313 | err = paranoid_check_vid_hdr(ubi, pnum, vid_hdr); | 1311 | err = self_check_vid_hdr(ubi, pnum, vid_hdr); |
| 1314 | 1312 | ||
| 1315 | exit: | 1313 | exit: |
| 1316 | ubi_free_vid_hdr(ubi, vid_hdr); | 1314 | ubi_free_vid_hdr(ubi, vid_hdr); |
| @@ -1358,7 +1356,7 @@ int ubi_dbg_check_write(struct ubi_device *ubi, const void *buf, int pnum, | |||
| 1358 | if (c == c1) | 1356 | if (c == c1) |
| 1359 | continue; | 1357 | continue; |
| 1360 | 1358 | ||
| 1361 | ubi_err("paranoid check failed for PEB %d:%d, len %d", | 1359 | ubi_err("self-check failed for PEB %d:%d, len %d", |
| 1362 | pnum, offset, len); | 1360 | pnum, offset, len); |
| 1363 | ubi_msg("data differ at position %d", i); | 1361 | ubi_msg("data differ at position %d", i); |
| 1364 | dump_len = max_t(int, 128, len - i); | 1362 | dump_len = max_t(int, 128, len - i); |
| @@ -1428,7 +1426,7 @@ int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len) | |||
| 1428 | return 0; | 1426 | return 0; |
| 1429 | 1427 | ||
| 1430 | fail: | 1428 | fail: |
| 1431 | ubi_err("paranoid check failed for PEB %d", pnum); | 1429 | ubi_err("self-check failed for PEB %d", pnum); |
| 1432 | ubi_msg("hex dump of the %d-%d region", offset, offset + len); | 1430 | ubi_msg("hex dump of the %d-%d region", offset, offset + len); |
| 1433 | print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, buf, len, 1); | 1431 | print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, buf, len, 1); |
| 1434 | err = -EINVAL; | 1432 | err = -EINVAL; |
