diff options
author | Artem Bityutskiy <Artem.Bityutskiy@nokia.com> | 2010-01-20 03:28:58 -0500 |
---|---|---|
committer | Artem Bityutskiy <Artem.Bityutskiy@nokia.com> | 2010-02-01 08:16:37 -0500 |
commit | adbf05e3ec6ea380ba145b6fa89d9125ed76eb98 (patch) | |
tree | 9da867755d3b915ec1a759658397aaa31bc68263 /drivers | |
parent | 0bf1c4399afee6a2031b0ee943a4c016e53f727c (diff) |
UBI: simplify debugging return codes
UBI debugging functions were a little bit over-engineered and
returned more error codes than needed, and the callers had to
do useless checks. Simplify the return codes.
Impact: only debugging code is affected, which means that for
non-developers this is a no-op patch.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/mtd/ubi/io.c | 50 | ||||
-rw-r--r-- | drivers/mtd/ubi/scan.c | 11 | ||||
-rw-r--r-- | drivers/mtd/ubi/wl.c | 17 |
3 files changed, 37 insertions, 41 deletions
diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c index 8aa51e7a6a7d..a2501299a67c 100644 --- a/drivers/mtd/ubi/io.c +++ b/drivers/mtd/ubi/io.c | |||
@@ -143,7 +143,7 @@ int ubi_io_read(const struct ubi_device *ubi, void *buf, int pnum, int offset, | |||
143 | 143 | ||
144 | err = paranoid_check_not_bad(ubi, pnum); | 144 | err = paranoid_check_not_bad(ubi, pnum); |
145 | if (err) | 145 | if (err) |
146 | return err > 0 ? -EINVAL : err; | 146 | return err; |
147 | 147 | ||
148 | addr = (loff_t)pnum * ubi->peb_size + offset; | 148 | addr = (loff_t)pnum * ubi->peb_size + offset; |
149 | retry: | 149 | retry: |
@@ -236,12 +236,12 @@ int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset, | |||
236 | 236 | ||
237 | err = paranoid_check_not_bad(ubi, pnum); | 237 | err = paranoid_check_not_bad(ubi, pnum); |
238 | if (err) | 238 | if (err) |
239 | return err > 0 ? -EINVAL : err; | 239 | return err; |
240 | 240 | ||
241 | /* The area we are writing to has to contain all 0xFF bytes */ | 241 | /* The area we are writing to has to contain all 0xFF bytes */ |
242 | err = ubi_dbg_check_all_ff(ubi, pnum, offset, len); | 242 | err = ubi_dbg_check_all_ff(ubi, pnum, offset, len); |
243 | if (err) | 243 | if (err) |
244 | return err > 0 ? -EINVAL : err; | 244 | return err; |
245 | 245 | ||
246 | if (offset >= ubi->leb_start) { | 246 | if (offset >= ubi->leb_start) { |
247 | /* | 247 | /* |
@@ -250,10 +250,10 @@ int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset, | |||
250 | */ | 250 | */ |
251 | err = paranoid_check_peb_ec_hdr(ubi, pnum); | 251 | err = paranoid_check_peb_ec_hdr(ubi, pnum); |
252 | if (err) | 252 | if (err) |
253 | return err > 0 ? -EINVAL : err; | 253 | return err; |
254 | err = paranoid_check_peb_vid_hdr(ubi, pnum); | 254 | err = paranoid_check_peb_vid_hdr(ubi, pnum); |
255 | if (err) | 255 | if (err) |
256 | return err > 0 ? -EINVAL : err; | 256 | return err; |
257 | } | 257 | } |
258 | 258 | ||
259 | if (ubi_dbg_is_write_failure()) { | 259 | if (ubi_dbg_is_write_failure()) { |
@@ -348,7 +348,7 @@ retry: | |||
348 | 348 | ||
349 | err = ubi_dbg_check_all_ff(ubi, pnum, 0, ubi->peb_size); | 349 | err = ubi_dbg_check_all_ff(ubi, pnum, 0, ubi->peb_size); |
350 | if (err) | 350 | if (err) |
351 | return err > 0 ? -EINVAL : err; | 351 | return err; |
352 | 352 | ||
353 | if (ubi_dbg_is_erase_failure() && !err) { | 353 | if (ubi_dbg_is_erase_failure() && !err) { |
354 | dbg_err("cannot erase PEB %d (emulated)", pnum); | 354 | dbg_err("cannot erase PEB %d (emulated)", pnum); |
@@ -542,7 +542,7 @@ int ubi_io_sync_erase(struct ubi_device *ubi, int pnum, int torture) | |||
542 | 542 | ||
543 | err = paranoid_check_not_bad(ubi, pnum); | 543 | err = paranoid_check_not_bad(ubi, pnum); |
544 | if (err != 0) | 544 | if (err != 0) |
545 | return err > 0 ? -EINVAL : err; | 545 | return err; |
546 | 546 | ||
547 | if (ubi->ro_mode) { | 547 | if (ubi->ro_mode) { |
548 | ubi_err("read-only mode"); | 548 | ubi_err("read-only mode"); |
@@ -819,7 +819,7 @@ int ubi_io_write_ec_hdr(struct ubi_device *ubi, int pnum, | |||
819 | 819 | ||
820 | err = paranoid_check_ec_hdr(ubi, pnum, ec_hdr); | 820 | err = paranoid_check_ec_hdr(ubi, pnum, ec_hdr); |
821 | if (err) | 821 | if (err) |
822 | return -EINVAL; | 822 | return err; |
823 | 823 | ||
824 | err = ubi_io_write(ubi, ec_hdr, pnum, 0, ubi->ec_hdr_alsize); | 824 | err = ubi_io_write(ubi, ec_hdr, pnum, 0, ubi->ec_hdr_alsize); |
825 | return err; | 825 | return err; |
@@ -1083,7 +1083,7 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum, | |||
1083 | 1083 | ||
1084 | err = paranoid_check_peb_ec_hdr(ubi, pnum); | 1084 | err = paranoid_check_peb_ec_hdr(ubi, pnum); |
1085 | if (err) | 1085 | if (err) |
1086 | return err > 0 ? -EINVAL : err; | 1086 | return err; |
1087 | 1087 | ||
1088 | vid_hdr->magic = cpu_to_be32(UBI_VID_HDR_MAGIC); | 1088 | vid_hdr->magic = cpu_to_be32(UBI_VID_HDR_MAGIC); |
1089 | vid_hdr->version = UBI_VERSION; | 1089 | vid_hdr->version = UBI_VERSION; |
@@ -1092,7 +1092,7 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum, | |||
1092 | 1092 | ||
1093 | err = paranoid_check_vid_hdr(ubi, pnum, vid_hdr); | 1093 | err = paranoid_check_vid_hdr(ubi, pnum, vid_hdr); |
1094 | if (err) | 1094 | if (err) |
1095 | return -EINVAL; | 1095 | return err; |
1096 | 1096 | ||
1097 | p = (char *)vid_hdr - ubi->vid_hdr_shift; | 1097 | p = (char *)vid_hdr - ubi->vid_hdr_shift; |
1098 | err = ubi_io_write(ubi, p, pnum, ubi->vid_hdr_aloffset, | 1098 | err = ubi_io_write(ubi, p, pnum, ubi->vid_hdr_aloffset, |
@@ -1107,8 +1107,8 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum, | |||
1107 | * @ubi: UBI device description object | 1107 | * @ubi: UBI device description object |
1108 | * @pnum: physical eraseblock number to check | 1108 | * @pnum: physical eraseblock number to check |
1109 | * | 1109 | * |
1110 | * This function returns zero if the physical eraseblock is good, a positive | 1110 | * This function returns zero if the physical eraseblock is good, %-EINVAL if |
1111 | * number if it is bad and a negative error code if an error occurred. | 1111 | * it is bad and a negative error code if an error occurred. |
1112 | */ | 1112 | */ |
1113 | static int paranoid_check_not_bad(const struct ubi_device *ubi, int pnum) | 1113 | static int paranoid_check_not_bad(const struct ubi_device *ubi, int pnum) |
1114 | { | 1114 | { |
@@ -1120,7 +1120,7 @@ static int paranoid_check_not_bad(const struct ubi_device *ubi, int pnum) | |||
1120 | 1120 | ||
1121 | ubi_err("paranoid check failed for PEB %d", pnum); | 1121 | ubi_err("paranoid check failed for PEB %d", pnum); |
1122 | ubi_dbg_dump_stack(); | 1122 | ubi_dbg_dump_stack(); |
1123 | return err; | 1123 | return err > 0 ? -EINVAL : err; |
1124 | } | 1124 | } |
1125 | 1125 | ||
1126 | /** | 1126 | /** |
@@ -1130,7 +1130,7 @@ static int paranoid_check_not_bad(const struct ubi_device *ubi, int pnum) | |||
1130 | * @ec_hdr: the erase counter header to check | 1130 | * @ec_hdr: the erase counter header to check |
1131 | * | 1131 | * |
1132 | * This function returns zero if the erase counter header contains valid | 1132 | * This function returns zero if the erase counter header contains valid |
1133 | * values, and %1 if not. | 1133 | * values, and %-EINVAL if not. |
1134 | */ | 1134 | */ |
1135 | static int paranoid_check_ec_hdr(const struct ubi_device *ubi, int pnum, | 1135 | static int paranoid_check_ec_hdr(const struct ubi_device *ubi, int pnum, |
1136 | const struct ubi_ec_hdr *ec_hdr) | 1136 | const struct ubi_ec_hdr *ec_hdr) |
@@ -1156,7 +1156,7 @@ static int paranoid_check_ec_hdr(const struct ubi_device *ubi, int pnum, | |||
1156 | fail: | 1156 | fail: |
1157 | ubi_dbg_dump_ec_hdr(ec_hdr); | 1157 | ubi_dbg_dump_ec_hdr(ec_hdr); |
1158 | ubi_dbg_dump_stack(); | 1158 | ubi_dbg_dump_stack(); |
1159 | return 1; | 1159 | return -EINVAL; |
1160 | } | 1160 | } |
1161 | 1161 | ||
1162 | /** | 1162 | /** |
@@ -1164,8 +1164,8 @@ fail: | |||
1164 | * @ubi: UBI device description object | 1164 | * @ubi: UBI device description object |
1165 | * @pnum: the physical eraseblock number to check | 1165 | * @pnum: the physical eraseblock number to check |
1166 | * | 1166 | * |
1167 | * This function returns zero if the erase counter header is all right, %1 if | 1167 | * This function returns zero if the erase counter header is all right and and |
1168 | * not, and a negative error code if an error occurred. | 1168 | * a negative error code if not or if an error occurred. |
1169 | */ | 1169 | */ |
1170 | static int paranoid_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum) | 1170 | static int paranoid_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum) |
1171 | { | 1171 | { |
@@ -1188,7 +1188,7 @@ static int paranoid_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum) | |||
1188 | ubi_err("paranoid check failed for PEB %d", pnum); | 1188 | ubi_err("paranoid check failed for PEB %d", pnum); |
1189 | ubi_dbg_dump_ec_hdr(ec_hdr); | 1189 | ubi_dbg_dump_ec_hdr(ec_hdr); |
1190 | ubi_dbg_dump_stack(); | 1190 | ubi_dbg_dump_stack(); |
1191 | err = 1; | 1191 | err = -EINVAL; |
1192 | goto exit; | 1192 | goto exit; |
1193 | } | 1193 | } |
1194 | 1194 | ||
@@ -1206,7 +1206,7 @@ exit: | |||
1206 | * @vid_hdr: the volume identifier header to check | 1206 | * @vid_hdr: the volume identifier header to check |
1207 | * | 1207 | * |
1208 | * This function returns zero if the volume identifier header is all right, and | 1208 | * This function returns zero if the volume identifier header is all right, and |
1209 | * %1 if not. | 1209 | * %-EINVAL if not. |
1210 | */ | 1210 | */ |
1211 | static int paranoid_check_vid_hdr(const struct ubi_device *ubi, int pnum, | 1211 | static int paranoid_check_vid_hdr(const struct ubi_device *ubi, int pnum, |
1212 | const struct ubi_vid_hdr *vid_hdr) | 1212 | const struct ubi_vid_hdr *vid_hdr) |
@@ -1233,7 +1233,7 @@ fail: | |||
1233 | ubi_err("paranoid check failed for PEB %d", pnum); | 1233 | ubi_err("paranoid check failed for PEB %d", pnum); |
1234 | ubi_dbg_dump_vid_hdr(vid_hdr); | 1234 | ubi_dbg_dump_vid_hdr(vid_hdr); |
1235 | ubi_dbg_dump_stack(); | 1235 | ubi_dbg_dump_stack(); |
1236 | return 1; | 1236 | return -EINVAL; |
1237 | 1237 | ||
1238 | } | 1238 | } |
1239 | 1239 | ||
@@ -1243,7 +1243,7 @@ fail: | |||
1243 | * @pnum: the physical eraseblock number to check | 1243 | * @pnum: the physical eraseblock number to check |
1244 | * | 1244 | * |
1245 | * This function returns zero if the volume identifier header is all right, | 1245 | * This function returns zero if the volume identifier header is all right, |
1246 | * %1 if not, and a negative error code if an error occurred. | 1246 | * and a negative error code if not or if an error occurred. |
1247 | */ | 1247 | */ |
1248 | static int paranoid_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum) | 1248 | static int paranoid_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum) |
1249 | { | 1249 | { |
@@ -1270,7 +1270,7 @@ static int paranoid_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum) | |||
1270 | ubi_err("paranoid check failed for PEB %d", pnum); | 1270 | ubi_err("paranoid check failed for PEB %d", pnum); |
1271 | ubi_dbg_dump_vid_hdr(vid_hdr); | 1271 | ubi_dbg_dump_vid_hdr(vid_hdr); |
1272 | ubi_dbg_dump_stack(); | 1272 | ubi_dbg_dump_stack(); |
1273 | err = 1; | 1273 | err = -EINVAL; |
1274 | goto exit; | 1274 | goto exit; |
1275 | } | 1275 | } |
1276 | 1276 | ||
@@ -1289,8 +1289,8 @@ exit: | |||
1289 | * @len: the length of the region to check | 1289 | * @len: the length of the region to check |
1290 | * | 1290 | * |
1291 | * This function returns zero if only 0xFF bytes are present at offset | 1291 | * This function returns zero if only 0xFF bytes are present at offset |
1292 | * @offset of the physical eraseblock @pnum, %1 if not, and a negative error | 1292 | * @offset of the physical eraseblock @pnum, and a negative error code if not |
1293 | * code if an error occurred. | 1293 | * or if an error occurred. |
1294 | */ | 1294 | */ |
1295 | int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len) | 1295 | int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len) |
1296 | { | 1296 | { |
@@ -1321,7 +1321,7 @@ fail: | |||
1321 | ubi_msg("hex dump of the %d-%d region", offset, offset + len); | 1321 | ubi_msg("hex dump of the %d-%d region", offset, offset + len); |
1322 | print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, | 1322 | print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, |
1323 | ubi->dbg_peb_buf, len, 1); | 1323 | ubi->dbg_peb_buf, len, 1); |
1324 | err = 1; | 1324 | err = -EINVAL; |
1325 | error: | 1325 | error: |
1326 | ubi_dbg_dump_stack(); | 1326 | ubi_dbg_dump_stack(); |
1327 | mutex_unlock(&ubi->dbg_buf_mutex); | 1327 | mutex_unlock(&ubi->dbg_buf_mutex); |
diff --git a/drivers/mtd/ubi/scan.c b/drivers/mtd/ubi/scan.c index 90af61a2c3e4..594184bbd56a 100644 --- a/drivers/mtd/ubi/scan.c +++ b/drivers/mtd/ubi/scan.c | |||
@@ -974,11 +974,8 @@ struct ubi_scan_info *ubi_scan(struct ubi_device *ubi) | |||
974 | seb->ec = si->mean_ec; | 974 | seb->ec = si->mean_ec; |
975 | 975 | ||
976 | err = paranoid_check_si(ubi, si); | 976 | err = paranoid_check_si(ubi, si); |
977 | if (err) { | 977 | if (err) |
978 | if (err > 0) | ||
979 | err = -EINVAL; | ||
980 | goto out_vidh; | 978 | goto out_vidh; |
981 | } | ||
982 | 979 | ||
983 | ubi_free_vid_hdr(ubi, vidh); | 980 | ubi_free_vid_hdr(ubi, vidh); |
984 | kfree(ech); | 981 | kfree(ech); |
@@ -1086,8 +1083,8 @@ void ubi_scan_destroy_si(struct ubi_scan_info *si) | |||
1086 | * @ubi: UBI device description object | 1083 | * @ubi: UBI device description object |
1087 | * @si: scanning information | 1084 | * @si: scanning information |
1088 | * | 1085 | * |
1089 | * This function returns zero if the scanning information is all right, %1 if | 1086 | * This function returns zero if the scanning information is all right, and a |
1090 | * not and a negative error code if an error occurred. | 1087 | * negative error code if not or if an error occurred. |
1091 | */ | 1088 | */ |
1092 | static int paranoid_check_si(struct ubi_device *ubi, struct ubi_scan_info *si) | 1089 | static int paranoid_check_si(struct ubi_device *ubi, struct ubi_scan_info *si) |
1093 | { | 1090 | { |
@@ -1346,7 +1343,7 @@ bad_vid_hdr: | |||
1346 | 1343 | ||
1347 | out: | 1344 | out: |
1348 | ubi_dbg_dump_stack(); | 1345 | ubi_dbg_dump_stack(); |
1349 | return 1; | 1346 | return -EINVAL; |
1350 | } | 1347 | } |
1351 | 1348 | ||
1352 | #endif /* CONFIG_MTD_UBI_DEBUG_PARANOID */ | 1349 | #endif /* CONFIG_MTD_UBI_DEBUG_PARANOID */ |
diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c index 600c7229d5cf..f64ddabd4ac8 100644 --- a/drivers/mtd/ubi/wl.c +++ b/drivers/mtd/ubi/wl.c | |||
@@ -464,7 +464,7 @@ retry: | |||
464 | ubi->peb_size - ubi->vid_hdr_aloffset); | 464 | ubi->peb_size - ubi->vid_hdr_aloffset); |
465 | if (err) { | 465 | if (err) { |
466 | ubi_err("new PEB %d does not contain all 0xFF bytes", e->pnum); | 466 | ubi_err("new PEB %d does not contain all 0xFF bytes", e->pnum); |
467 | return err > 0 ? -EINVAL : err; | 467 | return err; |
468 | } | 468 | } |
469 | 469 | ||
470 | return e->pnum; | 470 | return e->pnum; |
@@ -513,7 +513,7 @@ static int sync_erase(struct ubi_device *ubi, struct ubi_wl_entry *e, | |||
513 | dbg_wl("erase PEB %d, old EC %llu", e->pnum, ec); | 513 | dbg_wl("erase PEB %d, old EC %llu", e->pnum, ec); |
514 | 514 | ||
515 | err = paranoid_check_ec(ubi, e->pnum, e->ec); | 515 | err = paranoid_check_ec(ubi, e->pnum, e->ec); |
516 | if (err > 0) | 516 | if (err) |
517 | return -EINVAL; | 517 | return -EINVAL; |
518 | 518 | ||
519 | ec_hdr = kzalloc(ubi->ec_hdr_alsize, GFP_NOFS); | 519 | ec_hdr = kzalloc(ubi->ec_hdr_alsize, GFP_NOFS); |
@@ -1572,8 +1572,7 @@ void ubi_wl_close(struct ubi_device *ubi) | |||
1572 | * @ec: the erase counter to check | 1572 | * @ec: the erase counter to check |
1573 | * | 1573 | * |
1574 | * This function returns zero if the erase counter of physical eraseblock @pnum | 1574 | * This function returns zero if the erase counter of physical eraseblock @pnum |
1575 | * is equivalent to @ec, %1 if not, and a negative error code if an error | 1575 | * is equivalent to @ec, and a negative error code if not or if an error occurred. |
1576 | * occurred. | ||
1577 | */ | 1576 | */ |
1578 | static int paranoid_check_ec(struct ubi_device *ubi, int pnum, int ec) | 1577 | static int paranoid_check_ec(struct ubi_device *ubi, int pnum, int ec) |
1579 | { | 1578 | { |
@@ -1611,8 +1610,8 @@ out_free: | |||
1611 | * @e: the wear-leveling entry to check | 1610 | * @e: the wear-leveling entry to check |
1612 | * @root: the root of the tree | 1611 | * @root: the root of the tree |
1613 | * | 1612 | * |
1614 | * This function returns zero if @e is in the @root RB-tree and %1 if it is | 1613 | * This function returns zero if @e is in the @root RB-tree and %-EINVAL if it |
1615 | * not. | 1614 | * is not. |
1616 | */ | 1615 | */ |
1617 | static int paranoid_check_in_wl_tree(struct ubi_wl_entry *e, | 1616 | static int paranoid_check_in_wl_tree(struct ubi_wl_entry *e, |
1618 | struct rb_root *root) | 1617 | struct rb_root *root) |
@@ -1623,7 +1622,7 @@ static int paranoid_check_in_wl_tree(struct ubi_wl_entry *e, | |||
1623 | ubi_err("paranoid check failed for PEB %d, EC %d, RB-tree %p ", | 1622 | ubi_err("paranoid check failed for PEB %d, EC %d, RB-tree %p ", |
1624 | e->pnum, e->ec, root); | 1623 | e->pnum, e->ec, root); |
1625 | ubi_dbg_dump_stack(); | 1624 | ubi_dbg_dump_stack(); |
1626 | return 1; | 1625 | return -EINVAL; |
1627 | } | 1626 | } |
1628 | 1627 | ||
1629 | /** | 1628 | /** |
@@ -1632,7 +1631,7 @@ static int paranoid_check_in_wl_tree(struct ubi_wl_entry *e, | |||
1632 | * @ubi: UBI device description object | 1631 | * @ubi: UBI device description object |
1633 | * @e: the wear-leveling entry to check | 1632 | * @e: the wear-leveling entry to check |
1634 | * | 1633 | * |
1635 | * This function returns zero if @e is in @ubi->pq and %1 if it is not. | 1634 | * This function returns zero if @e is in @ubi->pq and %-EINVAL if it is not. |
1636 | */ | 1635 | */ |
1637 | static int paranoid_check_in_pq(struct ubi_device *ubi, struct ubi_wl_entry *e) | 1636 | static int paranoid_check_in_pq(struct ubi_device *ubi, struct ubi_wl_entry *e) |
1638 | { | 1637 | { |
@@ -1647,6 +1646,6 @@ static int paranoid_check_in_pq(struct ubi_device *ubi, struct ubi_wl_entry *e) | |||
1647 | ubi_err("paranoid check failed for PEB %d, EC %d, Protect queue", | 1646 | ubi_err("paranoid check failed for PEB %d, EC %d, Protect queue", |
1648 | e->pnum, e->ec); | 1647 | e->pnum, e->ec); |
1649 | ubi_dbg_dump_stack(); | 1648 | ubi_dbg_dump_stack(); |
1650 | return 1; | 1649 | return -EINVAL; |
1651 | } | 1650 | } |
1652 | #endif /* CONFIG_MTD_UBI_DEBUG_PARANOID */ | 1651 | #endif /* CONFIG_MTD_UBI_DEBUG_PARANOID */ |