UBI: simplify debugging options
Subsystems (2)
PATCH 1/7 UBI: allocate write checking buffer on demand
In reply to Artem BityutskiyFrom: Artem Bityutskiy <[email protected]>
Instead of using pre-allocated 'ubi->dbg_peb_buf' buffer in 'ubi_dbg_check_write()', dynamically allocate it when needed. The intend is to get rid of the pre-allocated 'ubi->dbg_peb_buf' buffer completely. And the need for this arises because we want to change to dynamic debugging control instead of compile-time control, i.e., we are going to kill the CONFIG_MTD_UBI_DEBUG_PARANOID Kconfig option, which would mean that 'ubi->dbg_peb_buf' is always allocated, which would be wasteful.
Thus, we are getting rid of 'ubi->dbg_peb_buf', and this is a preparation for that.
--- drivers/mtd/ubi/io.c | 24 +++++++++++++++--------- 1 files changed, 15 insertions(+), 9 deletions(-)
drivers/mtd/ubi/io.c +15 -9
@@ -1326,16 +1326,22 @@ int ubi_dbg_check_write(struct ubi_device *ubi, const void *buf, int pnum, {int err, i;size_t read; +void *buf1;loff_t addr = (loff_t )pnum * ubi->peb_size + offset; -mutex_lock (&ubi->dbg_buf_mutex); - err = ubi->mtd->read (ubi->mtd, addr, len, &read, ubi->dbg_peb_buf); + buf1 =__vmalloc (len,GFP_KERNEL |GFP_NOFS ,PAGE_KERNEL ); +if (!buf1) { +ubi_err ("cannot allocate memory to check writes" ); +return 0 ; + } + + err = ubi->mtd->read (ubi->mtd, addr, len, &read, buf1);if (err && err != -EUCLEAN ) - goto out_unlock; + goto out_free;for (i =0 ; i < len; i++) {uint8_t c = ((uint8_t *)buf)[i]; -uint8_t c1 = ((uint8_t *)ubi->dbg_peb_buf)[i]; +uint8_t c1 = ((uint8_t *)buf1)[i];int dump_len;if (c == c1)
@@ -1352,17 +1358,17 @@ int ubi_dbg_check_write(struct ubi_device *ubi, const void *buf, int pnum,ubi_msg ("hex dump of the read buffer from %d to %d" , i, i + dump_len);print_hex_dump (KERN_DEBUG ,"" ,DUMP_PREFIX_OFFSET ,32 ,1 , - ubi->dbg_peb_buf + i, dump_len,1 ); + buf1 + i, dump_len,1 );ubi_dbg_dump_stack (); err = -EINVAL ; - goto out_unlock; + goto out_free; } -mutex_unlock (&ubi->dbg_buf_mutex); +vfree (buf1);return 0 ; -out_unlock: -mutex_unlock (&ubi->dbg_buf_mutex); +out_free: +vfree (buf1);return err; }
Signature · 1 line
1.7.2.3
PATCH 2/7 UBI: allocate erase checking buffer on demand
In reply to Artem BityutskiyFrom: Artem Bityutskiy <[email protected]>
Instead of using pre-allocated 'ubi->dbg_peb_buf' buffer in 'ubi_dbg_check_all_ff()', dynamically allocate it when needed. The intend is to get rid of the pre-allocated 'ubi->dbg_peb_buf' buffer completely. And the need for this arises because we want to change to dynamic debugging control instead of compile-time control, i.e., we are going to kill the CONFIG_MTD_UBI_DEBUG_PARANOID Kconfig option, which would mean that 'ubi->dbg_peb_buf' is always allocated, which would be wasteful.
Thus, we are getting rid of 'ubi->dbg_peb_buf', and this is a preparation for that.
--- drivers/mtd/ubi/io.c | 19 ++++++++++++------- 1 files changed, 12 insertions(+), 7 deletions(-)
drivers/mtd/ubi/io.c +12 -7
@@ -1387,35 +1387,40 @@ int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len) {size_t read;int err; +void *buf;loff_t addr = (loff_t )pnum * ubi->peb_size + offset; -mutex_lock (&ubi->dbg_buf_mutex); - err = ubi->mtd->read (ubi->mtd, addr, len, &read, ubi->dbg_peb_buf); + buf =__vmalloc (len,GFP_KERNEL |GFP_NOFS ,PAGE_KERNEL ); +if (!buf) { +ubi_err ("cannot allocate memory to check for 0xFFs" ); +return 0 ; + } + + err = ubi->mtd->read (ubi->mtd, addr, len, &read, buf);if (err && err != -EUCLEAN ) {ubi_err ("error %d while reading %d bytes from PEB %d:%d, " "read %zd bytes" , err, len, pnum, offset, read); goto error; } - err =ubi_check_pattern (ubi->dbg_peb_buf,0xFF , len); + err =ubi_check_pattern (buf,0xFF , len);if (err ==0 ) {ubi_err ("flash region at PEB %d:%d, length %d does not " "contain all 0xFF bytes" , pnum, offset, len); goto fail; } -mutex_unlock (&ubi->dbg_buf_mutex); +vfree (buf);return 0 ; fail:ubi_err ("paranoid check failed for PEB %d" , pnum);ubi_msg ("hex dump of the %d-%d region" , offset, offset + len); -print_hex_dump (KERN_DEBUG ,"" ,DUMP_PREFIX_OFFSET ,32 ,1 , - ubi->dbg_peb_buf, len,1 ); +print_hex_dump (KERN_DEBUG ,"" ,DUMP_PREFIX_OFFSET ,32 ,1 , buf, len,1 ); err = -EINVAL ; error:ubi_dbg_dump_stack (); -mutex_unlock (&ubi->dbg_buf_mutex); +vfree (buf);return err; }
Signature · 1 line
1.7.2.3
cover UBI: simplify debugging options
Hi,
these are rather trivial patches which I have been thinking to make for long time - remove the UBI debugging options from Kconfig and make them dynamically selectable via module parameters of sysfs files. This is much more flexible and simplifies the Linux configuration menu.
Artem.
PATCH 3/7 UBI: kill debugging buffer
From: Artem Bityutskiy <[email protected]>
This patch kills the 'ubi->dbg_peb_buf' debugging buffer and the associated mutex, because all users of this buffer are now gone. We are killing this buffer because we are going to switch to dynamic debugging control, just like in UBIFS, which means that CONFIG_MTD_UBI_DEBUG_PARANOID will be removed. In this case we'd end up always allocating 'ubi->dbg_peb_buf', which is rather large (128KiB or more), and this would be wasteful. Thus, we are just killing it.
--- drivers/mtd/ubi/build.c | 13 ------------- drivers/mtd/ubi/ubi.h | 6 ------ 2 files changed, 0 insertions(+), 19 deletions(-)
drivers/mtd/ubi/build.c +0 -13
@@ -939,13 +939,6 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)if (!ubi->peb_buf2) goto out_free; -#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID -mutex_init (&ubi->dbg_buf_mutex); - ubi->dbg_peb_buf =vmalloc (ubi->peb_size); -if (!ubi->dbg_peb_buf) - goto out_free; -#endif - err =attach_by_scanning (ubi);if (err) {dbg_err ("failed to attach by scanning, error %d" , err);
@@ -1011,9 +1004,6 @@ out_detach: out_free:vfree (ubi->peb_buf1);vfree (ubi->peb_buf2); -#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID -vfree (ubi->dbg_peb_buf); -#endif if (ref)put_device (&ubi->dev);else
@@ -1084,9 +1074,6 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)put_mtd_device (ubi->mtd);vfree (ubi->peb_buf1);vfree (ubi->peb_buf2); -#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID -vfree (ubi->dbg_peb_buf); -#endif ubi_msg ("mtd%d is detached from ubi%d" , ubi->mtd->index, ubi->ubi_num);put_device (&ubi->dev);return 0 ;
drivers/mtd/ubi/ubi.h +0 -6
@@ -387,8 +387,6 @@ struct ubi_wl_entry;* @peb_buf2: another buffer of PEB size used for different purposes * @buf_mutex: protects @peb_buf1 and @peb_buf2 * @ckvol_mutex: serializes static volume checking when opening -* @dbg_peb_buf: buffer of PEB size used for debugging -* @dbg_buf_mutex: protects @dbg_peb_buf */ struct ubi_device {struct cdev cdev;
@@ -470,10 +468,6 @@ struct ubi_device {void *peb_buf2;struct mutex buf_mutex;struct mutex ckvol_mutex; -#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID -void *dbg_peb_buf; -struct mutex dbg_buf_mutex; -#endif };extern struct kmem_cache *ubi_wl_entry_slab;
Signature · 1 line
1.7.2.3
PATCH 4/7 UBI: remove UBI_IO_DEBUG macro
In reply to Artem BityutskiyFrom: Artem Bityutskiy <[email protected]>
This additional little macro is used to print a bit more messages while scanning the media. However, we have the 'dbg_bld()' macro for this, so we better us 'dbg_bld()' and kill UBI_IO_DEBUG. This simplifies the code a tiny bit.
--- drivers/mtd/ubi/debug.h | 3 --- drivers/mtd/ubi/io.c | 34 ++++++++++++++++------------------ 2 files changed, 16 insertions(+), 21 deletions(-)
drivers/mtd/ubi/debug.h +0 -3
@@ -91,10 +91,8 @@ void ubi_dbg_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len);#ifdef CONFIG_MTD_UBI_DEBUG_MSG_BLD /* Initialization and build messages */ #define dbg_bld (fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) -#define UBI_IO_DEBUG 1#else #define dbg_bld (fmt, ...) ({}) -#define UBI_IO_DEBUG 0#endif #ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
@@ -177,7 +175,6 @@ static inline int ubi_dbg_is_erase_failure(void)#define ubi_dbg_dump_flash (ubi, pnum, offset, len) ({})#define ubi_dbg_print_hex_dump (l, ps, pt, r, g, b, len, a) ({}) -#define UBI_IO_DEBUG 0#define DBG_DISABLE_BGT 0#define ubi_dbg_is_bitflip () 0#define ubi_dbg_is_write_failure () 0
drivers/mtd/ubi/io.c +16 -18
@@ -783,9 +783,8 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum,if (verbose)ubi_warn ("no EC header found at PEB %d, " "only 0xFF bytes" , pnum); -else if (UBI_IO_DEBUG ) -dbg_msg ("no EC header found at PEB %d, " -"only 0xFF bytes" , pnum); +dbg_bld ("no EC header found at PEB %d, " +"only 0xFF bytes" , pnum);if (!read_err)return UBI_IO_FF ;else
@@ -800,9 +799,9 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum,ubi_warn ("bad magic number at PEB %d: %08x instead of " "%08x" , pnum, magic,UBI_EC_HDR_MAGIC );ubi_dbg_dump_ec_hdr (ec_hdr); - }else if (UBI_IO_DEBUG ) -dbg_msg ("bad magic number at PEB %d: %08x instead of " -"%08x" , pnum, magic,UBI_EC_HDR_MAGIC ); + } +dbg_bld ("bad magic number at PEB %d: %08x instead of " +"%08x" , pnum, magic,UBI_EC_HDR_MAGIC );return UBI_IO_BAD_HDR ; }
@@ -814,9 +813,9 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum,ubi_warn ("bad EC header CRC at PEB %d, calculated " "%#08x, read %#08x" , pnum, crc, hdr_crc);ubi_dbg_dump_ec_hdr (ec_hdr); - }else if (UBI_IO_DEBUG ) -dbg_msg ("bad EC header CRC at PEB %d, calculated " -"%#08x, read %#08x" , pnum, crc, hdr_crc); + } +dbg_bld ("bad EC header CRC at PEB %d, calculated " +"%#08x, read %#08x" , pnum, crc, hdr_crc);if (!read_err)return UBI_IO_BAD_HDR ;
@@ -1039,9 +1038,8 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum,if (verbose)ubi_warn ("no VID header found at PEB %d, " "only 0xFF bytes" , pnum); -else if (UBI_IO_DEBUG ) -dbg_msg ("no VID header found at PEB %d, " -"only 0xFF bytes" , pnum); +dbg_bld ("no VID header found at PEB %d, " +"only 0xFF bytes" , pnum);if (!read_err)return UBI_IO_FF ;else
@@ -1052,9 +1050,9 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum,ubi_warn ("bad magic number at PEB %d: %08x instead of " "%08x" , pnum, magic,UBI_VID_HDR_MAGIC );ubi_dbg_dump_vid_hdr (vid_hdr); - }else if (UBI_IO_DEBUG ) -dbg_msg ("bad magic number at PEB %d: %08x instead of " -"%08x" , pnum, magic,UBI_VID_HDR_MAGIC ); + } +dbg_bld ("bad magic number at PEB %d: %08x instead of " +"%08x" , pnum, magic,UBI_VID_HDR_MAGIC );return UBI_IO_BAD_HDR ; }
@@ -1066,9 +1064,9 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum,ubi_warn ("bad CRC at PEB %d, calculated %#08x, " "read %#08x" , pnum, crc, hdr_crc);ubi_dbg_dump_vid_hdr (vid_hdr); - }else if (UBI_IO_DEBUG ) -dbg_msg ("bad CRC at PEB %d, calculated %#08x, " -"read %#08x" , pnum, crc, hdr_crc); + } +dbg_bld ("bad CRC at PEB %d, calculated %#08x, " +"read %#08x" , pnum, crc, hdr_crc);if (!read_err)return UBI_IO_BAD_HDR ;else
Signature · 1 line
1.7.2.3
PATCH 5/7 UBI: make debugging messages dynamic
In reply to Artem BityutskiyFrom: Artem Bityutskiy <[email protected]>
This patch adds a possibility to dynamically select UBI debugging messages, instead of selecting them compile-time from the configuration menu. This is much more flexible, and consistent with UBIFS, and this also simplifies UBI Kconfig menu and the code.
--- drivers/mtd/ubi/Kconfig.debug | 30 ---------------------- drivers/mtd/ubi/debug.c | 8 ++++++ drivers/mtd/ubi/debug.h | 54 ++++++++++++++++++++++------------------- 3 files changed, 37 insertions(+), 55 deletions(-)
drivers/mtd/ubi/Kconfig.debug +0 -30
@@ -10,11 +10,6 @@ config MTD_UBI_DEBUG if MTD_UBI_DEBUG -config MTD_UBI_DEBUG_MSG - bool "UBI debugging messages" - help - This option enables UBI debugging messages. - config MTD_UBI_DEBUG_PARANOID bool "Extra self-checks" help
@@ -45,29 +40,4 @@ config MTD_UBI_DEBUG_EMULATE_ERASE_FAILURES This option emulates erase failures with probability 1/100. Useful for debugging and testing how UBI handlines errors. -comment "Additional UBI debugging messages" - -config MTD_UBI_DEBUG_MSG_BLD - bool "Additional UBI initialization and build messages" - help - This option enables detailed UBI initialization and device build - debugging messages. - -config MTD_UBI_DEBUG_MSG_EBA - bool "Eraseblock association unit messages" - help - This option enables debugging messages from the UBI eraseblock - association unit. - -config MTD_UBI_DEBUG_MSG_WL - bool "Wear-leveling unit messages" - help - This option enables debugging messages from the UBI wear-leveling - unit. - -config MTD_UBI_DEBUG_MSG_IO - bool "Input/output unit messages" - help - This option enables debugging messages from the UBI input/output unit. - endif # MTD_UBI_DEBUG
drivers/mtd/ubi/debug.c +8 -0
@@ -27,6 +27,14 @@#ifdef CONFIG_MTD_UBI_DEBUG #include "ubi.h" +#include <linux/module.h> +#include <linux/moduleparam.h> + +unsigned int ubi_msg_flags; + +module_param_named (debug_msgs, ubi_msg_flags, uint,S_IRUGO |S_IWUSR ); + +MODULE_PARM_DESC (debug_msgs,"Debug message type flags" );/** * ubi_dbg_dump_ec_hdr - dump an erase counter header.
drivers/mtd/ubi/debug.h +29 -25
78 lines not on this page · raw message
Signature · 1 line
1.7.2.3
PATCH 7/7 UBI: make tests modes dynamic
In reply to Artem BityutskiyFrom: Artem Bityutskiy <[email protected]>
Similarly to the debugging checks and message, make the test modes be dynamically selected via the "debug_tsts" module parameter or via the "/sys/module/ubi/parameters/debug_tsts" sysfs file. This is consistent with UBIFS as well.
And now, since all the Kconfig knobs became dynamic, we can remove the Kconfig.debug file completely.
--- drivers/mtd/ubi/Kconfig | 8 ++++++- drivers/mtd/ubi/Kconfig.debug | 37 --------------------------------- drivers/mtd/ubi/build.c | 3 +- drivers/mtd/ubi/debug.c | 3 ++ drivers/mtd/ubi/debug.h | 46 +++++++++++++++++++++++++---------------- drivers/mtd/ubi/wl.c | 4 +- 6 files changed, 41 insertions(+), 60 deletions(-) delete mode 100644 drivers/mtd/ubi/Kconfig.debug
drivers/mtd/ubi/Kconfig +7 -1
@@ -52,6 +52,12 @@ config MTD_UBI_GLUEBI work on top of UBI. Do not enable this unless you use legacy software. -source "drivers/mtd/ubi/Kconfig.debug" +config MTD_UBI_DEBUG + bool "UBI debugging" + depends on SYSFS + select DEBUG_FS + select KALLSYMS_ALL if KALLSYMS && DEBUG_KERNEL + help + This option enables UBI debugging. endif # MTD_UBI
drivers/mtd/ubi/Kconfig.debug deleted +0 -37
@@ -1,37 +0,0 @@ -comment "UBI debugging options" - -config MTD_UBI_DEBUG - bool "UBI debugging" - depends on SYSFS - select DEBUG_FS - select KALLSYMS_ALL if KALLSYMS && DEBUG_KERNEL - help - This option enables UBI debugging. - -if MTD_UBI_DEBUG - -config MTD_UBI_DEBUG_DISABLE_BGT - bool "Do not enable the UBI background thread" - help - This option switches the background thread off by default. The thread - may be also be enabled/disabled via UBI sysfs. - -config MTD_UBI_DEBUG_EMULATE_BITFLIPS - bool "Emulate flash bit-flips" - help - This option emulates bit-flips with probability 1/50, which in turn - causes scrubbing. Useful for debugging and stressing UBI. - -config MTD_UBI_DEBUG_EMULATE_WRITE_FAILURES - bool "Emulate flash write failures" - help - This option emulates write failures with probability 1/100. Useful for - debugging and testing how UBI handlines errors. - -config MTD_UBI_DEBUG_EMULATE_ERASE_FAILURES - bool "Emulate flash erase failures" - help - This option emulates erase failures with probability 1/100. Useful for - debugging and testing how UBI handlines errors. - -endif # MTD_UBI_DEBUG
drivers/mtd/ubi/build.c +1 -2
@@ -986,8 +986,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)* checks @ubi->thread_enabled. Otherwise we may fail to wake it up. */ spin_lock (&ubi->wl_lock); -if (!DBG_DISABLE_BGT ) - ubi->thread_enabled =1 ; + ubi->thread_enabled =1 ;wake_up_process (ubi->bgt_thread);spin_unlock (&ubi->wl_lock);
drivers/mtd/ubi/debug.c +3 -0
@@ -32,12 +32,15 @@unsigned int ubi_msg_flags;unsigned int ubi_chk_flags; +unsigned int ubi_tst_flags;module_param_named (debug_msgs, ubi_msg_flags, uint,S_IRUGO |S_IWUSR );module_param_named (debug_chks, ubi_chk_flags, uint,S_IRUGO |S_IWUSR ); +module_param_named (debug_tsts, ubi_chk_flags, uint,S_IRUGO |S_IWUSR );MODULE_PARM_DESC (debug_msgs,"Debug message type flags" );MODULE_PARM_DESC (debug_chks,"Debug check flags" ); +MODULE_PARM_DESC (debug_tsts,"Debug special test flags" );/** * ubi_dbg_dump_ec_hdr - dump an erase counter header.
drivers/mtd/ubi/debug.h +28 -18
79 lines not on this page · raw message
drivers/mtd/ubi/wl.c +2 -2
@@ -613,7 +613,7 @@ static void schedule_ubi_work(struct ubi_device *ubi, struct ubi_work *wrk)list_add_tail (&wrk->list, &ubi->works);ubi_assert (ubi->works_count >=0 ); ubi->works_count +=1 ; -if (ubi->thread_enabled) +if (ubi->thread_enabled && !ubi_dbg_is_bgt_disabled ())wake_up_process (ubi->bgt_thread);spin_unlock (&ubi->wl_lock); }
@@ -1364,7 +1364,7 @@ int ubi_thread(void *u)spin_lock (&ubi->wl_lock);if (list_empty (&ubi->works) || ubi->ro_mode || - !ubi->thread_enabled) { + !ubi->thread_enabled ||ubi_dbg_is_bgt_disabled ()) {set_current_state (TASK_INTERRUPTIBLE );spin_unlock (&ubi->wl_lock);schedule ();
Signature · 1 line
1.7.2.3
PATCH 6/7 UBI: make self-checks dynamic
In reply to Artem BityutskiyFrom: Artem Bityutskiy <[email protected]>
This patch adds a possibility to dynamically switch UBI self-checks on and off, instead of toggling them compile-time from the configuration menu. This is much more flexible, and consistent with UBIFS, and this also simplifies UBI Kconfig menu and the code.
This patch introduces two levels of self-checks - general, which includes all self-checks which are relatively fast, and I/O, which includes write-verify checks and erase-verify checks, which are relatively slow and involve flash I/O.
--- drivers/mtd/ubi/Kconfig.debug | 6 ------ drivers/mtd/ubi/debug.c | 3 +++ drivers/mtd/ubi/debug.h | 18 +++++++++++++----- drivers/mtd/ubi/io.c | 27 ++++++++++++++++++++++++--- drivers/mtd/ubi/scan.c | 9 ++++++--- drivers/mtd/ubi/vmt.c | 7 +++++-- drivers/mtd/ubi/vtbl.c | 9 ++++++--- drivers/mtd/ubi/wl.c | 16 +++++++++++++--- 8 files changed, 70 insertions(+), 25 deletions(-)
drivers/mtd/ubi/Kconfig.debug +0 -6
@@ -10,12 +10,6 @@ config MTD_UBI_DEBUG if MTD_UBI_DEBUG -config MTD_UBI_DEBUG_PARANOID - bool "Extra self-checks" - help - This option enables extra checks in UBI code. Note this slows UBI down - significantly. - config MTD_UBI_DEBUG_DISABLE_BGT bool "Do not enable the UBI background thread" help
drivers/mtd/ubi/debug.c +3 -0
@@ -31,10 +31,13 @@#include <linux/moduleparam.h> unsigned int ubi_msg_flags; +unsigned int ubi_chk_flags;module_param_named (debug_msgs, ubi_msg_flags, uint,S_IRUGO |S_IWUSR ); +module_param_named (debug_chks, ubi_chk_flags, uint,S_IRUGO |S_IWUSR );MODULE_PARM_DESC (debug_msgs,"Debug message type flags" ); +MODULE_PARM_DESC (debug_chks,"Debug check flags" );/** * ubi_dbg_dump_ec_hdr - dump an erase counter header.
drivers/mtd/ubi/debug.h +13 -5
@@ -99,14 +99,22 @@ enum {/* Initialization and build messages */ #define dbg_bld (fmt, ...) dbg_do_msg(UBI_MSG_BLD, fmt, ##__VA_ARGS__) -#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID +extern unsigned int ubi_chk_flags; + +/* +* Debugging check flags. +* +* UBI_CHK_GEN: general checks +* UBI_CHK_IO: check writes and erases +*/ +enum { +UBI_CHK_GEN =0x1 , +UBI_CHK_IO =0x2 , +}; +int ubi_dbg_check_all_ff (struct ubi_device *ubi,int pnum,int offset,int len);int ubi_dbg_check_write (struct ubi_device *ubi,const void *buf,int pnum,int offset,int len); -#else -#define ubi_dbg_check_all_ff (ubi, pnum, offset, len) 0 -#define ubi_dbg_check_write (ubi, buf, pnum, offset, len) 0 -#endif #ifdef CONFIG_MTD_UBI_DEBUG_DISABLE_BGT #define DBG_DISABLE_BGT 1
drivers/mtd/ubi/io.c +24 -3
@@ -91,7 +91,7 @@#include <linux/slab.h> #include "ubi.h" -#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID +#ifdef CONFIG_MTD_UBI_DEBUG static int paranoid_check_not_bad (const struct ubi_device *ubi,int pnum);static int paranoid_check_peb_ec_hdr (const struct ubi_device *ubi,int pnum); static int paranoid_check_ec_hdr(const struct ubi_device *ubi, int pnum,
@@ -1126,7 +1126,7 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum,return err; } -#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID +#ifdef CONFIG_MTD_UBI_DEBUG /** * paranoid_check_not_bad - ensure that a physical eraseblock is not bad.
@@ -1140,6 +1140,9 @@ static int paranoid_check_not_bad(const struct ubi_device *ubi, int pnum) {int err; +if (!(ubi_chk_flags &UBI_CHK_IO )) +return 0 ; + err =ubi_io_is_bad (ubi, pnum);if (!err)return err;
@@ -1164,6 +1167,9 @@ static int paranoid_check_ec_hdr(const struct ubi_device *ubi, int pnum,int err;uint32_t magic; +if (!(ubi_chk_flags &UBI_CHK_IO )) +return 0 ; + magic =be32_to_cpu (ec_hdr->magic);if (magic !=UBI_EC_HDR_MAGIC ) { ubi_err("bad magic %#08x, must be %#08x",
@@ -1199,6 +1205,9 @@ static int paranoid_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum)uint32_t crc, hdr_crc;struct ubi_ec_hdr *ec_hdr; +if (!(ubi_chk_flags &UBI_CHK_IO )) +return 0 ; + ec_hdr =kzalloc (ubi->ec_hdr_alsize,GFP_NOFS );if (!ec_hdr)return -ENOMEM ;
@@ -1240,6 +1249,9 @@ static int paranoid_check_vid_hdr(const struct ubi_device *ubi, int pnum,int err;uint32_t magic; +if (!(ubi_chk_flags &UBI_CHK_IO )) +return 0 ; + magic =be32_to_cpu (vid_hdr->magic);if (magic !=UBI_VID_HDR_MAGIC ) { ubi_err("bad VID header magic %#08x at PEB %d, must be %#08x",
@@ -1278,6 +1290,9 @@ static int paranoid_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum)struct ubi_vid_hdr *vid_hdr;void *p; +if (!(ubi_chk_flags &UBI_CHK_IO )) +return 0 ; + vid_hdr =ubi_zalloc_vid_hdr (ubi,GFP_NOFS );if (!vid_hdr)return -ENOMEM ;
@@ -1327,6 +1342,9 @@ int ubi_dbg_check_write(struct ubi_device *ubi, const void *buf, int pnum,void *buf1;loff_t addr = (loff_t )pnum * ubi->peb_size + offset; +if (!(ubi_chk_flags &UBI_CHK_IO )) +return 0 ; + buf1 =__vmalloc (len,GFP_KERNEL |GFP_NOFS ,PAGE_KERNEL );if (!buf1) {ubi_err ("cannot allocate memory to check writes" );
@@ -1388,6 +1406,9 @@ int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len)void *buf;loff_t addr = (loff_t )pnum * ubi->peb_size + offset; +if (!(ubi_chk_flags &UBI_CHK_IO )) +return 0 ; + buf =__vmalloc (len,GFP_KERNEL |GFP_NOFS ,PAGE_KERNEL );if (!buf) {ubi_err ("cannot allocate memory to check for 0xFFs" );
@@ -1422,4 +1443,4 @@ error: return err; } -#endif /* CONFIG_MTD_UBI_DEBUG_PARANOID */ +#endif /* CONFIG_MTD_UBI_DEBUG */
drivers/mtd/ubi/scan.c +6 -3
@@ -157,7 +157,7 @@#include <linux/random.h> #include "ubi.h" -#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID +#ifdef CONFIG_MTD_UBI_DEBUG static int paranoid_check_si (struct ubi_device *ubi,struct ubi_scan_info *si);#else #define paranoid_check_si (ubi, si) 0
@@ -1398,7 +1398,7 @@ void ubi_scan_destroy_si(struct ubi_scan_info *si)kfree (si); } -#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID +#ifdef CONFIG_MTD_UBI_DEBUG /** * paranoid_check_si - check the scanning information.
@@ -1416,6 +1416,9 @@ static int paranoid_check_si(struct ubi_device *ubi, struct ubi_scan_info *si)struct ubi_scan_leb *seb, *last_seb;uint8_t *buf; +if (!(ubi_chk_flags &UBI_CHK_GEN )) +return 0 ; +/* * At first, check that scanning information is OK. */
@@ -1668,4 +1671,4 @@ out: return -EINVAL; } -#endif /* CONFIG_MTD_UBI_DEBUG_PARANOID */ +#endif /* CONFIG_MTD_UBI_DEBUG */
drivers/mtd/ubi/vmt.c +5 -2
@@ -28,7 +28,7 @@#include <linux/slab.h> #include "ubi.h" -#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID +#ifdef CONFIG_MTD_UBI_DEBUG static int paranoid_check_volumes (struct ubi_device *ubi);#else #define paranoid_check_volumes (ubi) 0
@@ -711,7 +711,7 @@ void ubi_free_volume(struct ubi_device *ubi, struct ubi_volume *vol)volume_sysfs_close (vol); } -#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID +#ifdef CONFIG_MTD_UBI_DEBUG /** * paranoid_check_volume - check volume information.
@@ -876,6 +876,9 @@ static int paranoid_check_volumes(struct ubi_device *ubi) {int i, err =0 ; +if (!(ubi_chk_flags &UBI_CHK_GEN )) +return 0 ; +for (i =0 ; i < ubi->vtbl_slots; i++) { err =paranoid_check_volume (ubi, i);if (err)
drivers/mtd/ubi/vtbl.c +6 -3
@@ -62,7 +62,7 @@#include <asm/div64.h> #include "ubi.h" -#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID +#ifdef CONFIG_MTD_UBI_DEBUG static void paranoid_vtbl_check (const struct ubi_device *ubi);#else #define paranoid_vtbl_check (ubi)
@@ -870,7 +870,7 @@ out_free:return err; } -#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID +#ifdef CONFIG_MTD_UBI_DEBUG /** * paranoid_vtbl_check - check volume table.
@@ -878,10 +878,13 @@ out_free:*/ static void paranoid_vtbl_check (const struct ubi_device *ubi) { +if (!(ubi_chk_flags &UBI_CHK_GEN )) +return ; +if (vtbl_check (ubi, ubi->vtbl)) {ubi_err ("paranoid check failed" );BUG (); } } -#endif /* CONFIG_MTD_UBI_DEBUG_PARANOID */ +#endif /* CONFIG_MTD_UBI_DEBUG */
drivers/mtd/ubi/wl.c +13 -3
@@ -161,7 +161,7 @@ struct ubi_work {int torture; }; -#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID +#ifdef CONFIG_MTD_UBI_DEBUG static int paranoid_check_ec (struct ubi_device *ubi,int pnum,int ec);static int paranoid_check_in_wl_tree (struct ubi_wl_entry *e,struct rb_root *root);
@@ -1561,7 +1561,7 @@ void ubi_wl_close(struct ubi_device *ubi)kfree (ubi->lookuptbl); } -#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID +#ifdef CONFIG_MTD_UBI_DEBUG /** * paranoid_check_ec - make sure that the erase counter of a PEB is correct.
@@ -1578,6 +1578,9 @@ static int paranoid_check_ec(struct ubi_device *ubi, int pnum, int ec)long long read_ec;struct ubi_ec_hdr *ec_hdr; +if (!(ubi_chk_flags &UBI_CHK_GEN )) +return 0 ; + ec_hdr =kzalloc (ubi->ec_hdr_alsize,GFP_NOFS );if (!ec_hdr)return -ENOMEM ;
@@ -1614,6 +1617,9 @@ out_free:static int paranoid_check_in_wl_tree (struct ubi_wl_entry *e,struct rb_root *root) { +if (!(ubi_chk_flags &UBI_CHK_GEN )) +return 0 ; +if (in_wl_tree (e, root))return 0 ;
@@ -1636,6 +1642,9 @@ static int paranoid_check_in_pq(struct ubi_device *ubi, struct ubi_wl_entry *e)struct ubi_wl_entry *p;int i; +if (!(ubi_chk_flags &UBI_CHK_GEN )) +return 0 ; +for (i =0 ; i <UBI_PROT_QUEUE_LEN ; ++i)list_for_each_entry (p, &ubi->pq[i], u.list)if (p == e)
@@ -1646,4 +1655,5 @@ static int paranoid_check_in_pq(struct ubi_device *ubi, struct ubi_wl_entry *e)ubi_dbg_dump_stack (); return -EINVAL; } -#endif /* CONFIG_MTD_UBI_DEBUG_PARANOID */ + +#endif /* CONFIG_MTD_UBI_DEBUG */
Signature · 1 line
1.7.2.3