aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/ubi
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mtd/ubi')
-rw-r--r--drivers/mtd/ubi/Kconfig2
-rw-r--r--drivers/mtd/ubi/build.c137
-rw-r--r--drivers/mtd/ubi/cdev.c2
-rw-r--r--drivers/mtd/ubi/debug.h4
-rw-r--r--drivers/mtd/ubi/gluebi.c1
-rw-r--r--drivers/mtd/ubi/io.c121
-rw-r--r--drivers/mtd/ubi/kapi.c40
-rw-r--r--drivers/mtd/ubi/scan.c12
-rw-r--r--drivers/mtd/ubi/ubi.h1
-rw-r--r--drivers/mtd/ubi/upd.c21
-rw-r--r--drivers/mtd/ubi/vmt.c1
-rw-r--r--drivers/mtd/ubi/vtbl.c2
-rw-r--r--drivers/mtd/ubi/wl.c17
13 files changed, 261 insertions, 100 deletions
diff --git a/drivers/mtd/ubi/Kconfig b/drivers/mtd/ubi/Kconfig
index b1cd7a1a2191..0a8c7ea764ae 100644
--- a/drivers/mtd/ubi/Kconfig
+++ b/drivers/mtd/ubi/Kconfig
@@ -1,5 +1,3 @@
1# drivers/mtd/ubi/Kconfig
2
3menu "UBI - Unsorted block images" 1menu "UBI - Unsorted block images"
4 depends on MTD 2 depends on MTD
5 3
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 14cec04c34f9..55c726dde942 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -37,12 +37,14 @@
37#include <linux/module.h> 37#include <linux/module.h>
38#include <linux/moduleparam.h> 38#include <linux/moduleparam.h>
39#include <linux/stringify.h> 39#include <linux/stringify.h>
40#include <linux/namei.h>
40#include <linux/stat.h> 41#include <linux/stat.h>
41#include <linux/miscdevice.h> 42#include <linux/miscdevice.h>
42#include <linux/log2.h> 43#include <linux/log2.h>
43#include <linux/kthread.h> 44#include <linux/kthread.h>
44#include <linux/reboot.h> 45#include <linux/reboot.h>
45#include <linux/kernel.h> 46#include <linux/kernel.h>
47#include <linux/slab.h>
46#include "ubi.h" 48#include "ubi.h"
47 49
48/* Maximum length of the 'mtd=' parameter */ 50/* Maximum length of the 'mtd=' parameter */
@@ -50,7 +52,8 @@
50 52
51/** 53/**
52 * struct mtd_dev_param - MTD device parameter description data structure. 54 * struct mtd_dev_param - MTD device parameter description data structure.
53 * @name: MTD device name or number string 55 * @name: MTD character device node path, MTD device name, or MTD device number
56 * string
54 * @vid_hdr_offs: VID header offset 57 * @vid_hdr_offs: VID header offset
55 */ 58 */
56struct mtd_dev_param { 59struct mtd_dev_param {
@@ -59,10 +62,10 @@ struct mtd_dev_param {
59}; 62};
60 63
61/* Numbers of elements set in the @mtd_dev_param array */ 64/* Numbers of elements set in the @mtd_dev_param array */
62static int mtd_devs; 65static int __initdata mtd_devs;
63 66
64/* MTD devices specification parameters */ 67/* MTD devices specification parameters */
65static struct mtd_dev_param mtd_dev_param[UBI_MAX_DEVICES]; 68static struct mtd_dev_param __initdata mtd_dev_param[UBI_MAX_DEVICES];
66 69
67/* Root UBI "class" object (corresponds to '/<sysfs>/class/ubi/') */ 70/* Root UBI "class" object (corresponds to '/<sysfs>/class/ubi/') */
68struct class *ubi_class; 71struct class *ubi_class;
@@ -87,7 +90,8 @@ DEFINE_MUTEX(ubi_devices_mutex);
87static DEFINE_SPINLOCK(ubi_devices_lock); 90static DEFINE_SPINLOCK(ubi_devices_lock);
88 91
89/* "Show" method for files in '/<sysfs>/class/ubi/' */ 92/* "Show" method for files in '/<sysfs>/class/ubi/' */
90static ssize_t ubi_version_show(struct class *class, char *buf) 93static ssize_t ubi_version_show(struct class *class, struct class_attribute *attr,
94 char *buf)
91{ 95{
92 return sprintf(buf, "%d\n", UBI_VERSION); 96 return sprintf(buf, "%d\n", UBI_VERSION);
93} 97}
@@ -363,11 +367,13 @@ static void dev_release(struct device *dev)
363/** 367/**
364 * ubi_sysfs_init - initialize sysfs for an UBI device. 368 * ubi_sysfs_init - initialize sysfs for an UBI device.
365 * @ubi: UBI device description object 369 * @ubi: UBI device description object
370 * @ref: set to %1 on exit in case of failure if a reference to @ubi->dev was
371 * taken
366 * 372 *
367 * This function returns zero in case of success and a negative error code in 373 * This function returns zero in case of success and a negative error code in
368 * case of failure. 374 * case of failure.
369 */ 375 */
370static int ubi_sysfs_init(struct ubi_device *ubi) 376static int ubi_sysfs_init(struct ubi_device *ubi, int *ref)
371{ 377{
372 int err; 378 int err;
373 379
@@ -379,6 +385,7 @@ static int ubi_sysfs_init(struct ubi_device *ubi)
379 if (err) 385 if (err)
380 return err; 386 return err;
381 387
388 *ref = 1;
382 err = device_create_file(&ubi->dev, &dev_eraseblock_size); 389 err = device_create_file(&ubi->dev, &dev_eraseblock_size);
383 if (err) 390 if (err)
384 return err; 391 return err;
@@ -434,7 +441,7 @@ static void ubi_sysfs_close(struct ubi_device *ubi)
434} 441}
435 442
436/** 443/**
437 * kill_volumes - destroy all volumes. 444 * kill_volumes - destroy all user volumes.
438 * @ubi: UBI device description object 445 * @ubi: UBI device description object
439 */ 446 */
440static void kill_volumes(struct ubi_device *ubi) 447static void kill_volumes(struct ubi_device *ubi)
@@ -447,36 +454,29 @@ static void kill_volumes(struct ubi_device *ubi)
447} 454}
448 455
449/** 456/**
450 * free_user_volumes - free all user volumes.
451 * @ubi: UBI device description object
452 *
453 * Normally the volumes are freed at the release function of the volume device
454 * objects. However, on error paths the volumes have to be freed before the
455 * device objects have been initialized.
456 */
457static void free_user_volumes(struct ubi_device *ubi)
458{
459 int i;
460
461 for (i = 0; i < ubi->vtbl_slots; i++)
462 if (ubi->volumes[i]) {
463 kfree(ubi->volumes[i]->eba_tbl);
464 kfree(ubi->volumes[i]);
465 }
466}
467
468/**
469 * uif_init - initialize user interfaces for an UBI device. 457 * uif_init - initialize user interfaces for an UBI device.
470 * @ubi: UBI device description object 458 * @ubi: UBI device description object
459 * @ref: set to %1 on exit in case of failure if a reference to @ubi->dev was
460 * taken, otherwise set to %0
461 *
462 * This function initializes various user interfaces for an UBI device. If the
463 * initialization fails at an early stage, this function frees all the
464 * resources it allocated, returns an error, and @ref is set to %0. However,
465 * if the initialization fails after the UBI device was registered in the
466 * driver core subsystem, this function takes a reference to @ubi->dev, because
467 * otherwise the release function ('dev_release()') would free whole @ubi
468 * object. The @ref argument is set to %1 in this case. The caller has to put
469 * this reference.
471 * 470 *
472 * This function returns zero in case of success and a negative error code in 471 * This function returns zero in case of success and a negative error code in
473 * case of failure. Note, this function destroys all volumes if it fails. 472 * case of failure.
474 */ 473 */
475static int uif_init(struct ubi_device *ubi) 474static int uif_init(struct ubi_device *ubi, int *ref)
476{ 475{
477 int i, err; 476 int i, err;
478 dev_t dev; 477 dev_t dev;
479 478
479 *ref = 0;
480 sprintf(ubi->ubi_name, UBI_NAME_STR "%d", ubi->ubi_num); 480 sprintf(ubi->ubi_name, UBI_NAME_STR "%d", ubi->ubi_num);
481 481
482 /* 482 /*
@@ -504,7 +504,7 @@ static int uif_init(struct ubi_device *ubi)
504 goto out_unreg; 504 goto out_unreg;
505 } 505 }
506 506
507 err = ubi_sysfs_init(ubi); 507 err = ubi_sysfs_init(ubi, ref);
508 if (err) 508 if (err)
509 goto out_sysfs; 509 goto out_sysfs;
510 510
@@ -522,6 +522,8 @@ static int uif_init(struct ubi_device *ubi)
522out_volumes: 522out_volumes:
523 kill_volumes(ubi); 523 kill_volumes(ubi);
524out_sysfs: 524out_sysfs:
525 if (*ref)
526 get_device(&ubi->dev);
525 ubi_sysfs_close(ubi); 527 ubi_sysfs_close(ubi);
526 cdev_del(&ubi->cdev); 528 cdev_del(&ubi->cdev);
527out_unreg: 529out_unreg:
@@ -875,7 +877,7 @@ static int ubi_reboot_notifier(struct notifier_block *n, unsigned long state,
875int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset) 877int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)
876{ 878{
877 struct ubi_device *ubi; 879 struct ubi_device *ubi;
878 int i, err, do_free = 1; 880 int i, err, ref = 0;
879 881
880 /* 882 /*
881 * Check if we already have the same MTD device attached. 883 * Check if we already have the same MTD device attached.
@@ -975,9 +977,9 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)
975 goto out_detach; 977 goto out_detach;
976 } 978 }
977 979
978 err = uif_init(ubi); 980 err = uif_init(ubi, &ref);
979 if (err) 981 if (err)
980 goto out_nofree; 982 goto out_detach;
981 983
982 ubi->bgt_thread = kthread_create(ubi_thread, ubi, ubi->bgt_name); 984 ubi->bgt_thread = kthread_create(ubi_thread, ubi, ubi->bgt_name);
983 if (IS_ERR(ubi->bgt_thread)) { 985 if (IS_ERR(ubi->bgt_thread)) {
@@ -1025,12 +1027,8 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)
1025 1027
1026out_uif: 1028out_uif:
1027 uif_close(ubi); 1029 uif_close(ubi);
1028out_nofree:
1029 do_free = 0;
1030out_detach: 1030out_detach:
1031 ubi_wl_close(ubi); 1031 ubi_wl_close(ubi);
1032 if (do_free)
1033 free_user_volumes(ubi);
1034 free_internal_volumes(ubi); 1032 free_internal_volumes(ubi);
1035 vfree(ubi->vtbl); 1033 vfree(ubi->vtbl);
1036out_free: 1034out_free:
@@ -1039,7 +1037,10 @@ out_free:
1039#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID 1037#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
1040 vfree(ubi->dbg_peb_buf); 1038 vfree(ubi->dbg_peb_buf);
1041#endif 1039#endif
1042 kfree(ubi); 1040 if (ref)
1041 put_device(&ubi->dev);
1042 else
1043 kfree(ubi);
1043 return err; 1044 return err;
1044} 1045}
1045 1046
@@ -1096,7 +1097,7 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)
1096 1097
1097 /* 1098 /*
1098 * Get a reference to the device in order to prevent 'dev_release()' 1099 * Get a reference to the device in order to prevent 'dev_release()'
1099 * from freeing @ubi object. 1100 * from freeing the @ubi object.
1100 */ 1101 */
1101 get_device(&ubi->dev); 1102 get_device(&ubi->dev);
1102 1103
@@ -1116,13 +1117,50 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)
1116} 1117}
1117 1118
1118/** 1119/**
1119 * find_mtd_device - open an MTD device by its name or number. 1120 * open_mtd_by_chdev - open an MTD device by its character device node path.
1120 * @mtd_dev: name or number of the device 1121 * @mtd_dev: MTD character device node path
1122 *
1123 * This helper function opens an MTD device by its character node device path.
1124 * Returns MTD device description object in case of success and a negative
1125 * error code in case of failure.
1126 */
1127static struct mtd_info * __init open_mtd_by_chdev(const char *mtd_dev)
1128{
1129 int err, major, minor, mode;
1130 struct path path;
1131
1132 /* Probably this is an MTD character device node path */
1133 err = kern_path(mtd_dev, LOOKUP_FOLLOW, &path);
1134 if (err)
1135 return ERR_PTR(err);
1136
1137 /* MTD device number is defined by the major / minor numbers */
1138 major = imajor(path.dentry->d_inode);
1139 minor = iminor(path.dentry->d_inode);
1140 mode = path.dentry->d_inode->i_mode;
1141 path_put(&path);
1142 if (major != MTD_CHAR_MAJOR || !S_ISCHR(mode))
1143 return ERR_PTR(-EINVAL);
1144
1145 if (minor & 1)
1146 /*
1147 * Just do not think the "/dev/mtdrX" devices support is need,
1148 * so do not support them to avoid doing extra work.
1149 */
1150 return ERR_PTR(-EINVAL);
1151
1152 return get_mtd_device(NULL, minor / 2);
1153}
1154
1155/**
1156 * open_mtd_device - open MTD device by name, character device path, or number.
1157 * @mtd_dev: name, character device node path, or MTD device device number
1121 * 1158 *
1122 * This function tries to open and MTD device described by @mtd_dev string, 1159 * This function tries to open and MTD device described by @mtd_dev string,
1123 * which is first treated as an ASCII number, and if it is not true, it is 1160 * which is first treated as ASCII MTD device number, and if it is not true, it
1124 * treated as MTD device name. Returns MTD device description object in case of 1161 * is treated as MTD device name, and if that is also not true, it is treated
1125 * success and a negative error code in case of failure. 1162 * as MTD character device node path. Returns MTD device description object in
1163 * case of success and a negative error code in case of failure.
1126 */ 1164 */
1127static struct mtd_info * __init open_mtd_device(const char *mtd_dev) 1165static struct mtd_info * __init open_mtd_device(const char *mtd_dev)
1128{ 1166{
@@ -1137,6 +1175,9 @@ static struct mtd_info * __init open_mtd_device(const char *mtd_dev)
1137 * MTD device name. 1175 * MTD device name.
1138 */ 1176 */
1139 mtd = get_mtd_device_nm(mtd_dev); 1177 mtd = get_mtd_device_nm(mtd_dev);
1178 if (IS_ERR(mtd) && PTR_ERR(mtd) == -ENODEV)
1179 /* Probably this is an MTD character device node path */
1180 mtd = open_mtd_by_chdev(mtd_dev);
1140 } else 1181 } else
1141 mtd = get_mtd_device(NULL, mtd_num); 1182 mtd = get_mtd_device(NULL, mtd_num);
1142 1183
@@ -1352,13 +1393,15 @@ static int __init ubi_mtd_param_parse(const char *val, struct kernel_param *kp)
1352 1393
1353module_param_call(mtd, ubi_mtd_param_parse, NULL, NULL, 000); 1394module_param_call(mtd, ubi_mtd_param_parse, NULL, NULL, 000);
1354MODULE_PARM_DESC(mtd, "MTD devices to attach. Parameter format: " 1395MODULE_PARM_DESC(mtd, "MTD devices to attach. Parameter format: "
1355 "mtd=<name|num>[,<vid_hdr_offs>].\n" 1396 "mtd=<name|num|path>[,<vid_hdr_offs>].\n"
1356 "Multiple \"mtd\" parameters may be specified.\n" 1397 "Multiple \"mtd\" parameters may be specified.\n"
1357 "MTD devices may be specified by their number or name.\n" 1398 "MTD devices may be specified by their number, name, or "
1399 "path to the MTD character device node.\n"
1358 "Optional \"vid_hdr_offs\" parameter specifies UBI VID " 1400 "Optional \"vid_hdr_offs\" parameter specifies UBI VID "
1359 "header position and data starting position to be used " 1401 "header position to be used by UBI.\n"
1360 "by UBI.\n" 1402 "Example 1: mtd=/dev/mtd0 - attach MTD device "
1361 "Example: mtd=content,1984 mtd=4 - attach MTD device" 1403 "/dev/mtd0.\n"
1404 "Example 2: mtd=content,1984 mtd=4 - attach MTD device "
1362 "with name \"content\" using VID header offset 1984, and " 1405 "with name \"content\" using VID header offset 1984, and "
1363 "MTD device number 4 with default VID header offset."); 1406 "MTD device number 4 with default VID header offset.");
1364 1407
diff --git a/drivers/mtd/ubi/cdev.c b/drivers/mtd/ubi/cdev.c
index f237ddbb2713..72ebb3f06b86 100644
--- a/drivers/mtd/ubi/cdev.c
+++ b/drivers/mtd/ubi/cdev.c
@@ -37,6 +37,7 @@
37 37
38#include <linux/module.h> 38#include <linux/module.h>
39#include <linux/stat.h> 39#include <linux/stat.h>
40#include <linux/slab.h>
40#include <linux/ioctl.h> 41#include <linux/ioctl.h>
41#include <linux/capability.h> 42#include <linux/capability.h>
42#include <linux/uaccess.h> 43#include <linux/uaccess.h>
@@ -853,7 +854,6 @@ static long ubi_cdev_ioctl(struct file *file, unsigned int cmd,
853 break; 854 break;
854 } 855 }
855 856
856 req.name[req.name_len] = '\0';
857 err = verify_mkvol_req(ubi, &req); 857 err = verify_mkvol_req(ubi, &req);
858 if (err) 858 if (err)
859 break; 859 break;
diff --git a/drivers/mtd/ubi/debug.h b/drivers/mtd/ubi/debug.h
index f30bcb372c05..17a107129726 100644
--- a/drivers/mtd/ubi/debug.h
+++ b/drivers/mtd/ubi/debug.h
@@ -96,8 +96,11 @@ void ubi_dbg_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len);
96 96
97#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID 97#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
98int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len); 98int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len);
99int ubi_dbg_check_write(struct ubi_device *ubi, const void *buf, int pnum,
100 int offset, int len);
99#else 101#else
100#define ubi_dbg_check_all_ff(ubi, pnum, offset, len) 0 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#endif 104#endif
102 105
103#ifdef CONFIG_MTD_UBI_DEBUG_DISABLE_BGT 106#ifdef CONFIG_MTD_UBI_DEBUG_DISABLE_BGT
@@ -176,6 +179,7 @@ static inline int ubi_dbg_is_erase_failure(void)
176#define ubi_dbg_is_write_failure() 0 179#define ubi_dbg_is_write_failure() 0
177#define ubi_dbg_is_erase_failure() 0 180#define ubi_dbg_is_erase_failure() 0
178#define ubi_dbg_check_all_ff(ubi, pnum, offset, len) 0 181#define ubi_dbg_check_all_ff(ubi, pnum, offset, len) 0
182#define ubi_dbg_check_write(ubi, buf, pnum, offset, len) 0
179 183
180#endif /* !CONFIG_MTD_UBI_DEBUG */ 184#endif /* !CONFIG_MTD_UBI_DEBUG */
181#endif /* !__UBI_DEBUG_H__ */ 185#endif /* !__UBI_DEBUG_H__ */
diff --git a/drivers/mtd/ubi/gluebi.c b/drivers/mtd/ubi/gluebi.c
index b5e478fa2661..9aa81584c8a2 100644
--- a/drivers/mtd/ubi/gluebi.c
+++ b/drivers/mtd/ubi/gluebi.c
@@ -31,6 +31,7 @@
31 31
32#include <linux/err.h> 32#include <linux/err.h>
33#include <linux/list.h> 33#include <linux/list.h>
34#include <linux/slab.h>
34#include <linux/sched.h> 35#include <linux/sched.h>
35#include <linux/math64.h> 36#include <linux/math64.h>
36#include <linux/module.h> 37#include <linux/module.h>
diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c
index 8aa51e7a6a7d..533b1a4b9af1 100644
--- a/drivers/mtd/ubi/io.c
+++ b/drivers/mtd/ubi/io.c
@@ -88,6 +88,7 @@
88 88
89#include <linux/crc32.h> 89#include <linux/crc32.h>
90#include <linux/err.h> 90#include <linux/err.h>
91#include <linux/slab.h>
91#include "ubi.h" 92#include "ubi.h"
92 93
93#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID 94#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
@@ -143,7 +144,7 @@ int ubi_io_read(const struct ubi_device *ubi, void *buf, int pnum, int offset,
143 144
144 err = paranoid_check_not_bad(ubi, pnum); 145 err = paranoid_check_not_bad(ubi, pnum);
145 if (err) 146 if (err)
146 return err > 0 ? -EINVAL : err; 147 return err;
147 148
148 addr = (loff_t)pnum * ubi->peb_size + offset; 149 addr = (loff_t)pnum * ubi->peb_size + offset;
149retry: 150retry:
@@ -236,12 +237,12 @@ int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset,
236 237
237 err = paranoid_check_not_bad(ubi, pnum); 238 err = paranoid_check_not_bad(ubi, pnum);
238 if (err) 239 if (err)
239 return err > 0 ? -EINVAL : err; 240 return err;
240 241
241 /* The area we are writing to has to contain all 0xFF bytes */ 242 /* The area we are writing to has to contain all 0xFF bytes */
242 err = ubi_dbg_check_all_ff(ubi, pnum, offset, len); 243 err = ubi_dbg_check_all_ff(ubi, pnum, offset, len);
243 if (err) 244 if (err)
244 return err > 0 ? -EINVAL : err; 245 return err;
245 246
246 if (offset >= ubi->leb_start) { 247 if (offset >= ubi->leb_start) {
247 /* 248 /*
@@ -250,10 +251,10 @@ int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset,
250 */ 251 */
251 err = paranoid_check_peb_ec_hdr(ubi, pnum); 252 err = paranoid_check_peb_ec_hdr(ubi, pnum);
252 if (err) 253 if (err)
253 return err > 0 ? -EINVAL : err; 254 return err;
254 err = paranoid_check_peb_vid_hdr(ubi, pnum); 255 err = paranoid_check_peb_vid_hdr(ubi, pnum);
255 if (err) 256 if (err)
256 return err > 0 ? -EINVAL : err; 257 return err;
257 } 258 }
258 259
259 if (ubi_dbg_is_write_failure()) { 260 if (ubi_dbg_is_write_failure()) {
@@ -273,6 +274,21 @@ int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset,
273 } else 274 } else
274 ubi_assert(written == len); 275 ubi_assert(written == len);
275 276
277 if (!err) {
278 err = ubi_dbg_check_write(ubi, buf, pnum, offset, len);
279 if (err)
280 return err;
281
282 /*
283 * Since we always write sequentially, the rest of the PEB has
284 * to contain only 0xFF bytes.
285 */
286 offset += len;
287 len = ubi->peb_size - offset;
288 if (len)
289 err = ubi_dbg_check_all_ff(ubi, pnum, offset, len);
290 }
291
276 return err; 292 return err;
277} 293}
278 294
@@ -348,7 +364,7 @@ retry:
348 364
349 err = ubi_dbg_check_all_ff(ubi, pnum, 0, ubi->peb_size); 365 err = ubi_dbg_check_all_ff(ubi, pnum, 0, ubi->peb_size);
350 if (err) 366 if (err)
351 return err > 0 ? -EINVAL : err; 367 return err;
352 368
353 if (ubi_dbg_is_erase_failure() && !err) { 369 if (ubi_dbg_is_erase_failure() && !err) {
354 dbg_err("cannot erase PEB %d (emulated)", pnum); 370 dbg_err("cannot erase PEB %d (emulated)", pnum);
@@ -542,7 +558,7 @@ int ubi_io_sync_erase(struct ubi_device *ubi, int pnum, int torture)
542 558
543 err = paranoid_check_not_bad(ubi, pnum); 559 err = paranoid_check_not_bad(ubi, pnum);
544 if (err != 0) 560 if (err != 0)
545 return err > 0 ? -EINVAL : err; 561 return err;
546 562
547 if (ubi->ro_mode) { 563 if (ubi->ro_mode) {
548 ubi_err("read-only mode"); 564 ubi_err("read-only mode");
@@ -819,7 +835,7 @@ int ubi_io_write_ec_hdr(struct ubi_device *ubi, int pnum,
819 835
820 err = paranoid_check_ec_hdr(ubi, pnum, ec_hdr); 836 err = paranoid_check_ec_hdr(ubi, pnum, ec_hdr);
821 if (err) 837 if (err)
822 return -EINVAL; 838 return err;
823 839
824 err = ubi_io_write(ubi, ec_hdr, pnum, 0, ubi->ec_hdr_alsize); 840 err = ubi_io_write(ubi, ec_hdr, pnum, 0, ubi->ec_hdr_alsize);
825 return err; 841 return err;
@@ -1083,7 +1099,7 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum,
1083 1099
1084 err = paranoid_check_peb_ec_hdr(ubi, pnum); 1100 err = paranoid_check_peb_ec_hdr(ubi, pnum);
1085 if (err) 1101 if (err)
1086 return err > 0 ? -EINVAL : err; 1102 return err;
1087 1103
1088 vid_hdr->magic = cpu_to_be32(UBI_VID_HDR_MAGIC); 1104 vid_hdr->magic = cpu_to_be32(UBI_VID_HDR_MAGIC);
1089 vid_hdr->version = UBI_VERSION; 1105 vid_hdr->version = UBI_VERSION;
@@ -1092,7 +1108,7 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum,
1092 1108
1093 err = paranoid_check_vid_hdr(ubi, pnum, vid_hdr); 1109 err = paranoid_check_vid_hdr(ubi, pnum, vid_hdr);
1094 if (err) 1110 if (err)
1095 return -EINVAL; 1111 return err;
1096 1112
1097 p = (char *)vid_hdr - ubi->vid_hdr_shift; 1113 p = (char *)vid_hdr - ubi->vid_hdr_shift;
1098 err = ubi_io_write(ubi, p, pnum, ubi->vid_hdr_aloffset, 1114 err = ubi_io_write(ubi, p, pnum, ubi->vid_hdr_aloffset,
@@ -1107,8 +1123,8 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum,
1107 * @ubi: UBI device description object 1123 * @ubi: UBI device description object
1108 * @pnum: physical eraseblock number to check 1124 * @pnum: physical eraseblock number to check
1109 * 1125 *
1110 * This function returns zero if the physical eraseblock is good, a positive 1126 * 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. 1127 * it is bad and a negative error code if an error occurred.
1112 */ 1128 */
1113static int paranoid_check_not_bad(const struct ubi_device *ubi, int pnum) 1129static int paranoid_check_not_bad(const struct ubi_device *ubi, int pnum)
1114{ 1130{
@@ -1120,7 +1136,7 @@ static int paranoid_check_not_bad(const struct ubi_device *ubi, int pnum)
1120 1136
1121 ubi_err("paranoid check failed for PEB %d", pnum); 1137 ubi_err("paranoid check failed for PEB %d", pnum);
1122 ubi_dbg_dump_stack(); 1138 ubi_dbg_dump_stack();
1123 return err; 1139 return err > 0 ? -EINVAL : err;
1124} 1140}
1125 1141
1126/** 1142/**
@@ -1130,7 +1146,7 @@ static int paranoid_check_not_bad(const struct ubi_device *ubi, int pnum)
1130 * @ec_hdr: the erase counter header to check 1146 * @ec_hdr: the erase counter header to check
1131 * 1147 *
1132 * This function returns zero if the erase counter header contains valid 1148 * This function returns zero if the erase counter header contains valid
1133 * values, and %1 if not. 1149 * values, and %-EINVAL if not.
1134 */ 1150 */
1135static int paranoid_check_ec_hdr(const struct ubi_device *ubi, int pnum, 1151static int paranoid_check_ec_hdr(const struct ubi_device *ubi, int pnum,
1136 const struct ubi_ec_hdr *ec_hdr) 1152 const struct ubi_ec_hdr *ec_hdr)
@@ -1156,7 +1172,7 @@ static int paranoid_check_ec_hdr(const struct ubi_device *ubi, int pnum,
1156fail: 1172fail:
1157 ubi_dbg_dump_ec_hdr(ec_hdr); 1173 ubi_dbg_dump_ec_hdr(ec_hdr);
1158 ubi_dbg_dump_stack(); 1174 ubi_dbg_dump_stack();
1159 return 1; 1175 return -EINVAL;
1160} 1176}
1161 1177
1162/** 1178/**
@@ -1164,8 +1180,8 @@ fail:
1164 * @ubi: UBI device description object 1180 * @ubi: UBI device description object
1165 * @pnum: the physical eraseblock number to check 1181 * @pnum: the physical eraseblock number to check
1166 * 1182 *
1167 * This function returns zero if the erase counter header is all right, %1 if 1183 * 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. 1184 * a negative error code if not or if an error occurred.
1169 */ 1185 */
1170static int paranoid_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum) 1186static int paranoid_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum)
1171{ 1187{
@@ -1188,7 +1204,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); 1204 ubi_err("paranoid check failed for PEB %d", pnum);
1189 ubi_dbg_dump_ec_hdr(ec_hdr); 1205 ubi_dbg_dump_ec_hdr(ec_hdr);
1190 ubi_dbg_dump_stack(); 1206 ubi_dbg_dump_stack();
1191 err = 1; 1207 err = -EINVAL;
1192 goto exit; 1208 goto exit;
1193 } 1209 }
1194 1210
@@ -1206,7 +1222,7 @@ exit:
1206 * @vid_hdr: the volume identifier header to check 1222 * @vid_hdr: the volume identifier header to check
1207 * 1223 *
1208 * This function returns zero if the volume identifier header is all right, and 1224 * This function returns zero if the volume identifier header is all right, and
1209 * %1 if not. 1225 * %-EINVAL if not.
1210 */ 1226 */
1211static int paranoid_check_vid_hdr(const struct ubi_device *ubi, int pnum, 1227static int paranoid_check_vid_hdr(const struct ubi_device *ubi, int pnum,
1212 const struct ubi_vid_hdr *vid_hdr) 1228 const struct ubi_vid_hdr *vid_hdr)
@@ -1233,7 +1249,7 @@ fail:
1233 ubi_err("paranoid check failed for PEB %d", pnum); 1249 ubi_err("paranoid check failed for PEB %d", pnum);
1234 ubi_dbg_dump_vid_hdr(vid_hdr); 1250 ubi_dbg_dump_vid_hdr(vid_hdr);
1235 ubi_dbg_dump_stack(); 1251 ubi_dbg_dump_stack();
1236 return 1; 1252 return -EINVAL;
1237 1253
1238} 1254}
1239 1255
@@ -1243,7 +1259,7 @@ fail:
1243 * @pnum: the physical eraseblock number to check 1259 * @pnum: the physical eraseblock number to check
1244 * 1260 *
1245 * This function returns zero if the volume identifier header is all right, 1261 * 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. 1262 * and a negative error code if not or if an error occurred.
1247 */ 1263 */
1248static int paranoid_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum) 1264static int paranoid_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum)
1249{ 1265{
@@ -1270,7 +1286,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); 1286 ubi_err("paranoid check failed for PEB %d", pnum);
1271 ubi_dbg_dump_vid_hdr(vid_hdr); 1287 ubi_dbg_dump_vid_hdr(vid_hdr);
1272 ubi_dbg_dump_stack(); 1288 ubi_dbg_dump_stack();
1273 err = 1; 1289 err = -EINVAL;
1274 goto exit; 1290 goto exit;
1275 } 1291 }
1276 1292
@@ -1282,6 +1298,61 @@ exit:
1282} 1298}
1283 1299
1284/** 1300/**
1301 * ubi_dbg_check_write - make sure write succeeded.
1302 * @ubi: UBI device description object
1303 * @buf: buffer with data which were written
1304 * @pnum: physical eraseblock number the data were written to
1305 * @offset: offset within the physical eraseblock the data were written to
1306 * @len: how many bytes were written
1307 *
1308 * This functions reads data which were recently written and compares it with
1309 * the original data buffer - the data have to match. Returns zero if the data
1310 * match and a negative error code if not or in case of failure.
1311 */
1312int ubi_dbg_check_write(struct ubi_device *ubi, const void *buf, int pnum,
1313 int offset, int len)
1314{
1315 int err, i;
1316
1317 mutex_lock(&ubi->dbg_buf_mutex);
1318 err = ubi_io_read(ubi, ubi->dbg_peb_buf, pnum, offset, len);
1319 if (err)
1320 goto out_unlock;
1321
1322 for (i = 0; i < len; i++) {
1323 uint8_t c = ((uint8_t *)buf)[i];
1324 uint8_t c1 = ((uint8_t *)ubi->dbg_peb_buf)[i];
1325 int dump_len;
1326
1327 if (c == c1)
1328 continue;
1329
1330 ubi_err("paranoid check failed for PEB %d:%d, len %d",
1331 pnum, offset, len);
1332 ubi_msg("data differ at position %d", i);
1333 dump_len = max_t(int, 128, len - i);
1334 ubi_msg("hex dump of the original buffer from %d to %d",
1335 i, i + dump_len);
1336 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1,
1337 buf + i, dump_len, 1);
1338 ubi_msg("hex dump of the read buffer from %d to %d",
1339 i, i + dump_len);
1340 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1,
1341 ubi->dbg_peb_buf + i, dump_len, 1);
1342 ubi_dbg_dump_stack();
1343 err = -EINVAL;
1344 goto out_unlock;
1345 }
1346 mutex_unlock(&ubi->dbg_buf_mutex);
1347
1348 return 0;
1349
1350out_unlock:
1351 mutex_unlock(&ubi->dbg_buf_mutex);
1352 return err;
1353}
1354
1355/**
1285 * ubi_dbg_check_all_ff - check that a region of flash is empty. 1356 * ubi_dbg_check_all_ff - check that a region of flash is empty.
1286 * @ubi: UBI device description object 1357 * @ubi: UBI device description object
1287 * @pnum: the physical eraseblock number to check 1358 * @pnum: the physical eraseblock number to check
@@ -1289,8 +1360,8 @@ exit:
1289 * @len: the length of the region to check 1360 * @len: the length of the region to check
1290 * 1361 *
1291 * This function returns zero if only 0xFF bytes are present at offset 1362 * 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 1363 * @offset of the physical eraseblock @pnum, and a negative error code if not
1293 * code if an error occurred. 1364 * or if an error occurred.
1294 */ 1365 */
1295int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len) 1366int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len)
1296{ 1367{
@@ -1321,7 +1392,7 @@ fail:
1321 ubi_msg("hex dump of the %d-%d region", offset, offset + len); 1392 ubi_msg("hex dump of the %d-%d region", offset, offset + len);
1322 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, 1393 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1,
1323 ubi->dbg_peb_buf, len, 1); 1394 ubi->dbg_peb_buf, len, 1);
1324 err = 1; 1395 err = -EINVAL;
1325error: 1396error:
1326 ubi_dbg_dump_stack(); 1397 ubi_dbg_dump_stack();
1327 mutex_unlock(&ubi->dbg_buf_mutex); 1398 mutex_unlock(&ubi->dbg_buf_mutex);
diff --git a/drivers/mtd/ubi/kapi.c b/drivers/mtd/ubi/kapi.c
index 88a72e9c8beb..17f287decc36 100644
--- a/drivers/mtd/ubi/kapi.c
+++ b/drivers/mtd/ubi/kapi.c
@@ -22,6 +22,9 @@
22 22
23#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/err.h> 24#include <linux/err.h>
25#include <linux/slab.h>
26#include <linux/namei.h>
27#include <linux/fs.h>
25#include <asm/div64.h> 28#include <asm/div64.h>
26#include "ubi.h" 29#include "ubi.h"
27 30
@@ -280,6 +283,43 @@ struct ubi_volume_desc *ubi_open_volume_nm(int ubi_num, const char *name,
280EXPORT_SYMBOL_GPL(ubi_open_volume_nm); 283EXPORT_SYMBOL_GPL(ubi_open_volume_nm);
281 284
282/** 285/**
286 * ubi_open_volume_path - open UBI volume by its character device node path.
287 * @pathname: volume character device node path
288 * @mode: open mode
289 *
290 * This function is similar to 'ubi_open_volume()', but opens a volume the path
291 * to its character device node.
292 */
293struct ubi_volume_desc *ubi_open_volume_path(const char *pathname, int mode)
294{
295 int error, ubi_num, vol_id, mod;
296 struct inode *inode;
297 struct path path;
298
299 dbg_gen("open volume %s, mode %d", pathname, mode);
300
301 if (!pathname || !*pathname)
302 return ERR_PTR(-EINVAL);
303
304 error = kern_path(pathname, LOOKUP_FOLLOW, &path);
305 if (error)
306 return ERR_PTR(error);
307
308 inode = path.dentry->d_inode;
309 mod = inode->i_mode;
310 ubi_num = ubi_major2num(imajor(inode));
311 vol_id = iminor(inode) - 1;
312 path_put(&path);
313
314 if (!S_ISCHR(mod))
315 return ERR_PTR(-EINVAL);
316 if (vol_id >= 0 && ubi_num >= 0)
317 return ubi_open_volume(ubi_num, vol_id, mode);
318 return ERR_PTR(-ENODEV);
319}
320EXPORT_SYMBOL_GPL(ubi_open_volume_path);
321
322/**
283 * ubi_close_volume - close UBI volume. 323 * ubi_close_volume - close UBI volume.
284 * @desc: volume descriptor 324 * @desc: volume descriptor
285 */ 325 */
diff --git a/drivers/mtd/ubi/scan.c b/drivers/mtd/ubi/scan.c
index 90af61a2c3e4..dc5f688699da 100644
--- a/drivers/mtd/ubi/scan.c
+++ b/drivers/mtd/ubi/scan.c
@@ -41,6 +41,7 @@
41 */ 41 */
42 42
43#include <linux/err.h> 43#include <linux/err.h>
44#include <linux/slab.h>
44#include <linux/crc32.h> 45#include <linux/crc32.h>
45#include <linux/math64.h> 46#include <linux/math64.h>
46#include "ubi.h" 47#include "ubi.h"
@@ -974,11 +975,8 @@ struct ubi_scan_info *ubi_scan(struct ubi_device *ubi)
974 seb->ec = si->mean_ec; 975 seb->ec = si->mean_ec;
975 976
976 err = paranoid_check_si(ubi, si); 977 err = paranoid_check_si(ubi, si);
977 if (err) { 978 if (err)
978 if (err > 0)
979 err = -EINVAL;
980 goto out_vidh; 979 goto out_vidh;
981 }
982 980
983 ubi_free_vid_hdr(ubi, vidh); 981 ubi_free_vid_hdr(ubi, vidh);
984 kfree(ech); 982 kfree(ech);
@@ -1086,8 +1084,8 @@ void ubi_scan_destroy_si(struct ubi_scan_info *si)
1086 * @ubi: UBI device description object 1084 * @ubi: UBI device description object
1087 * @si: scanning information 1085 * @si: scanning information
1088 * 1086 *
1089 * This function returns zero if the scanning information is all right, %1 if 1087 * This function returns zero if the scanning information is all right, and a
1090 * not and a negative error code if an error occurred. 1088 * negative error code if not or if an error occurred.
1091 */ 1089 */
1092static int paranoid_check_si(struct ubi_device *ubi, struct ubi_scan_info *si) 1090static int paranoid_check_si(struct ubi_device *ubi, struct ubi_scan_info *si)
1093{ 1091{
@@ -1346,7 +1344,7 @@ bad_vid_hdr:
1346 1344
1347out: 1345out:
1348 ubi_dbg_dump_stack(); 1346 ubi_dbg_dump_stack();
1349 return 1; 1347 return -EINVAL;
1350} 1348}
1351 1349
1352#endif /* CONFIG_MTD_UBI_DEBUG_PARANOID */ 1350#endif /* CONFIG_MTD_UBI_DEBUG_PARANOID */
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
index 1af08178defd..5176d4886518 100644
--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -34,6 +34,7 @@
34#include <linux/fs.h> 34#include <linux/fs.h>
35#include <linux/cdev.h> 35#include <linux/cdev.h>
36#include <linux/device.h> 36#include <linux/device.h>
37#include <linux/slab.h>
37#include <linux/string.h> 38#include <linux/string.h>
38#include <linux/vmalloc.h> 39#include <linux/vmalloc.h>
39#include <linux/notifier.h> 40#include <linux/notifier.h>
diff --git a/drivers/mtd/ubi/upd.c b/drivers/mtd/ubi/upd.c
index 74fdc40c8627..425bf5a3edd4 100644
--- a/drivers/mtd/ubi/upd.c
+++ b/drivers/mtd/ubi/upd.c
@@ -147,12 +147,15 @@ int ubi_start_update(struct ubi_device *ubi, struct ubi_volume *vol,
147 } 147 }
148 148
149 if (bytes == 0) { 149 if (bytes == 0) {
150 err = ubi_wl_flush(ubi);
151 if (err)
152 return err;
153
150 err = clear_update_marker(ubi, vol, 0); 154 err = clear_update_marker(ubi, vol, 0);
151 if (err) 155 if (err)
152 return err; 156 return err;
153 err = ubi_wl_flush(ubi); 157 vol->updating = 0;
154 if (!err) 158 return 0;
155 vol->updating = 0;
156 } 159 }
157 160
158 vol->upd_buf = vmalloc(ubi->leb_size); 161 vol->upd_buf = vmalloc(ubi->leb_size);
@@ -362,16 +365,16 @@ int ubi_more_update_data(struct ubi_device *ubi, struct ubi_volume *vol,
362 365
363 ubi_assert(vol->upd_received <= vol->upd_bytes); 366 ubi_assert(vol->upd_received <= vol->upd_bytes);
364 if (vol->upd_received == vol->upd_bytes) { 367 if (vol->upd_received == vol->upd_bytes) {
368 err = ubi_wl_flush(ubi);
369 if (err)
370 return err;
365 /* The update is finished, clear the update marker */ 371 /* The update is finished, clear the update marker */
366 err = clear_update_marker(ubi, vol, vol->upd_bytes); 372 err = clear_update_marker(ubi, vol, vol->upd_bytes);
367 if (err) 373 if (err)
368 return err; 374 return err;
369 err = ubi_wl_flush(ubi); 375 vol->updating = 0;
370 if (err == 0) { 376 err = to_write;
371 vol->updating = 0; 377 vfree(vol->upd_buf);
372 err = to_write;
373 vfree(vol->upd_buf);
374 }
375 } 378 }
376 379
377 return err; 380 return err;
diff --git a/drivers/mtd/ubi/vmt.c b/drivers/mtd/ubi/vmt.c
index ab64cb56df6e..e42afab9a9fe 100644
--- a/drivers/mtd/ubi/vmt.c
+++ b/drivers/mtd/ubi/vmt.c
@@ -25,6 +25,7 @@
25 25
26#include <linux/err.h> 26#include <linux/err.h>
27#include <linux/math64.h> 27#include <linux/math64.h>
28#include <linux/slab.h>
28#include "ubi.h" 29#include "ubi.h"
29 30
30#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID 31#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
diff --git a/drivers/mtd/ubi/vtbl.c b/drivers/mtd/ubi/vtbl.c
index 1afc61e7455d..cd90ff3b76b1 100644
--- a/drivers/mtd/ubi/vtbl.c
+++ b/drivers/mtd/ubi/vtbl.c
@@ -58,6 +58,7 @@
58 58
59#include <linux/crc32.h> 59#include <linux/crc32.h>
60#include <linux/err.h> 60#include <linux/err.h>
61#include <linux/slab.h>
61#include <asm/div64.h> 62#include <asm/div64.h>
62#include "ubi.h" 63#include "ubi.h"
63 64
@@ -566,6 +567,7 @@ static int init_volumes(struct ubi_device *ubi, const struct ubi_scan_info *si,
566 vol->reserved_pebs = be32_to_cpu(vtbl[i].reserved_pebs); 567 vol->reserved_pebs = be32_to_cpu(vtbl[i].reserved_pebs);
567 vol->alignment = be32_to_cpu(vtbl[i].alignment); 568 vol->alignment = be32_to_cpu(vtbl[i].alignment);
568 vol->data_pad = be32_to_cpu(vtbl[i].data_pad); 569 vol->data_pad = be32_to_cpu(vtbl[i].data_pad);
570 vol->upd_marker = vtbl[i].upd_marker;
569 vol->vol_type = vtbl[i].vol_type == UBI_VID_DYNAMIC ? 571 vol->vol_type = vtbl[i].vol_type == UBI_VID_DYNAMIC ?
570 UBI_DYNAMIC_VOLUME : UBI_STATIC_VOLUME; 572 UBI_DYNAMIC_VOLUME : UBI_STATIC_VOLUME;
571 vol->name_len = be16_to_cpu(vtbl[i].name_len); 573 vol->name_len = be16_to_cpu(vtbl[i].name_len);
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 */
1578static int paranoid_check_ec(struct ubi_device *ubi, int pnum, int ec) 1577static 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 */
1617static int paranoid_check_in_wl_tree(struct ubi_wl_entry *e, 1616static 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 */
1637static int paranoid_check_in_pq(struct ubi_device *ubi, struct ubi_wl_entry *e) 1636static 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 */