Merge git://git.infradead.org/ubi-2.6

* git://git.infradead.org/ubi-2.6:
UBI: add write checking
UBI: simplify debugging return codes
UBI: fix attaching error path
UBI: support attaching by MTD character device name
UBI: mark few variables as __initdata

+198 -87
+87 -46
drivers/mtd/ubi/build.c
··· 37 37 #include <linux/module.h> 38 38 #include <linux/moduleparam.h> 39 39 #include <linux/stringify.h> 40 + #include <linux/namei.h> 40 41 #include <linux/stat.h> 41 42 #include <linux/miscdevice.h> 42 43 #include <linux/log2.h> ··· 51 50 52 51 /** 53 52 * struct mtd_dev_param - MTD device parameter description data structure. 54 - * @name: MTD device name or number string 53 + * @name: MTD character device node path, MTD device name, or MTD device number 54 + * string 55 55 * @vid_hdr_offs: VID header offset 56 56 */ 57 57 struct mtd_dev_param { ··· 61 59 }; 62 60 63 61 /* Numbers of elements set in the @mtd_dev_param array */ 64 - static int mtd_devs; 62 + static int __initdata mtd_devs; 65 63 66 64 /* MTD devices specification parameters */ 67 - static struct mtd_dev_param mtd_dev_param[UBI_MAX_DEVICES]; 65 + static struct mtd_dev_param __initdata mtd_dev_param[UBI_MAX_DEVICES]; 68 66 69 67 /* Root UBI "class" object (corresponds to '/<sysfs>/class/ubi/') */ 70 68 struct class *ubi_class; ··· 365 363 /** 366 364 * ubi_sysfs_init - initialize sysfs for an UBI device. 367 365 * @ubi: UBI device description object 366 + * @ref: set to %1 on exit in case of failure if a reference to @ubi->dev was 367 + * taken 368 368 * 369 369 * This function returns zero in case of success and a negative error code in 370 370 * case of failure. 371 371 */ 372 - static int ubi_sysfs_init(struct ubi_device *ubi) 372 + static int ubi_sysfs_init(struct ubi_device *ubi, int *ref) 373 373 { 374 374 int err; 375 375 ··· 383 379 if (err) 384 380 return err; 385 381 382 + *ref = 1; 386 383 err = device_create_file(&ubi->dev, &dev_eraseblock_size); 387 384 if (err) 388 385 return err; ··· 439 434 } 440 435 441 436 /** 442 - * kill_volumes - destroy all volumes. 437 + * kill_volumes - destroy all user volumes. 443 438 * @ubi: UBI device description object 444 439 */ 445 440 static void kill_volumes(struct ubi_device *ubi) ··· 452 447 } 453 448 454 449 /** 455 - * free_user_volumes - free all user volumes. 456 - * @ubi: UBI device description object 457 - * 458 - * Normally the volumes are freed at the release function of the volume device 459 - * objects. However, on error paths the volumes have to be freed before the 460 - * device objects have been initialized. 461 - */ 462 - static void free_user_volumes(struct ubi_device *ubi) 463 - { 464 - int i; 465 - 466 - for (i = 0; i < ubi->vtbl_slots; i++) 467 - if (ubi->volumes[i]) { 468 - kfree(ubi->volumes[i]->eba_tbl); 469 - kfree(ubi->volumes[i]); 470 - } 471 - } 472 - 473 - /** 474 450 * uif_init - initialize user interfaces for an UBI device. 475 451 * @ubi: UBI device description object 452 + * @ref: set to %1 on exit in case of failure if a reference to @ubi->dev was 453 + * taken, otherwise set to %0 454 + * 455 + * This function initializes various user interfaces for an UBI device. If the 456 + * initialization fails at an early stage, this function frees all the 457 + * resources it allocated, returns an error, and @ref is set to %0. However, 458 + * if the initialization fails after the UBI device was registered in the 459 + * driver core subsystem, this function takes a reference to @ubi->dev, because 460 + * otherwise the release function ('dev_release()') would free whole @ubi 461 + * object. The @ref argument is set to %1 in this case. The caller has to put 462 + * this reference. 476 463 * 477 464 * This function returns zero in case of success and a negative error code in 478 - * case of failure. Note, this function destroys all volumes if it fails. 465 + * case of failure. 479 466 */ 480 - static int uif_init(struct ubi_device *ubi) 467 + static int uif_init(struct ubi_device *ubi, int *ref) 481 468 { 482 469 int i, err; 483 470 dev_t dev; 484 471 472 + *ref = 0; 485 473 sprintf(ubi->ubi_name, UBI_NAME_STR "%d", ubi->ubi_num); 486 474 487 475 /* ··· 502 504 goto out_unreg; 503 505 } 504 506 505 - err = ubi_sysfs_init(ubi); 507 + err = ubi_sysfs_init(ubi, ref); 506 508 if (err) 507 509 goto out_sysfs; 508 510 ··· 520 522 out_volumes: 521 523 kill_volumes(ubi); 522 524 out_sysfs: 525 + if (*ref) 526 + get_device(&ubi->dev); 523 527 ubi_sysfs_close(ubi); 524 528 cdev_del(&ubi->cdev); 525 529 out_unreg: ··· 875 875 int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset) 876 876 { 877 877 struct ubi_device *ubi; 878 - int i, err, do_free = 1; 878 + int i, err, ref = 0; 879 879 880 880 /* 881 881 * Check if we already have the same MTD device attached. ··· 975 975 goto out_detach; 976 976 } 977 977 978 - err = uif_init(ubi); 978 + err = uif_init(ubi, &ref); 979 979 if (err) 980 - goto out_nofree; 980 + goto out_detach; 981 981 982 982 ubi->bgt_thread = kthread_create(ubi_thread, ubi, ubi->bgt_name); 983 983 if (IS_ERR(ubi->bgt_thread)) { ··· 1025 1025 1026 1026 out_uif: 1027 1027 uif_close(ubi); 1028 - out_nofree: 1029 - do_free = 0; 1030 1028 out_detach: 1031 1029 ubi_wl_close(ubi); 1032 - if (do_free) 1033 - free_user_volumes(ubi); 1034 1030 free_internal_volumes(ubi); 1035 1031 vfree(ubi->vtbl); 1036 1032 out_free: ··· 1035 1039 #ifdef CONFIG_MTD_UBI_DEBUG_PARANOID 1036 1040 vfree(ubi->dbg_peb_buf); 1037 1041 #endif 1038 - kfree(ubi); 1042 + if (ref) 1043 + put_device(&ubi->dev); 1044 + else 1045 + kfree(ubi); 1039 1046 return err; 1040 1047 } 1041 1048 ··· 1095 1096 1096 1097 /* 1097 1098 * Get a reference to the device in order to prevent 'dev_release()' 1098 - * from freeing @ubi object. 1099 + * from freeing the @ubi object. 1099 1100 */ 1100 1101 get_device(&ubi->dev); 1101 1102 ··· 1115 1116 } 1116 1117 1117 1118 /** 1118 - * find_mtd_device - open an MTD device by its name or number. 1119 - * @mtd_dev: name or number of the device 1119 + * open_mtd_by_chdev - open an MTD device by its character device node path. 1120 + * @mtd_dev: MTD character device node path 1121 + * 1122 + * This helper function opens an MTD device by its character node device path. 1123 + * Returns MTD device description object in case of success and a negative 1124 + * error code in case of failure. 1125 + */ 1126 + static struct mtd_info * __init open_mtd_by_chdev(const char *mtd_dev) 1127 + { 1128 + int err, major, minor, mode; 1129 + struct path path; 1130 + 1131 + /* Probably this is an MTD character device node path */ 1132 + err = kern_path(mtd_dev, LOOKUP_FOLLOW, &path); 1133 + if (err) 1134 + return ERR_PTR(err); 1135 + 1136 + /* MTD device number is defined by the major / minor numbers */ 1137 + major = imajor(path.dentry->d_inode); 1138 + minor = iminor(path.dentry->d_inode); 1139 + mode = path.dentry->d_inode->i_mode; 1140 + path_put(&path); 1141 + if (major != MTD_CHAR_MAJOR || !S_ISCHR(mode)) 1142 + return ERR_PTR(-EINVAL); 1143 + 1144 + if (minor & 1) 1145 + /* 1146 + * Just do not think the "/dev/mtdrX" devices support is need, 1147 + * so do not support them to avoid doing extra work. 1148 + */ 1149 + return ERR_PTR(-EINVAL); 1150 + 1151 + return get_mtd_device(NULL, minor / 2); 1152 + } 1153 + 1154 + /** 1155 + * open_mtd_device - open MTD device by name, character device path, or number. 1156 + * @mtd_dev: name, character device node path, or MTD device device number 1120 1157 * 1121 1158 * This function tries to open and MTD device described by @mtd_dev string, 1122 - * which is first treated as an ASCII number, and if it is not true, it is 1123 - * treated as MTD device name. Returns MTD device description object in case of 1124 - * success and a negative error code in case of failure. 1159 + * which is first treated as ASCII MTD device number, and if it is not true, it 1160 + * is treated as MTD device name, and if that is also not true, it is treated 1161 + * as MTD character device node path. Returns MTD device description object in 1162 + * case of success and a negative error code in case of failure. 1125 1163 */ 1126 1164 static struct mtd_info * __init open_mtd_device(const char *mtd_dev) 1127 1165 { ··· 1173 1137 * MTD device name. 1174 1138 */ 1175 1139 mtd = get_mtd_device_nm(mtd_dev); 1140 + if (IS_ERR(mtd) && PTR_ERR(mtd) == -ENODEV) 1141 + /* Probably this is an MTD character device node path */ 1142 + mtd = open_mtd_by_chdev(mtd_dev); 1176 1143 } else 1177 1144 mtd = get_mtd_device(NULL, mtd_num); 1178 1145 ··· 1391 1352 1392 1353 module_param_call(mtd, ubi_mtd_param_parse, NULL, NULL, 000); 1393 1354 MODULE_PARM_DESC(mtd, "MTD devices to attach. Parameter format: " 1394 - "mtd=<name|num>[,<vid_hdr_offs>].\n" 1355 + "mtd=<name|num|path>[,<vid_hdr_offs>].\n" 1395 1356 "Multiple \"mtd\" parameters may be specified.\n" 1396 - "MTD devices may be specified by their number or name.\n" 1357 + "MTD devices may be specified by their number, name, or " 1358 + "path to the MTD character device node.\n" 1397 1359 "Optional \"vid_hdr_offs\" parameter specifies UBI VID " 1398 - "header position and data starting position to be used " 1399 - "by UBI.\n" 1400 - "Example: mtd=content,1984 mtd=4 - attach MTD device" 1360 + "header position to be used by UBI.\n" 1361 + "Example 1: mtd=/dev/mtd0 - attach MTD device " 1362 + "/dev/mtd0.\n" 1363 + "Example 2: mtd=content,1984 mtd=4 - attach MTD device " 1401 1364 "with name \"content\" using VID header offset 1984, and " 1402 1365 "MTD device number 4 with default VID header offset."); 1403 1366
+4
drivers/mtd/ubi/debug.h
··· 96 96 97 97 #ifdef CONFIG_MTD_UBI_DEBUG_PARANOID 98 98 int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len); 99 + int ubi_dbg_check_write(struct ubi_device *ubi, const void *buf, int pnum, 100 + int offset, int len); 99 101 #else 100 102 #define ubi_dbg_check_all_ff(ubi, pnum, offset, len) 0 103 + #define ubi_dbg_check_write(ubi, buf, pnum, offset, len) 0 101 104 #endif 102 105 103 106 #ifdef CONFIG_MTD_UBI_DEBUG_DISABLE_BGT ··· 179 176 #define ubi_dbg_is_write_failure() 0 180 177 #define ubi_dbg_is_erase_failure() 0 181 178 #define ubi_dbg_check_all_ff(ubi, pnum, offset, len) 0 179 + #define ubi_dbg_check_write(ubi, buf, pnum, offset, len) 0 182 180 183 181 #endif /* !CONFIG_MTD_UBI_DEBUG */ 184 182 #endif /* !__UBI_DEBUG_H__ */
+95 -25
drivers/mtd/ubi/io.c
··· 143 143 144 144 err = paranoid_check_not_bad(ubi, pnum); 145 145 if (err) 146 - return err > 0 ? -EINVAL : err; 146 + return err; 147 147 148 148 addr = (loff_t)pnum * ubi->peb_size + offset; 149 149 retry: ··· 236 236 237 237 err = paranoid_check_not_bad(ubi, pnum); 238 238 if (err) 239 - return err > 0 ? -EINVAL : err; 239 + return err; 240 240 241 241 /* The area we are writing to has to contain all 0xFF bytes */ 242 242 err = ubi_dbg_check_all_ff(ubi, pnum, offset, len); 243 243 if (err) 244 - return err > 0 ? -EINVAL : err; 244 + return err; 245 245 246 246 if (offset >= ubi->leb_start) { 247 247 /* ··· 250 250 */ 251 251 err = paranoid_check_peb_ec_hdr(ubi, pnum); 252 252 if (err) 253 - return err > 0 ? -EINVAL : err; 253 + return err; 254 254 err = paranoid_check_peb_vid_hdr(ubi, pnum); 255 255 if (err) 256 - return err > 0 ? -EINVAL : err; 256 + return err; 257 257 } 258 258 259 259 if (ubi_dbg_is_write_failure()) { ··· 272 272 ubi_dbg_dump_flash(ubi, pnum, offset, len); 273 273 } else 274 274 ubi_assert(written == len); 275 + 276 + if (!err) { 277 + err = ubi_dbg_check_write(ubi, buf, pnum, offset, len); 278 + if (err) 279 + return err; 280 + 281 + /* 282 + * Since we always write sequentially, the rest of the PEB has 283 + * to contain only 0xFF bytes. 284 + */ 285 + offset += len; 286 + len = ubi->peb_size - offset; 287 + if (len) 288 + err = ubi_dbg_check_all_ff(ubi, pnum, offset, len); 289 + } 275 290 276 291 return err; 277 292 } ··· 363 348 364 349 err = ubi_dbg_check_all_ff(ubi, pnum, 0, ubi->peb_size); 365 350 if (err) 366 - return err > 0 ? -EINVAL : err; 351 + return err; 367 352 368 353 if (ubi_dbg_is_erase_failure() && !err) { 369 354 dbg_err("cannot erase PEB %d (emulated)", pnum); ··· 557 542 558 543 err = paranoid_check_not_bad(ubi, pnum); 559 544 if (err != 0) 560 - return err > 0 ? -EINVAL : err; 545 + return err; 561 546 562 547 if (ubi->ro_mode) { 563 548 ubi_err("read-only mode"); ··· 834 819 835 820 err = paranoid_check_ec_hdr(ubi, pnum, ec_hdr); 836 821 if (err) 837 - return -EINVAL; 822 + return err; 838 823 839 824 err = ubi_io_write(ubi, ec_hdr, pnum, 0, ubi->ec_hdr_alsize); 840 825 return err; ··· 1098 1083 1099 1084 err = paranoid_check_peb_ec_hdr(ubi, pnum); 1100 1085 if (err) 1101 - return err > 0 ? -EINVAL : err; 1086 + return err; 1102 1087 1103 1088 vid_hdr->magic = cpu_to_be32(UBI_VID_HDR_MAGIC); 1104 1089 vid_hdr->version = UBI_VERSION; ··· 1107 1092 1108 1093 err = paranoid_check_vid_hdr(ubi, pnum, vid_hdr); 1109 1094 if (err) 1110 - return -EINVAL; 1095 + return err; 1111 1096 1112 1097 p = (char *)vid_hdr - ubi->vid_hdr_shift; 1113 1098 err = ubi_io_write(ubi, p, pnum, ubi->vid_hdr_aloffset, ··· 1122 1107 * @ubi: UBI device description object 1123 1108 * @pnum: physical eraseblock number to check 1124 1109 * 1125 - * This function returns zero if the physical eraseblock is good, a positive 1126 - * number if it is bad and a negative error code if an error occurred. 1110 + * This function returns zero if the physical eraseblock is good, %-EINVAL if 1111 + * it is bad and a negative error code if an error occurred. 1127 1112 */ 1128 1113 static int paranoid_check_not_bad(const struct ubi_device *ubi, int pnum) 1129 1114 { ··· 1135 1120 1136 1121 ubi_err("paranoid check failed for PEB %d", pnum); 1137 1122 ubi_dbg_dump_stack(); 1138 - return err; 1123 + return err > 0 ? -EINVAL : err; 1139 1124 } 1140 1125 1141 1126 /** ··· 1145 1130 * @ec_hdr: the erase counter header to check 1146 1131 * 1147 1132 * This function returns zero if the erase counter header contains valid 1148 - * values, and %1 if not. 1133 + * values, and %-EINVAL if not. 1149 1134 */ 1150 1135 static int paranoid_check_ec_hdr(const struct ubi_device *ubi, int pnum, 1151 1136 const struct ubi_ec_hdr *ec_hdr) ··· 1171 1156 fail: 1172 1157 ubi_dbg_dump_ec_hdr(ec_hdr); 1173 1158 ubi_dbg_dump_stack(); 1174 - return 1; 1159 + return -EINVAL; 1175 1160 } 1176 1161 1177 1162 /** ··· 1179 1164 * @ubi: UBI device description object 1180 1165 * @pnum: the physical eraseblock number to check 1181 1166 * 1182 - * This function returns zero if the erase counter header is all right, %1 if 1183 - * not, and a negative error code if an error occurred. 1167 + * This function returns zero if the erase counter header is all right and and 1168 + * a negative error code if not or if an error occurred. 1184 1169 */ 1185 1170 static int paranoid_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum) 1186 1171 { ··· 1203 1188 ubi_err("paranoid check failed for PEB %d", pnum); 1204 1189 ubi_dbg_dump_ec_hdr(ec_hdr); 1205 1190 ubi_dbg_dump_stack(); 1206 - err = 1; 1191 + err = -EINVAL; 1207 1192 goto exit; 1208 1193 } 1209 1194 ··· 1221 1206 * @vid_hdr: the volume identifier header to check 1222 1207 * 1223 1208 * This function returns zero if the volume identifier header is all right, and 1224 - * %1 if not. 1209 + * %-EINVAL if not. 1225 1210 */ 1226 1211 static int paranoid_check_vid_hdr(const struct ubi_device *ubi, int pnum, 1227 1212 const struct ubi_vid_hdr *vid_hdr) ··· 1248 1233 ubi_err("paranoid check failed for PEB %d", pnum); 1249 1234 ubi_dbg_dump_vid_hdr(vid_hdr); 1250 1235 ubi_dbg_dump_stack(); 1251 - return 1; 1236 + return -EINVAL; 1252 1237 1253 1238 } 1254 1239 ··· 1258 1243 * @pnum: the physical eraseblock number to check 1259 1244 * 1260 1245 * This function returns zero if the volume identifier header is all right, 1261 - * %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. 1262 1247 */ 1263 1248 static int paranoid_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum) 1264 1249 { ··· 1285 1270 ubi_err("paranoid check failed for PEB %d", pnum); 1286 1271 ubi_dbg_dump_vid_hdr(vid_hdr); 1287 1272 ubi_dbg_dump_stack(); 1288 - err = 1; 1273 + err = -EINVAL; 1289 1274 goto exit; 1290 1275 } 1291 1276 ··· 1297 1282 } 1298 1283 1299 1284 /** 1285 + * ubi_dbg_check_write - make sure write succeeded. 1286 + * @ubi: UBI device description object 1287 + * @buf: buffer with data which were written 1288 + * @pnum: physical eraseblock number the data were written to 1289 + * @offset: offset within the physical eraseblock the data were written to 1290 + * @len: how many bytes were written 1291 + * 1292 + * This functions reads data which were recently written and compares it with 1293 + * the original data buffer - the data have to match. Returns zero if the data 1294 + * match and a negative error code if not or in case of failure. 1295 + */ 1296 + int ubi_dbg_check_write(struct ubi_device *ubi, const void *buf, int pnum, 1297 + int offset, int len) 1298 + { 1299 + int err, i; 1300 + 1301 + mutex_lock(&ubi->dbg_buf_mutex); 1302 + err = ubi_io_read(ubi, ubi->dbg_peb_buf, pnum, offset, len); 1303 + if (err) 1304 + goto out_unlock; 1305 + 1306 + for (i = 0; i < len; i++) { 1307 + uint8_t c = ((uint8_t *)buf)[i]; 1308 + uint8_t c1 = ((uint8_t *)ubi->dbg_peb_buf)[i]; 1309 + int dump_len; 1310 + 1311 + if (c == c1) 1312 + continue; 1313 + 1314 + ubi_err("paranoid check failed for PEB %d:%d, len %d", 1315 + pnum, offset, len); 1316 + ubi_msg("data differ at position %d", i); 1317 + dump_len = max_t(int, 128, len - i); 1318 + ubi_msg("hex dump of the original buffer from %d to %d", 1319 + i, i + dump_len); 1320 + print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, 1321 + buf + i, dump_len, 1); 1322 + ubi_msg("hex dump of the read buffer from %d to %d", 1323 + i, i + dump_len); 1324 + print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, 1325 + ubi->dbg_peb_buf + i, dump_len, 1); 1326 + ubi_dbg_dump_stack(); 1327 + err = -EINVAL; 1328 + goto out_unlock; 1329 + } 1330 + mutex_unlock(&ubi->dbg_buf_mutex); 1331 + 1332 + return 0; 1333 + 1334 + out_unlock: 1335 + mutex_unlock(&ubi->dbg_buf_mutex); 1336 + return err; 1337 + } 1338 + 1339 + /** 1300 1340 * ubi_dbg_check_all_ff - check that a region of flash is empty. 1301 1341 * @ubi: UBI device description object 1302 1342 * @pnum: the physical eraseblock number to check ··· 1359 1289 * @len: the length of the region to check 1360 1290 * 1361 1291 * This function returns zero if only 0xFF bytes are present at offset 1362 - * @offset of the physical eraseblock @pnum, %1 if not, and a negative error 1363 - * code if an error occurred. 1292 + * @offset of the physical eraseblock @pnum, and a negative error code if not 1293 + * or if an error occurred. 1364 1294 */ 1365 1295 int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len) 1366 1296 { ··· 1391 1321 ubi_msg("hex dump of the %d-%d region", offset, offset + len); 1392 1322 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, 1393 1323 ubi->dbg_peb_buf, len, 1); 1394 - err = 1; 1324 + err = -EINVAL; 1395 1325 error: 1396 1326 ubi_dbg_dump_stack(); 1397 1327 mutex_unlock(&ubi->dbg_buf_mutex);
+4 -7
drivers/mtd/ubi/scan.c
··· 974 974 seb->ec = si->mean_ec; 975 975 976 976 err = paranoid_check_si(ubi, si); 977 - if (err) { 978 - if (err > 0) 979 - err = -EINVAL; 977 + if (err) 980 978 goto out_vidh; 981 - } 982 979 983 980 ubi_free_vid_hdr(ubi, vidh); 984 981 kfree(ech); ··· 1083 1086 * @ubi: UBI device description object 1084 1087 * @si: scanning information 1085 1088 * 1086 - * This function returns zero if the scanning information is all right, %1 if 1087 - * not and a negative error code if an error occurred. 1089 + * This function returns zero if the scanning information is all right, and a 1090 + * negative error code if not or if an error occurred. 1088 1091 */ 1089 1092 static int paranoid_check_si(struct ubi_device *ubi, struct ubi_scan_info *si) 1090 1093 { ··· 1343 1346 1344 1347 out: 1345 1348 ubi_dbg_dump_stack(); 1346 - return 1; 1349 + return -EINVAL; 1347 1350 } 1348 1351 1349 1352 #endif /* CONFIG_MTD_UBI_DEBUG_PARANOID */
+8 -9
drivers/mtd/ubi/wl.c
··· 464 464 ubi->peb_size - ubi->vid_hdr_aloffset); 465 465 if (err) { 466 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 470 return e->pnum; ··· 513 513 dbg_wl("erase PEB %d, old EC %llu", e->pnum, ec); 514 514 515 515 err = paranoid_check_ec(ubi, e->pnum, e->ec); 516 - if (err > 0) 516 + if (err) 517 517 return -EINVAL; 518 518 519 519 ec_hdr = kzalloc(ubi->ec_hdr_alsize, GFP_NOFS); ··· 1572 1572 * @ec: the erase counter to check 1573 1573 * 1574 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 1576 - * occurred. 1575 + * is equivalent to @ec, and a negative error code if not or if an error occurred. 1577 1576 */ 1578 1577 static int paranoid_check_ec(struct ubi_device *ubi, int pnum, int ec) 1579 1578 { ··· 1610 1611 * @e: the wear-leveling entry to check 1611 1612 * @root: the root of the tree 1612 1613 * 1613 - * This function returns zero if @e is in the @root RB-tree and %1 if it is 1614 - * not. 1614 + * This function returns zero if @e is in the @root RB-tree and %-EINVAL if it 1615 + * is not. 1615 1616 */ 1616 1617 static int paranoid_check_in_wl_tree(struct ubi_wl_entry *e, 1617 1618 struct rb_root *root) ··· 1622 1623 ubi_err("paranoid check failed for PEB %d, EC %d, RB-tree %p ", 1623 1624 e->pnum, e->ec, root); 1624 1625 ubi_dbg_dump_stack(); 1625 - return 1; 1626 + return -EINVAL; 1626 1627 } 1627 1628 1628 1629 /** ··· 1631 1632 * @ubi: UBI device description object 1632 1633 * @e: the wear-leveling entry to check 1633 1634 * 1634 - * This function returns zero if @e is in @ubi->pq and %1 if it is not. 1635 + * This function returns zero if @e is in @ubi->pq and %-EINVAL if it is not. 1635 1636 */ 1636 1637 static int paranoid_check_in_pq(struct ubi_device *ubi, struct ubi_wl_entry *e) 1637 1638 { ··· 1646 1647 ubi_err("paranoid check failed for PEB %d, EC %d, Protect queue", 1647 1648 e->pnum, e->ec); 1648 1649 ubi_dbg_dump_stack(); 1649 - return 1; 1650 + return -EINVAL; 1650 1651 } 1651 1652 #endif /* CONFIG_MTD_UBI_DEBUG_PARANOID */