mtd_tests: Remove duplicate code and cleanups
cover mtd_tests: Remove duplicate code and cleanups
This RFC patchset moves some common code in all the tests to a common header file. Also, all the printk,PRINT_PREF are replaced with pr_info style prints. This way duplicates are eliminated and the code looks clean.
I deliberately missed out the mtd_oobtest as Brian Norris has already sent a patch for that.
All the patches are compile tested and checkpatch clean(No checkpatch warnings are introduced by the code that is added in this patch).
Vikram Narayanan(8):
mtd_tests: Refactor duplicate code
mtd_pagetest: Replace printk with pr_{info,crit}
mtd_torturetest: Replace printk with pr_{info,crit}
mtd_subpagetest: Replace printk with pr_info
mtd_stresstest: Replace printk with pr_{info,crit}
mtd_speedtest: Replace printk with pr_{info,crit}
mtd_readtest: Replace printk with pr_info
mtd_nandbiterrs: Replace msg macro with pr_info
drivers/mtd/tests/mtd_nandbiterrs.c | 97 +++++++----------- drivers/mtd/tests/mtd_oobtest.c | 31 +----- drivers/mtd/tests/mtd_pagetest.c | 191 +++++++++++++++-------------------- drivers/mtd/tests/mtd_readtest.c | 42 ++++---- drivers/mtd/tests/mtd_speedtest.c | 140 ++++++++------------------ drivers/mtd/tests/mtd_stresstest.c | 71 ++++--------- drivers/mtd/tests/mtd_subpagetest.c | 147 +++++++++++---------------- drivers/mtd/tests/mtd_tests.h | 60 +++++++++++ drivers/mtd/tests/mtd_torturetest.c | 104 +++++++------------ 9 files changed, 370 insertions(+), 513 deletions(-)
PATCH 1/8 mtd_tests: Refactor duplicate code
Move the duplicate code from all the tests to a common header.
--- drivers/mtd/tests/mtd_nandbiterrs.c | 29 ++--------------- drivers/mtd/tests/mtd_oobtest.c | 31 ++---------------- drivers/mtd/tests/mtd_pagetest.c | 39 ++++------------------ drivers/mtd/tests/mtd_speedtest.c | 60 ++-------------------------------- drivers/mtd/tests/mtd_stresstest.c | 31 ++---------------- drivers/mtd/tests/mtd_subpagetest.c | 29 +--------------- drivers/mtd/tests/mtd_tests.h | 60 +++++++++++++++++++++++++++++++++++ drivers/mtd/tests/mtd_torturetest.c | 33 +------------------ 8 files changed, 84 insertions(+), 228 deletions(-) create mode 100644 drivers/mtd/tests/mtd_tests.h
drivers/mtd/tests/mtd_nandbiterrs.c +3 -26
@@ -46,6 +46,7 @@#include <linux/err.h> #include <linux/mtd/nand.h> #include <linux/slab.h> +#include "mtd_tests.h" #define msg(FMT, VA...) pr_info("mtd_nandbiterrs: "FMT, ##VA)
@@ -97,30 +98,6 @@ static uint8_t hash(unsigned offset)return c; } -static int erase_block (void ) -{ -int err; -struct erase_info ei; -loff_t addr = eraseblock * mtd->erasesize; - -msg ("erase_block\n" ); - -memset (&ei,0 ,sizeof (struct erase_info )); - ei.mtd = mtd; - ei.addr = addr; - ei.len = mtd->erasesize; - - err =mtd_erase (mtd, &ei); -if (err || ei.state ==MTD_ERASE_FAILED ) { -msg ("error %d while erasing\n" , err); -if (!err) - err = -EIO ; -return err; - } - -return 0 ; -} -/* Writes wbuffer to page */ static int write_page (int log) {
@@ -414,7 +391,7 @@ static int __init mtd_nandbiterrs_init(void) goto exit_rbuffer; } - err =erase_block (); + err =erase_eraseblock (mtd, eraseblock);if (err) goto exit_error;
@@ -427,7 +404,7 @@ static int __init mtd_nandbiterrs_init(void) goto exit_error;/* We leave the block un-erased in case of test failure. */ - err =erase_block (); + err =erase_eraseblock (mtd, eraseblock);if (err) goto exit_error;
drivers/mtd/tests/mtd_oobtest.c +3 -28
@@ -27,6 +27,7 @@#include <linux/mtd/mtd.h> #include <linux/slab.h> #include <linux/sched.h> +#include "mtd_tests.h" #define PRINT_PREF KERN_INFO "mtd_oobtest: "
@@ -67,32 +68,6 @@ static void set_random_data(unsigned char *buf, size_t len) buf[i] =simple_rand (); } -static int erase_eraseblock (int ebnum) -{ -int err; -struct erase_info ei; -loff_t addr = ebnum * mtd->erasesize; - -memset (&ei,0 ,sizeof (struct erase_info )); - ei.mtd = mtd; - ei.addr = addr; - ei.len = mtd->erasesize; - - err =mtd_erase (mtd, &ei); -if (err) { -printk (PRINT_PREF "error %d while erasing EB %d\n" , err, ebnum); -return err; - } - -if (ei.state ==MTD_ERASE_FAILED ) { -printk (PRINT_PREF "some erase error occurred at EB %d\n" , - ebnum); -return -EIO ; - } - -return 0 ; -} -static int erase_whole_device (void ) {int err;
@@ -102,7 +77,7 @@ static int erase_whole_device(void)for (i =0 ; i < ebcnt; ++i) {if (bbt[i])continue ; - err =erase_eraseblock (i); + err =erase_eraseblock (mtd, i);if (err)return err;cond_resched ();
@@ -597,7 +572,7 @@ static int __init mtd_oobtest_init(void) errcnt +=1 ; } - err =erase_eraseblock (ebcnt -1 ); + err =erase_eraseblock (mtd, ebcnt -1 );if (err) goto out;
drivers/mtd/tests/mtd_pagetest.c +7 -32
@@ -27,6 +27,7 @@#include <linux/mtd/mtd.h> #include <linux/slab.h> #include <linux/sched.h> +#include "mtd_tests.h" #define PRINT_PREF KERN_INFO "mtd_pagetest: "
@@ -66,32 +67,6 @@ static void set_random_data(unsigned char *buf, size_t len) buf[i] =simple_rand (); } -static int erase_eraseblock (int ebnum) -{ -int err; -struct erase_info ei; -loff_t addr = ebnum * mtd->erasesize; - -memset (&ei,0 ,sizeof (struct erase_info )); - ei.mtd = mtd; - ei.addr = addr; - ei.len = mtd->erasesize; - - err =mtd_erase (mtd, &ei); -if (err) { -printk (PRINT_PREF "error %d while erasing EB %d\n" , err, ebnum); -return err; - } - -if (ei.state ==MTD_ERASE_FAILED ) { -printk (PRINT_PREF "some erase error occurred at EB %d\n" , - ebnum); -return -EIO ; - } - -return 0 ; -} -static int write_eraseblock (int ebnum) {int err =0 ;
@@ -321,7 +296,7 @@ static int erasecrosstest(void) ebnum2 -=1 ;printk (PRINT_PREF "erasing block %d\n" , ebnum); - err =erase_eraseblock (ebnum); + err =erase_eraseblock (mtd, ebnum);if (err)return err;
@@ -354,7 +329,7 @@ static int erasecrosstest(void) }printk (PRINT_PREF "erasing block %d\n" , ebnum); - err =erase_eraseblock (ebnum); + err =erase_eraseblock (mtd, ebnum);if (err)return err;
@@ -369,7 +344,7 @@ static int erasecrosstest(void) }printk (PRINT_PREF "erasing block %d\n" , ebnum2); - err =erase_eraseblock (ebnum2); + err =erase_eraseblock (mtd, ebnum2);if (err)return err;
@@ -412,7 +387,7 @@ static int erasetest(void) }printk (PRINT_PREF "erasing block %d\n" , ebnum); - err =erase_eraseblock (ebnum); + err =erase_eraseblock (mtd, ebnum);if (err)return err;
@@ -426,7 +401,7 @@ static int erasetest(void) }printk (PRINT_PREF "erasing block %d\n" , ebnum); - err =erase_eraseblock (ebnum); + err =erase_eraseblock (mtd, ebnum);if (err)return err;
@@ -557,7 +532,7 @@ static int __init mtd_pagetest_init(void)for (i =0 ; i < ebcnt; ++i) {if (bbt[i])continue ; - err =erase_eraseblock (i); + err =erase_eraseblock (mtd, i);if (err) goto out;cond_resched ();
drivers/mtd/tests/mtd_speedtest.c +4 -56
90 lines not on this page · raw message
drivers/mtd/tests/mtd_stresstest.c +3 -28
@@ -28,6 +28,7 @@#include <linux/sched.h> #include <linux/vmalloc.h> #include <linux/random.h> +#include "mtd_tests.h" #define PRINT_PREF KERN_INFO "mtd_stresstest: "
@@ -81,32 +82,6 @@ static int rand_len(int offs)return len; } -static int erase_eraseblock (int ebnum) -{ -int err; -struct erase_info ei; -loff_t addr = ebnum * mtd->erasesize; - -memset (&ei,0 ,sizeof (struct erase_info )); - ei.mtd = mtd; - ei.addr = addr; - ei.len = mtd->erasesize; - - err =mtd_erase (mtd, &ei); -if (unlikely (err)) { -printk (PRINT_PREF "error %d while erasing EB %d\n" , err, ebnum); -return err; - } - -if (unlikely (ei.state ==MTD_ERASE_FAILED )) { -printk (PRINT_PREF "some erase error occurred at EB %d\n" , - ebnum); -return -EIO ; - } - -return 0 ; -} -static int is_block_bad (int ebnum) {loff_t addr = ebnum * mtd->erasesize;
@@ -154,7 +129,7 @@ static int do_write(void) offs = offsets[eb];if (offs >= mtd->erasesize) { - err =erase_eraseblock (eb); + err =erase_eraseblock (mtd, eb);if (err)return err; offs = offsets[eb] =0 ;
@@ -165,7 +140,7 @@ static int do_write(void)if (bbt[eb +1 ]) len = mtd->erasesize - offs;else { - err =erase_eraseblock (eb +1 ); + err =erase_eraseblock (mtd, eb +1 );if (err)return err; offsets[eb +1 ] =0 ;
drivers/mtd/tests/mtd_subpagetest.c +2 -27
@@ -26,6 +26,7 @@#include <linux/mtd/mtd.h> #include <linux/slab.h> #include <linux/sched.h> +#include "mtd_tests.h" #define PRINT_PREF KERN_INFO "mtd_subpagetest: "
@@ -69,32 +70,6 @@ static inline void clear_data(unsigned char *buf, size_t len)memset (buf,0 , len); } -static int erase_eraseblock (int ebnum) -{ -int err; -struct erase_info ei; -loff_t addr = ebnum * mtd->erasesize; - -memset (&ei,0 ,sizeof (struct erase_info )); - ei.mtd = mtd; - ei.addr = addr; - ei.len = mtd->erasesize; - - err =mtd_erase (mtd, &ei); -if (err) { -printk (PRINT_PREF "error %d while erasing EB %d\n" , err, ebnum); -return err; - } - -if (ei.state ==MTD_ERASE_FAILED ) { -printk (PRINT_PREF "some erase error occurred at EB %d\n" , - ebnum); -return -EIO ; - } - -return 0 ; -} -static int erase_whole_device (void ) {int err;
@@ -104,7 +79,7 @@ static int erase_whole_device(void)for (i =0 ; i < ebcnt; ++i) {if (bbt[i])continue ; - err =erase_eraseblock (i); + err =erase_eraseblock (mtd, i);if (err)return err;cond_resched ();
drivers/mtd/tests/mtd_tests.h new file +60 -0
60 lines not on this page · raw message
drivers/mtd/tests/mtd_torturetest.c +2 -31
@@ -30,7 +30,7 @@#include <linux/mtd/mtd.h> #include <linux/slab.h> #include <linux/sched.h> - +#include "mtd_tests.h" #define PRINT_PREF KERN_INFO "mtd_torturetest: "#define RETRIES 3
@@ -92,35 +92,6 @@ static inline void stop_timing(void) }/* -* Erase eraseblock number @ebnum. -*/ -static inline int erase_eraseblock (int ebnum) -{ -int err; -struct erase_info ei; -loff_t addr = ebnum * mtd->erasesize; - -memset (&ei,0 ,sizeof (struct erase_info )); - ei.mtd = mtd; - ei.addr = addr; - ei.len = mtd->erasesize; - - err =mtd_erase (mtd, &ei); -if (err) { -printk (PRINT_PREF "error %d while erasing EB %d\n" , err, ebnum); -return err; - } - -if (ei.state ==MTD_ERASE_FAILED ) { -printk (PRINT_PREF "some erase error occurred at EB %d\n" , - ebnum); -return -EIO ; - } - -return 0 ; -} - -/* * Check that the contents of eraseblock number @enbum is equivalent to the * @buf buffer. */
@@ -316,7 +287,7 @@ static int __init tort_init(void)for (i = eb; i < eb + ebcnt; i++) {if (bad_ebs[i - eb])continue ; - err =erase_eraseblock (i); + err =erase_eraseblock (mtd, i);if (err) goto out;cond_resched ();
Signature · 1 line
1.7.4.1
PATCH 2/8 mtd_pagetest: Replace printk with pr_{info,crit}
In reply to Vikram NarayananRemove PRINT_PREF macro and use pr_fmt to add the prefix
--- drivers/mtd/tests/mtd_pagetest.c | 152 +++++++++++++++++++------------------- 1 files changed, 76 insertions(+), 76 deletions(-)
drivers/mtd/tests/mtd_pagetest.c +76 -76
@@ -19,6 +19,8 @@* Author: Adrian Hunter <[email protected]> */ +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt +#include <asm/div64.h> #include <linux/init.h> #include <linux/module.h>
@@ -29,8 +31,6 @@#include <linux/sched.h> #include "mtd_tests.h" -#define PRINT_PREF KERN_INFO "mtd_pagetest: " -static int dev = -EINVAL ;module_param (dev, int,S_IRUGO );MODULE_PARM_DESC (dev,"MTD device number to use" );
@@ -77,7 +77,7 @@ static int write_eraseblock(int ebnum)cond_resched (); err =mtd_write (mtd, addr, mtd->erasesize, &written, writebuf);if (err || written != mtd->erasesize) -printk (PRINT_PREF "error: write failed at %#llx\n" , +pr_info ("error: write failed at %#llx\n" , (long long )addr);return err;
@@ -106,7 +106,7 @@ static int verify_eraseblock(int ebnum)if (mtd_is_bitflip (err)) err =0 ;if (err || read != bufsize) { -printk (PRINT_PREF "error: read failed at %#llx\n" , +pr_info ("error: read failed at %#llx\n" , (long long )addr0);return err; }
@@ -114,7 +114,7 @@ static int verify_eraseblock(int ebnum)if (mtd_is_bitflip (err)) err =0 ;if (err || read != bufsize) { -printk (PRINT_PREF "error: read failed at %#llx\n" , +pr_info ("error: read failed at %#llx\n" , (long long )(addrn - bufsize));return err; }
@@ -123,12 +123,12 @@ static int verify_eraseblock(int ebnum)if (mtd_is_bitflip (err)) err =0 ;if (err || read != bufsize) { -printk (PRINT_PREF "error: read failed at %#llx\n" , +pr_info ("error: read failed at %#llx\n" , (long long )addr);break ; }if (memcmp (twopages, writebuf + (j * pgsize), bufsize)) { -printk (PRINT_PREF "error: verify failed at %#llx\n" , +pr_info ("error: verify failed at %#llx\n" , (long long )addr); errcnt +=1 ; }
@@ -141,7 +141,7 @@ static int verify_eraseblock(int ebnum)if (mtd_is_bitflip (err)) err =0 ;if (err || read != bufsize) { -printk (PRINT_PREF "error: read failed at %#llx\n" , +pr_info ("error: read failed at %#llx\n" , (long long )addr0);return err; }
@@ -149,7 +149,7 @@ static int verify_eraseblock(int ebnum)if (mtd_is_bitflip (err)) err =0 ;if (err || read != bufsize) { -printk (PRINT_PREF "error: read failed at %#llx\n" , +pr_info ("error: read failed at %#llx\n" , (long long )(addrn - bufsize));return err; }
@@ -158,14 +158,14 @@ static int verify_eraseblock(int ebnum)if (mtd_is_bitflip (err)) err =0 ;if (err || read != bufsize) { -printk (PRINT_PREF "error: read failed at %#llx\n" , +pr_info ("error: read failed at %#llx\n" , (long long )addr);return err; }memcpy (boundary, writebuf + mtd->erasesize - pgsize, pgsize);set_random_data (boundary + pgsize, pgsize);if (memcmp (twopages, boundary, bufsize)) { -printk (PRINT_PREF "error: verify failed at %#llx\n" , +pr_info ("error: verify failed at %#llx\n" , (long long )addr); errcnt +=1 ; }
@@ -181,10 +181,10 @@ static int crosstest(void)loff_t addr, addr0, addrn;unsigned char *pp1, *pp2, *pp3, *pp4; -printk (PRINT_PREF "crosstest\n" ); +pr_info ("crosstest\n" ); pp1 =kmalloc (pgsize *4 ,GFP_KERNEL );if (!pp1) { -printk (PRINT_PREF "error: cannot allocate memory\n" ); +pr_info ("error: cannot allocate memory\n" );return -ENOMEM ; } pp2 = pp1 + pgsize;
@@ -206,7 +206,7 @@ static int crosstest(void)if (mtd_is_bitflip (err)) err =0 ;if (err || read != pgsize) { -printk (PRINT_PREF "error: read failed at %#llx\n" , +pr_info ("error: read failed at %#llx\n" , (long long )addr);kfree (pp1);return err;
@@ -218,7 +218,7 @@ static int crosstest(void)if (mtd_is_bitflip (err)) err =0 ;if (err || read != pgsize) { -printk (PRINT_PREF "error: read failed at %#llx\n" , +pr_info ("error: read failed at %#llx\n" , (long long )addr);kfree (pp1);return err;
@@ -226,12 +226,12 @@ static int crosstest(void)/* Read first page to pp2 */ addr = addr0; -printk (PRINT_PREF "reading page at %#llx\n" , (long long )addr); +pr_info ("reading page at %#llx\n" , (long long )addr); err =mtd_read (mtd, addr, pgsize, &read, pp2);if (mtd_is_bitflip (err)) err =0 ;if (err || read != pgsize) { -printk (PRINT_PREF "error: read failed at %#llx\n" , +pr_info ("error: read failed at %#llx\n" , (long long )addr);kfree (pp1);return err;
@@ -239,12 +239,12 @@ static int crosstest(void)/* Read last page to pp3 */ addr = addrn - pgsize; -printk (PRINT_PREF "reading page at %#llx\n" , (long long )addr); +pr_info ("reading page at %#llx\n" , (long long )addr); err =mtd_read (mtd, addr, pgsize, &read, pp3);if (mtd_is_bitflip (err)) err =0 ;if (err || read != pgsize) { -printk (PRINT_PREF "error: read failed at %#llx\n" , +pr_info ("error: read failed at %#llx\n" , (long long )addr);kfree (pp1);return err;
@@ -252,25 +252,25 @@ static int crosstest(void)/* Read first page again to pp4 */ addr = addr0; -printk (PRINT_PREF "reading page at %#llx\n" , (long long )addr); +pr_info ("reading page at %#llx\n" , (long long )addr); err =mtd_read (mtd, addr, pgsize, &read, pp4);if (mtd_is_bitflip (err)) err =0 ;if (err || read != pgsize) { -printk (PRINT_PREF "error: read failed at %#llx\n" , +pr_info ("error: read failed at %#llx\n" , (long long )addr);kfree (pp1);return err; }/* pp2 and pp4 should be the same */ -printk (PRINT_PREF "verifying pages read at %#llx match\n" , +pr_info ("verifying pages read at %#llx match\n" , (long long )addr0);if (memcmp (pp2, pp4, pgsize)) { -printk (PRINT_PREF "verify failed!\n" ); +pr_info ("verify failed!\n" ); errcnt +=1 ; }else if (!err) -printk (PRINT_PREF "crosstest ok\n" ); +pr_info ("crosstest ok\n" );kfree (pp1);return err; }
@@ -282,7 +282,7 @@ static int erasecrosstest(void)loff_t addr0;char *readbuf = twopages; -printk (PRINT_PREF "erasecrosstest\n" ); +pr_info ("erasecrosstest\n" ); ebnum =0 ; addr0 =0 ;
@@ -295,79 +295,79 @@ static int erasecrosstest(void)while (ebnum2 && bbt[ebnum2]) ebnum2 -=1 ; -printk (PRINT_PREF "erasing block %d\n" , ebnum); +pr_info ("erasing block %d\n" , ebnum); err =erase_eraseblock (mtd, ebnum);if (err)return err; -printk (PRINT_PREF "writing 1st page of block %d\n" , ebnum); +pr_info ("writing 1st page of block %d\n" , ebnum);set_random_data (writebuf, pgsize);strcpy (writebuf,"There is no data like this!" ); err =mtd_write (mtd, addr0, pgsize, &written, writebuf);if (err || written != pgsize) { -printk (PRINT_PREF "error: write failed at %#llx\n" , +pr_info ("error: write failed at %#llx\n" , (long long )addr0);return err ? err :-1 ; } -printk (PRINT_PREF "reading 1st page of block %d\n" , ebnum); +pr_info ("reading 1st page of block %d\n" , ebnum);memset (readbuf,0 , pgsize); err =mtd_read (mtd, addr0, pgsize, &read, readbuf);if (mtd_is_bitflip (err)) err =0 ;if (err || read != pgsize) { -printk (PRINT_PREF "error: read failed at %#llx\n" , +pr_info ("error: read failed at %#llx\n" , (long long )addr0);return err ? err :-1 ; } -printk (PRINT_PREF "verifying 1st page of block %d\n" , ebnum); +pr_info ("verifying 1st page of block %d\n" , ebnum);if (memcmp (writebuf, readbuf, pgsize)) { -printk (PRINT_PREF "verify failed!\n" ); +pr_info ("verify failed!\n" ); errcnt +=1 ;return -1 ; } -printk (PRINT_PREF "erasing block %d\n" , ebnum); +pr_info ("erasing block %d\n" , ebnum); err =erase_eraseblock (mtd, ebnum);if (err)return err; -printk (PRINT_PREF "writing 1st page of block %d\n" , ebnum); +pr_info ("writing 1st page of block %d\n" , ebnum);set_random_data (writebuf, pgsize);strcpy (writebuf,"There is no data like this!" ); err =mtd_write (mtd, addr0, pgsize, &written, writebuf);if (err || written != pgsize) { -printk (PRINT_PREF "error: write failed at %#llx\n" , +pr_info ("error: write failed at %#llx\n" , (long long )addr0);return err ? err :-1 ; } -printk (PRINT_PREF "erasing block %d\n" , ebnum2); +pr_info ("erasing block %d\n" , ebnum2); err =erase_eraseblock (mtd, ebnum2);if (err)return err; -printk (PRINT_PREF "reading 1st page of block %d\n" , ebnum); +pr_info ("reading 1st page of block %d\n" , ebnum);memset (readbuf,0 , pgsize); err =mtd_read (mtd, addr0, pgsize, &read, readbuf);if (mtd_is_bitflip (err)) err =0 ;if (err || read != pgsize) { -printk (PRINT_PREF "error: read failed at %#llx\n" , +pr_info ("error: read failed at %#llx\n" , (long long )addr0);return err ? err :-1 ; } -printk (PRINT_PREF "verifying 1st page of block %d\n" , ebnum); +pr_info ("verifying 1st page of block %d\n" , ebnum);if (memcmp (writebuf, readbuf, pgsize)) { -printk (PRINT_PREF "verify failed!\n" ); +pr_info ("verify failed!\n" ); errcnt +=1 ;return -1 ; }if (!err) -printk (PRINT_PREF "erasecrosstest ok\n" ); +pr_info ("erasecrosstest ok\n" );return err; }
@@ -377,7 +377,7 @@ static int erasetest(void)int err =0 , i, ebnum, ok =1 ;loff_t addr0; -printk (PRINT_PREF "erasetest\n" ); +pr_info ("erasetest\n" ); ebnum =0 ; addr0 =0 ;
@@ -386,40 +386,40 @@ static int erasetest(void) ebnum +=1 ; } -printk (PRINT_PREF "erasing block %d\n" , ebnum); +pr_info ("erasing block %d\n" , ebnum); err =erase_eraseblock (mtd, ebnum);if (err)return err; -printk (PRINT_PREF "writing 1st page of block %d\n" , ebnum); +pr_info ("writing 1st page of block %d\n" , ebnum);set_random_data (writebuf, pgsize); err =mtd_write (mtd, addr0, pgsize, &written, writebuf);if (err || written != pgsize) { -printk (PRINT_PREF "error: write failed at %#llx\n" , +pr_info ("error: write failed at %#llx\n" , (long long )addr0);return err ? err :-1 ; } -printk (PRINT_PREF "erasing block %d\n" , ebnum); +pr_info ("erasing block %d\n" , ebnum); err =erase_eraseblock (mtd, ebnum);if (err)return err; -printk (PRINT_PREF "reading 1st page of block %d\n" , ebnum); +pr_info ("reading 1st page of block %d\n" , ebnum); err =mtd_read (mtd, addr0, pgsize, &read, twopages);if (mtd_is_bitflip (err)) err =0 ;if (err || read != pgsize) { -printk (PRINT_PREF "error: read failed at %#llx\n" , +pr_info ("error: read failed at %#llx\n" , (long long )addr0);return err ? err :-1 ; } -printk (PRINT_PREF "verifying 1st page of block %d is all 0xff\n" , +pr_info ("verifying 1st page of block %d is all 0xff\n" , ebnum);for (i =0 ; i < pgsize; ++i)if (twopages[i] !=0xff ) { -printk (PRINT_PREF "verifying all 0xff failed at %d\n" , +pr_info ("verifying all 0xff failed at %d\n" , i); errcnt +=1 ; ok =0 ;
@@ -427,7 +427,7 @@ static int erasetest(void) }if (ok && !err) -printk (PRINT_PREF "erasetest ok\n" ); +pr_info ("erasetest ok\n" );return err; }
@@ -439,7 +439,7 @@ static int is_block_bad(int ebnum) ret =mtd_block_isbad (mtd, addr);if (ret) -printk (PRINT_PREF "block %d is bad\n" , ebnum); +pr_info ("block %d is bad\n" , ebnum);return ret; }
@@ -449,18 +449,18 @@ static int scan_for_bad_eraseblocks(void) bbt =kzalloc (ebcnt,GFP_KERNEL );if (!bbt) { -printk (PRINT_PREF "error: cannot allocate memory\n" ); +pr_info ("error: cannot allocate memory\n" );return -ENOMEM ; } -printk (PRINT_PREF "scanning for bad eraseblocks\n" ); +pr_info ("scanning for bad eraseblocks\n" );for (i =0 ; i < ebcnt; ++i) { bbt[i] =is_block_bad (i) ?1 :0 ;if (bbt[i]) bad +=1 ;cond_resched (); } -printk (PRINT_PREF "scanned %d eraseblocks, %d are bad\n" , i, bad); +pr_info ("scanned %d eraseblocks, %d are bad\n" , i, bad);return 0 ; }
@@ -470,26 +470,26 @@ static int __init mtd_pagetest_init(void)uint64_t tmp;uint32_t i; -printk (KERN_INFO "\n" ); -printk (KERN_INFO "=================================================\n" ); + +printk (KERN_INFO "\n=================================================\n" );if (dev <0 ) { -printk (PRINT_PREF "Please specify a valid mtd-device via module paramter\n" ); -printk (KERN_CRIT "CAREFUL: This test wipes all data on the specified MTD device!\n" ); +pr_info ("Please specify a valid mtd-device via module paramter\n" ); +pr_crit ("CAREFUL: This test wipes all data on the specified MTD device!\n" );return -EINVAL ; } -printk (PRINT_PREF "MTD device: %d\n" , dev); +pr_info ("MTD device: %d\n" , dev); mtd =get_mtd_device (NULL , dev);if (IS_ERR (mtd)) { err =PTR_ERR (mtd); -printk (PRINT_PREF "error: cannot get MTD device\n" ); +pr_info ("error: cannot get MTD device\n" );return err; }if (mtd->type !=MTD_NANDFLASH ) { -printk (PRINT_PREF "this test requires NAND flash\n" ); +pr_info ("this test requires NAND flash\n" ); goto out; }
@@ -499,7 +499,7 @@ static int __init mtd_pagetest_init(void) pgcnt = mtd->erasesize / mtd->writesize; pgsize = mtd->writesize; - printk(PRINT_PREF "MTD device size %llu, eraseblock size %u, " + pr_info("MTD device size %llu, eraseblock size %u, " "page size %u, count of eraseblocks %u, pages per " "eraseblock %u, OOB size %u\n", (unsigned long long)mtd->size, mtd->erasesize,
@@ -509,17 +509,17 @@ static int __init mtd_pagetest_init(void) bufsize = pgsize *2 ; writebuf =kmalloc (mtd->erasesize,GFP_KERNEL );if (!writebuf) { -printk (PRINT_PREF "error: cannot allocate memory\n" ); +pr_info ("error: cannot allocate memory\n" ); goto out; } twopages =kmalloc (bufsize,GFP_KERNEL );if (!twopages) { -printk (PRINT_PREF "error: cannot allocate memory\n" ); +pr_info ("error: cannot allocate memory\n" ); goto out; } boundary =kmalloc (bufsize,GFP_KERNEL );if (!boundary) { -printk (PRINT_PREF "error: cannot allocate memory\n" ); +pr_info ("error: cannot allocate memory\n" ); goto out; }
@@ -528,7 +528,7 @@ static int __init mtd_pagetest_init(void) goto out;/* Erase all eraseblocks */ -printk (PRINT_PREF "erasing whole device\n" ); +pr_info ("erasing whole device\n" );for (i =0 ; i < ebcnt; ++i) {if (bbt[i])continue ;
@@ -537,11 +537,11 @@ static int __init mtd_pagetest_init(void) goto out;cond_resched (); } -printk (PRINT_PREF "erased %u eraseblocks\n" , i); +pr_info ("erased %u eraseblocks\n" , i);/* Write all eraseblocks */ simple_srand (1 ); -printk (PRINT_PREF "writing whole device\n" ); +pr_info ("writing whole device\n" );for (i =0 ; i < ebcnt; ++i) {if (bbt[i])continue ;
@@ -549,14 +549,14 @@ static int __init mtd_pagetest_init(void)if (err) goto out;if (i %256 ==0 ) -printk (PRINT_PREF "written up to eraseblock %u\n" , i); +pr_info ("written up to eraseblock %u\n" , i);cond_resched (); } -printk (PRINT_PREF "written %u eraseblocks\n" , i); +pr_info ("written %u eraseblocks\n" , i);/* Check all eraseblocks */ simple_srand (1 ); -printk (PRINT_PREF "verifying all eraseblocks\n" ); +pr_info ("verifying all eraseblocks\n" );for (i =0 ; i < ebcnt; ++i) {if (bbt[i])continue ;
@@ -564,10 +564,10 @@ static int __init mtd_pagetest_init(void)if (err) goto out;if (i %256 ==0 ) -printk (PRINT_PREF "verified up to eraseblock %u\n" , i); +pr_info ("verified up to eraseblock %u\n" , i);cond_resched (); } -printk (PRINT_PREF "verified %u eraseblocks\n" , i); +pr_info ("verified %u eraseblocks\n" , i); err =crosstest ();if (err)
@@ -581,7 +581,7 @@ static int __init mtd_pagetest_init(void)if (err) goto out; -printk (PRINT_PREF "finished with %d errors\n" , errcnt); +pr_info ("finished with %d errors\n" , errcnt); out:kfree (bbt);
@@ -590,7 +590,7 @@ out:kfree (writebuf);put_mtd_device (mtd);if (err) -printk (PRINT_PREF "error %d occurred\n" , err); +pr_info ("error %d occurred\n" , err);printk (KERN_INFO "=================================================\n" );return err; }
Signature · 1 line
1.7.4.1
PATCH 3/8 mtd_torturetest: Replace printk with pr_{info,crit}
In reply to Vikram NarayananRemove PRINT_PREF macro and use pr_fmt to add the prefix
--- drivers/mtd/tests/mtd_torturetest.c | 73 ++++++++++++++++++----------------- 1 files changed, 37 insertions(+), 36 deletions(-)
drivers/mtd/tests/mtd_torturetest.c +37 -36
@@ -23,6 +23,8 @@* damage caused by this program. */ +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt +#include <linux/init.h> #include <linux/module.h> #include <linux/moduleparam.h>
@@ -31,7 +33,7 @@#include <linux/slab.h> #include <linux/sched.h> #include "mtd_tests.h" -#define PRINT_PREF KERN_INFO "mtd_torturetest: " +#define RETRIES 3static int eb =8 ;
@@ -110,40 +112,40 @@ static inline int check_eraseblock(int ebnum, unsigned char *buf) retry: err =mtd_read (mtd, addr, len, &read, check_buf);if (mtd_is_bitflip (err)) -printk (PRINT_PREF "single bit flip occurred at EB %d " +pr_info ("single bit flip occurred at EB %d " "MTD reported that it was fixed.\n" , ebnum);else if (err) { -printk (PRINT_PREF "error %d while reading EB %d, " +pr_info ("error %d while reading EB %d, " "read %zd\n" , err, ebnum, read);return err; }if (read != len) { -printk (PRINT_PREF "failed to read %zd bytes from EB %d, " +pr_info ("failed to read %zd bytes from EB %d, " "read only %zd, but no error reported\n" , len, ebnum, read);return -EIO ; }if (memcmp (buf, check_buf, len)) { -printk (PRINT_PREF "read wrong data from EB %d\n" , ebnum); +pr_info ("read wrong data from EB %d\n" , ebnum);report_corrupt (check_buf, buf);if (retries++ <RETRIES ) {/* Try read again */ yield (); -printk (PRINT_PREF "re-try reading data from EB %d\n" , +pr_info ("re-try reading data from EB %d\n" , ebnum); goto retry; }else { -printk (PRINT_PREF "retried %d times, still errors, " +pr_info ("retried %d times, still errors, " "give-up\n" ,RETRIES );return -EINVAL ; } }if (retries !=0 ) -printk (PRINT_PREF "only attempt number %d was OK (!!!)\n" , +pr_info ("only attempt number %d was OK (!!!)\n" , retries);return 0 ;
@@ -162,12 +164,12 @@ static inline int write_pattern(int ebnum, void *buf) } err =mtd_write (mtd, addr, len, &written, buf);if (err) { -printk (PRINT_PREF "error %d while writing EB %d, written %zd" +pr_info ("error %d while writing EB %d, written %zd" " bytes\n" , err, ebnum, written);return err; }if (written != len) { -printk (PRINT_PREF "written only %zd bytes of %zd, but no error" +pr_info ("written only %zd bytes of %zd, but no error" " reported\n" , written, len);return -EIO ; }
@@ -180,66 +182,65 @@ static int __init tort_init(void)int err =0 , i, infinite = !cycles_count;int bad_ebs[ebcnt]; -printk (KERN_INFO "\n" ); -printk (KERN_INFO "=================================================\n" ); -printk (PRINT_PREF "Warning: this program is trying to wear out your " +printk (KERN_INFO "\n=================================================\n" ); +pr_info ("Warning: this program is trying to wear out your " "flash, stop it if this is not wanted.\n" );if (dev <0 ) { -printk (PRINT_PREF "Please specify a valid mtd-device via module paramter\n" ); -printk (KERN_CRIT "CAREFUL: This test wipes all data on the specified MTD device!\n" ); +pr_info ("Please specify a valid mtd-device via module paramter\n" ); +pr_crit ("CAREFUL: This test wipes all data on the specified MTD device!\n" );return -EINVAL ; } -printk (PRINT_PREF "MTD device: %d\n" , dev); -printk (PRINT_PREF "torture %d eraseblocks (%d-%d) of mtd%d\n" , +pr_info ("MTD device: %d\n" , dev); +pr_info ("torture %d eraseblocks (%d-%d) of mtd%d\n" , ebcnt, eb, eb + ebcnt -1 , dev);if (pgcnt) -printk (PRINT_PREF "torturing just %d pages per eraseblock\n" , +pr_info ("torturing just %d pages per eraseblock\n" , pgcnt); -printk (PRINT_PREF "write verify %s\n" , check ?"enabled" :"disabled" ); +pr_info ("write verify %s\n" , check ?"enabled" :"disabled" ); mtd =get_mtd_device (NULL , dev);if (IS_ERR (mtd)) { err =PTR_ERR (mtd); -printk (PRINT_PREF "error: cannot get MTD device\n" ); +pr_info ("error: cannot get MTD device\n" );return err; }if (mtd->writesize ==1 ) { -printk (PRINT_PREF "not NAND flash, assume page size is 512 " +pr_info ("not NAND flash, assume page size is 512 " "bytes.\n" ); pgsize =512 ; }else pgsize = mtd->writesize;if (pgcnt && (pgcnt > mtd->erasesize / pgsize || pgcnt <0 )) { -printk (PRINT_PREF "error: invalid pgcnt value %d\n" , pgcnt); +pr_info ("error: invalid pgcnt value %d\n" , pgcnt); goto out_mtd; } err = -ENOMEM ; patt_5A5 =kmalloc (mtd->erasesize,GFP_KERNEL );if (!patt_5A5) { -printk (PRINT_PREF "error: cannot allocate memory\n" ); +pr_info ("error: cannot allocate memory\n" ); goto out_mtd; } patt_A5A =kmalloc (mtd->erasesize,GFP_KERNEL );if (!patt_A5A) { -printk (PRINT_PREF "error: cannot allocate memory\n" ); +pr_info ("error: cannot allocate memory\n" ); goto out_patt_5A5; } patt_FF =kmalloc (mtd->erasesize,GFP_KERNEL );if (!patt_FF) { -printk (PRINT_PREF "error: cannot allocate memory\n" ); +pr_info ("error: cannot allocate memory\n" ); goto out_patt_A5A; } check_buf =kmalloc (mtd->erasesize,GFP_KERNEL );if (!check_buf) { -printk (PRINT_PREF "error: cannot allocate memory\n" ); +pr_info ("error: cannot allocate memory\n" ); goto out_patt_FF; }
@@ -266,13 +267,13 @@ static int __init tort_init(void) err =mtd_block_isbad (mtd, (loff_t )i * mtd->erasesize);if (err <0 ) { -printk (PRINT_PREF "block_isbad() returned %d " +pr_info ("block_isbad() returned %d " "for EB %d\n" , err, i); goto out; }if (err) { -printk ("EB %d is bad. Skip it.\n" , i); +pr_info ("EB %d is bad. Skip it.\n" , i); bad_ebs[i - eb] =1 ; } }
@@ -300,7 +301,7 @@ static int __init tort_init(void)continue ; err =check_eraseblock (i, patt_FF);if (err) { -printk (PRINT_PREF "verify failed" +pr_info ("verify failed" " for 0xFF... pattern\n" ); goto out; }
@@ -333,7 +334,7 @@ static int __init tort_init(void) patt = patt_A5A; err =check_eraseblock (i, patt);if (err) { -printk (PRINT_PREF "verify failed for %s" +pr_info ("verify failed for %s" " pattern\n" , ((eb + erase_cycles) &1 ) ?"0x55AA55..." :"0xAA55AA..." );
@@ -351,7 +352,7 @@ static int __init tort_init(void)stop_timing (); ms = (finish.tv_sec - start.tv_sec) *1000 + (finish.tv_usec - start.tv_usec) /1000 ; -printk (PRINT_PREF "%08u erase cycles done, took %lu " +pr_info ("%08u erase cycles done, took %lu " "milliseconds (%lu seconds)\n" , erase_cycles, ms, ms /1000 );start_timing ();
@@ -362,7 +363,7 @@ static int __init tort_init(void) } out: -printk (PRINT_PREF "finished after %u erase cycles\n" , +pr_info ("finished after %u erase cycles\n" , erase_cycles);kfree (check_buf); out_patt_FF:
@@ -374,7 +375,7 @@ out_patt_5A5: out_mtd:put_mtd_device (mtd);if (err) -printk (PRINT_PREF "error %d occurred during torturing\n" , err); +pr_info ("error %d occurred during torturing\n" , err);printk (KERN_INFO "=================================================\n" );return err; }
@@ -412,9 +413,9 @@ static void report_corrupt(unsigned char *read, unsigned char *written) &bits) >= 0) pages++; -printk (PRINT_PREF "verify fails on %d pages, %d bytes/%d bits\n" , +pr_info ("verify fails on %d pages, %d bytes/%d bits\n" , pages, bytes, bits); -printk (PRINT_PREF "The following is a list of all differences between" +pr_info ("The following is a list of all differences between" " what was read from flash and what was expected\n" );for (i =0 ; i < check_len; i += pgsize) {
@@ -428,7 +429,7 @@ static void report_corrupt(unsigned char *read, unsigned char *written)printk ("-------------------------------------------------------" "----------------------------------\n" ); -printk (PRINT_PREF "Page %zd has %d bytes/%d bits failing verify," +pr_info ("Page %zd has %d bytes/%d bits failing verify," " starting at offset 0x%x\n" , (mtd->erasesize - check_len + i) / pgsize, bytes, bits, first);
Signature · 1 line
1.7.4.1
PATCH 4/8 mtd_subpagetest: Replace printk with pr_info
In reply to Vikram NarayananRemove PRINT_PREF macro and use pr_fmt to add the prefix
--- drivers/mtd/tests/mtd_subpagetest.c | 118 +++++++++++++++++----------------- 1 files changed, 59 insertions(+), 59 deletions(-)
drivers/mtd/tests/mtd_subpagetest.c +59 -59
@@ -19,6 +19,8 @@* */ +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt +#include <linux/init.h> #include <linux/module.h> #include <linux/moduleparam.h>
@@ -28,8 +30,6 @@#include <linux/sched.h> #include "mtd_tests.h" -#define PRINT_PREF KERN_INFO "mtd_subpagetest: " -static int dev = -EINVAL ;module_param (dev, int,S_IRUGO );MODULE_PARM_DESC (dev,"MTD device number to use" );
@@ -75,7 +75,7 @@ static int erase_whole_device(void)int err;unsigned int i; -printk (PRINT_PREF "erasing whole device\n" ); +pr_info ("erasing whole device\n" );for (i =0 ; i < ebcnt; ++i) {if (bbt[i])continue ;
@@ -84,7 +84,7 @@ static int erase_whole_device(void)return err;cond_resched (); } -printk (PRINT_PREF "erased %u eraseblocks\n" , i); +pr_info ("erased %u eraseblocks\n" , i);return 0 ; }
@@ -97,11 +97,11 @@ static int write_eraseblock(int ebnum)set_random_data (writebuf, subpgsize); err =mtd_write (mtd, addr, subpgsize, &written, writebuf);if (unlikely (err || written != subpgsize)) { -printk (PRINT_PREF "error: write failed at %#llx\n" , +pr_info ("error: write failed at %#llx\n" , (long long )addr);if (written != subpgsize) { -printk (PRINT_PREF " write size: %#x\n" , subpgsize); -printk (PRINT_PREF " written: %#zx\n" , written); +pr_info (" write size: %#x\n" , subpgsize); +pr_info (" written: %#zx\n" , written); }return err ? err :-1 ; }
@@ -111,11 +111,11 @@ static int write_eraseblock(int ebnum)set_random_data (writebuf, subpgsize); err =mtd_write (mtd, addr, subpgsize, &written, writebuf);if (unlikely (err || written != subpgsize)) { -printk (PRINT_PREF "error: write failed at %#llx\n" , +pr_info ("error: write failed at %#llx\n" , (long long )addr);if (written != subpgsize) { -printk (PRINT_PREF " write size: %#x\n" , subpgsize); -printk (PRINT_PREF " written: %#zx\n" , written); +pr_info (" write size: %#x\n" , subpgsize); +pr_info (" written: %#zx\n" , written); }return err ? err :-1 ; }
@@ -135,12 +135,12 @@ static int write_eraseblock2(int ebnum)set_random_data (writebuf, subpgsize * k); err =mtd_write (mtd, addr, subpgsize * k, &written, writebuf);if (unlikely (err || written != subpgsize * k)) { -printk (PRINT_PREF "error: write failed at %#llx\n" , +pr_info ("error: write failed at %#llx\n" , (long long )addr);if (written != subpgsize) { -printk (PRINT_PREF " write size: %#x\n" , +pr_info (" write size: %#x\n" , subpgsize * k); -printk (PRINT_PREF " written: %#08zx\n" , +pr_info (" written: %#08zx\n" , written); }return err ? err :-1 ;
@@ -173,23 +173,23 @@ static int verify_eraseblock(int ebnum) err =mtd_read (mtd, addr, subpgsize, &read, readbuf);if (unlikely (err || read != subpgsize)) {if (mtd_is_bitflip (err) && read == subpgsize) { -printk (PRINT_PREF "ECC correction at %#llx\n" , +pr_info ("ECC correction at %#llx\n" , (long long )addr); err =0 ; }else { -printk (PRINT_PREF "error: read failed at %#llx\n" , +pr_info ("error: read failed at %#llx\n" , (long long )addr);return err ? err :-1 ; } }if (unlikely (memcmp (readbuf, writebuf, subpgsize))) { -printk (PRINT_PREF "error: verify failed at %#llx\n" , +pr_info ("error: verify failed at %#llx\n" , (long long )addr); -printk (PRINT_PREF "------------- written----------------\n" ); +pr_info ("------------- written----------------\n" );print_subpage (writebuf); -printk (PRINT_PREF "------------- read ------------------\n" ); +pr_info ("------------- read ------------------\n" );print_subpage (readbuf); -printk (PRINT_PREF "-------------------------------------\n" ); +pr_info ("-------------------------------------\n" ); errcnt +=1 ; }
@@ -200,23 +200,23 @@ static int verify_eraseblock(int ebnum) err =mtd_read (mtd, addr, subpgsize, &read, readbuf);if (unlikely (err || read != subpgsize)) {if (mtd_is_bitflip (err) && read == subpgsize) { -printk (PRINT_PREF "ECC correction at %#llx\n" , +pr_info ("ECC correction at %#llx\n" , (long long )addr); err =0 ; }else { -printk (PRINT_PREF "error: read failed at %#llx\n" , +pr_info ("error: read failed at %#llx\n" , (long long )addr);return err ? err :-1 ; } }if (unlikely (memcmp (readbuf, writebuf, subpgsize))) { -printk (PRINT_PREF "error: verify failed at %#llx\n" , +pr_info ("error: verify failed at %#llx\n" , (long long )addr); -printk (PRINT_PREF "------------- written----------------\n" ); +pr_info ("------------- written----------------\n" );print_subpage (writebuf); -printk (PRINT_PREF "------------- read ------------------\n" ); +pr_info ("------------- read ------------------\n" );print_subpage (readbuf); -printk (PRINT_PREF "-------------------------------------\n" ); +pr_info ("-------------------------------------\n" ); errcnt +=1 ; }
@@ -237,17 +237,17 @@ static int verify_eraseblock2(int ebnum) err =mtd_read (mtd, addr, subpgsize * k, &read, readbuf);if (unlikely (err || read != subpgsize * k)) {if (mtd_is_bitflip (err) && read == subpgsize * k) { -printk (PRINT_PREF "ECC correction at %#llx\n" , +pr_info ("ECC correction at %#llx\n" , (long long )addr); err =0 ; }else { -printk (PRINT_PREF "error: read failed at " +pr_info ("error: read failed at " "%#llx\n" , (long long )addr);return err ? err :-1 ; } }if (unlikely (memcmp (readbuf, writebuf, subpgsize * k))) { -printk (PRINT_PREF "error: verify failed at %#llx\n" , +pr_info ("error: verify failed at %#llx\n" , (long long )addr); errcnt +=1 ; }
@@ -270,17 +270,17 @@ static int verify_eraseblock_ff(int ebnum) err =mtd_read (mtd, addr, subpgsize, &read, readbuf);if (unlikely (err || read != subpgsize)) {if (mtd_is_bitflip (err) && read == subpgsize) { -printk (PRINT_PREF "ECC correction at %#llx\n" , +pr_info ("ECC correction at %#llx\n" , (long long )addr); err =0 ; }else { -printk (PRINT_PREF "error: read failed at " +pr_info ("error: read failed at " "%#llx\n" , (long long )addr);return err ? err :-1 ; } }if (unlikely (memcmp (readbuf, writebuf, subpgsize))) { -printk (PRINT_PREF "error: verify 0xff failed at " +pr_info ("error: verify 0xff failed at " "%#llx\n" , (long long )addr); errcnt +=1 ; }
@@ -295,7 +295,7 @@ static int verify_all_eraseblocks_ff(void)int err;unsigned int i; -printk (PRINT_PREF "verifying all eraseblocks for 0xff\n" ); +pr_info ("verifying all eraseblocks for 0xff\n" );for (i =0 ; i < ebcnt; ++i) {if (bbt[i])continue ;
@@ -303,10 +303,10 @@ static int verify_all_eraseblocks_ff(void)if (err)return err;if (i %256 ==0 ) -printk (PRINT_PREF "verified up to eraseblock %u\n" , i); +pr_info ("verified up to eraseblock %u\n" , i);cond_resched (); } -printk (PRINT_PREF "verified %u eraseblocks\n" , i); +pr_info ("verified %u eraseblocks\n" , i);return 0 ; }
@@ -317,7 +317,7 @@ static int is_block_bad(int ebnum) ret =mtd_block_isbad (mtd, addr);if (ret) -printk (PRINT_PREF "block %d is bad\n" , ebnum); +pr_info ("block %d is bad\n" , ebnum);return ret; }
@@ -327,18 +327,18 @@ static int scan_for_bad_eraseblocks(void) bbt =kzalloc (ebcnt,GFP_KERNEL );if (!bbt) { -printk (PRINT_PREF "error: cannot allocate memory\n" ); +pr_info ("error: cannot allocate memory\n" );return -ENOMEM ; } -printk (PRINT_PREF "scanning for bad eraseblocks\n" ); +pr_info ("scanning for bad eraseblocks\n" );for (i =0 ; i < ebcnt; ++i) { bbt[i] =is_block_bad (i) ?1 :0 ;if (bbt[i]) bad +=1 ;cond_resched (); } -printk (PRINT_PREF "scanned %d eraseblocks, %d are bad\n" , i, bad); +pr_info ("scanned %d eraseblocks, %d are bad\n" , i, bad);return 0 ; }
@@ -352,22 +352,22 @@ static int __init mtd_subpagetest_init(void)printk (KERN_INFO "=================================================\n" );if (dev <0 ) { -printk (PRINT_PREF "Please specify a valid mtd-device via module paramter\n" ); +pr_info ("Please specify a valid mtd-device via module paramter\n" );printk (KERN_CRIT "CAREFUL: This test wipes all data on the specified MTD device!\n" );return -EINVAL ; } -printk (PRINT_PREF "MTD device: %d\n" , dev); +pr_info ("MTD device: %d\n" , dev); mtd =get_mtd_device (NULL , dev);if (IS_ERR (mtd)) { err =PTR_ERR (mtd); -printk (PRINT_PREF "error: cannot get MTD device\n" ); +pr_info ("error: cannot get MTD device\n" );return err; }if (mtd->type !=MTD_NANDFLASH ) { -printk (PRINT_PREF "this test requires NAND flash\n" ); +pr_info ("this test requires NAND flash\n" ); goto out; }
@@ -377,7 +377,7 @@ static int __init mtd_subpagetest_init(void) ebcnt = tmp; pgcnt = mtd->erasesize / mtd->writesize; - printk(PRINT_PREF "MTD device size %llu, eraseblock size %u, " + pr_info("MTD device size %llu, eraseblock size %u, " "page size %u, subpage size %u, count of eraseblocks %u, " "pages per eraseblock %u, OOB size %u\n", (unsigned long long)mtd->size, mtd->erasesize,
@@ -387,12 +387,12 @@ static int __init mtd_subpagetest_init(void) bufsize = subpgsize *32 ; writebuf =kmalloc (bufsize,GFP_KERNEL );if (!writebuf) { -printk (PRINT_PREF "error: cannot allocate memory\n" ); +pr_info ("error: cannot allocate memory\n" ); goto out; } readbuf =kmalloc (bufsize,GFP_KERNEL );if (!readbuf) { -printk (PRINT_PREF "error: cannot allocate memory\n" ); +pr_info ("error: cannot allocate memory\n" ); goto out; }
@@ -404,7 +404,7 @@ static int __init mtd_subpagetest_init(void)if (err) goto out; -printk (PRINT_PREF "writing whole device\n" ); +pr_info ("writing whole device\n" );simple_srand (1 );for (i =0 ; i < ebcnt; ++i) {if (bbt[i])
@@ -413,13 +413,13 @@ static int __init mtd_subpagetest_init(void)if (unlikely (err)) goto out;if (i %256 ==0 ) -printk (PRINT_PREF "written up to eraseblock %u\n" , i); +pr_info ("written up to eraseblock %u\n" , i);cond_resched (); } -printk (PRINT_PREF "written %u eraseblocks\n" , i); +pr_info ("written %u eraseblocks\n" , i);simple_srand (1 ); -printk (PRINT_PREF "verifying all eraseblocks\n" ); +pr_info ("verifying all eraseblocks\n" );for (i =0 ; i < ebcnt; ++i) {if (bbt[i])continue ;
@@ -427,10 +427,10 @@ static int __init mtd_subpagetest_init(void)if (unlikely (err)) goto out;if (i %256 ==0 ) -printk (PRINT_PREF "verified up to eraseblock %u\n" , i); +pr_info ("verified up to eraseblock %u\n" , i);cond_resched (); } -printk (PRINT_PREF "verified %u eraseblocks\n" , i); +pr_info ("verified %u eraseblocks\n" , i); err =erase_whole_device ();if (err)
@@ -442,7 +442,7 @@ static int __init mtd_subpagetest_init(void)/* Write all eraseblocks */ simple_srand (3 ); -printk (PRINT_PREF "writing whole device\n" ); +pr_info ("writing whole device\n" );for (i =0 ; i < ebcnt; ++i) {if (bbt[i])continue ;
@@ -450,14 +450,14 @@ static int __init mtd_subpagetest_init(void)if (unlikely (err)) goto out;if (i %256 ==0 ) -printk (PRINT_PREF "written up to eraseblock %u\n" , i); +pr_info ("written up to eraseblock %u\n" , i);cond_resched (); } -printk (PRINT_PREF "written %u eraseblocks\n" , i); +pr_info ("written %u eraseblocks\n" , i);/* Check all eraseblocks */ simple_srand (3 ); -printk (PRINT_PREF "verifying all eraseblocks\n" ); +pr_info ("verifying all eraseblocks\n" );for (i =0 ; i < ebcnt; ++i) {if (bbt[i])continue ;
@@ -465,10 +465,10 @@ static int __init mtd_subpagetest_init(void)if (unlikely (err)) goto out;if (i %256 ==0 ) -printk (PRINT_PREF "verified up to eraseblock %u\n" , i); +pr_info ("verified up to eraseblock %u\n" , i);cond_resched (); } -printk (PRINT_PREF "verified %u eraseblocks\n" , i); +pr_info ("verified %u eraseblocks\n" , i); err =erase_whole_device ();if (err)
@@ -478,7 +478,7 @@ static int __init mtd_subpagetest_init(void)if (err) goto out; -printk (PRINT_PREF "finished with %d errors\n" , errcnt); +pr_info ("finished with %d errors\n" , errcnt); out:kfree (bbt);
@@ -486,7 +486,7 @@ out:kfree (writebuf);put_mtd_device (mtd);if (err) -printk (PRINT_PREF "error %d occurred\n" , err); +pr_info ("error %d occurred\n" , err);printk (KERN_INFO "=================================================\n" );return err; }
Signature · 1 line
1.7.4.1
PATCH 5/8 mtd_stresstest: Replace printk with pr_{info,crit}
In reply to Vikram NarayananRemove PRINT_PREF macro and use pr_fmt to add the prefix
--- drivers/mtd/tests/mtd_stresstest.c | 40 ++++++++++++++++++------------------ 1 files changed, 20 insertions(+), 20 deletions(-)
drivers/mtd/tests/mtd_stresstest.c +20 -20
@@ -19,6 +19,8 @@* Author: Adrian Hunter <[email protected]> */ +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt +#include <linux/init.h> #include <linux/module.h> #include <linux/moduleparam.h>
@@ -30,8 +32,6 @@#include <linux/random.h> #include "mtd_tests.h" -#define PRINT_PREF KERN_INFO "mtd_stresstest: " -static int dev = -EINVAL ;module_param (dev, int,S_IRUGO );MODULE_PARM_DESC (dev,"MTD device number to use" );
@@ -89,7 +89,7 @@ static int is_block_bad(int ebnum) ret =mtd_block_isbad (mtd, addr);if (ret) -printk (PRINT_PREF "block %d is bad\n" , ebnum); +pr_info ("block %d is bad\n" , ebnum);return ret; }
@@ -112,7 +112,7 @@ static int do_read(void)if (mtd_is_bitflip (err)) err =0 ;if (unlikely (err || read != len)) { -printk (PRINT_PREF "error: read failed at 0x%llx\n" , +pr_info ("error: read failed at 0x%llx\n" , (long long )addr);if (!err) err = -EINVAL ;
@@ -149,7 +149,7 @@ static int do_write(void) addr = eb * mtd->erasesize + offs; err =mtd_write (mtd, addr, len, &written, writebuf);if (unlikely (err || written != len)) { -printk (PRINT_PREF "error: write failed at 0x%llx\n" , +pr_info ("error: write failed at 0x%llx\n" , (long long )addr);if (!err) err = -EINVAL ;
@@ -178,21 +178,21 @@ static int scan_for_bad_eraseblocks(void) bbt =kzalloc (ebcnt,GFP_KERNEL );if (!bbt) { -printk (PRINT_PREF "error: cannot allocate memory\n" ); +pr_info ("error: cannot allocate memory\n" );return -ENOMEM ; }if (!mtd_can_have_bb (mtd))return 0 ; -printk (PRINT_PREF "scanning for bad eraseblocks\n" ); +pr_info ("scanning for bad eraseblocks\n" );for (i =0 ; i < ebcnt; ++i) { bbt[i] =is_block_bad (i) ?1 :0 ;if (bbt[i]) bad +=1 ;cond_resched (); } -printk (PRINT_PREF "scanned %d eraseblocks, %d are bad\n" , i, bad); +pr_info ("scanned %d eraseblocks, %d are bad\n" , i, bad);return 0 ; }
@@ -206,22 +206,22 @@ static int __init mtd_stresstest_init(void)printk (KERN_INFO "=================================================\n" );if (dev <0 ) { -printk (PRINT_PREF "Please specify a valid mtd-device via module paramter\n" ); -printk (KERN_CRIT "CAREFUL: This test wipes all data on the specified MTD device!\n" ); +pr_info ("Please specify a valid mtd-device via module paramter\n" ); +pr_crit ("CAREFUL: This test wipes all data on the specified MTD device!\n" );return -EINVAL ; } -printk (PRINT_PREF "MTD device: %d\n" , dev); +pr_info ("MTD device: %d\n" , dev); mtd =get_mtd_device (NULL , dev);if (IS_ERR (mtd)) { err =PTR_ERR (mtd); -printk (PRINT_PREF "error: cannot get MTD device\n" ); +pr_info ("error: cannot get MTD device\n" );return err; }if (mtd->writesize ==1 ) { -printk (PRINT_PREF "not NAND flash, assume page size is 512 " +pr_info ("not NAND flash, assume page size is 512 " "bytes.\n" ); pgsize =512 ; }else
@@ -232,14 +232,14 @@ static int __init mtd_stresstest_init(void) ebcnt = tmp; pgcnt = mtd->erasesize / pgsize; -printk (PRINT_PREF "MTD device size %llu, eraseblock size %u, " +pr_info ("MTD device size %llu, eraseblock size %u, " "page size %u, count of eraseblocks %u, pages per " "eraseblock %u, OOB size %u\n" , (unsigned long long )mtd->size, mtd->erasesize, pgsize, ebcnt, pgcnt, mtd->oobsize);if (ebcnt <2 ) { -printk (PRINT_PREF "error: need at least 2 eraseblocks\n" ); +pr_info ("error: need at least 2 eraseblocks\n" ); err = -ENOSPC ; goto out_put_mtd; }
@@ -252,7 +252,7 @@ static int __init mtd_stresstest_init(void) writebuf =vmalloc (bufsize); offsets =kmalloc (ebcnt *sizeof (int ),GFP_KERNEL );if (!readbuf || !writebuf || !offsets) { -printk (PRINT_PREF "error: cannot allocate memory\n" ); +pr_info ("error: cannot allocate memory\n" ); goto out; }for (i =0 ; i < ebcnt; i++)
@@ -265,16 +265,16 @@ static int __init mtd_stresstest_init(void) goto out;/* Do operations */ -printk (PRINT_PREF "doing operations\n" ); +pr_info ("doing operations\n" );for (op =0 ; op < count; op++) {if ((op &1023 ) ==0 ) -printk (PRINT_PREF "%d operations done\n" , op); +pr_info ("%d operations done\n" , op); err =do_operation ();if (err) goto out;cond_resched (); } -printk (PRINT_PREF "finished, %d operations done\n" , op); +pr_info ("finished, %d operations done\n" , op); out:kfree (offsets);
@@ -284,7 +284,7 @@ out: out_put_mtd:put_mtd_device (mtd);if (err) -printk (PRINT_PREF "error %d occurred\n" , err); +pr_info ("error %d occurred\n" , err);printk (KERN_INFO "=================================================\n" );return err; }
Signature · 1 line
1.7.4.1
PATCH 6/8 mtd_speedtest: Replace printk with pr_{info,crit}
In reply to Vikram NarayananRemove PRINT_PREF macro and use pr_fmt to add the prefix
--- drivers/mtd/tests/mtd_speedtest.c | 80 ++++++++++++++++++------------------ 1 files changed, 40 insertions(+), 40 deletions(-)
drivers/mtd/tests/mtd_speedtest.c +40 -40
@@ -19,6 +19,8 @@* Author: Adrian Hunter <[email protected]> */ +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt +#include <linux/init.h> #include <linux/module.h> #include <linux/moduleparam.h>
@@ -29,8 +31,6 @@#include <linux/random.h> #include "mtd_tests.h" -#define PRINT_PREF KERN_INFO "mtd_speedtest: " -static int dev = -EINVAL ;module_param (dev, int,S_IRUGO );MODULE_PARM_DESC (dev,"MTD device number to use" );
@@ -82,7 +82,7 @@ static int write_eraseblock(int ebnum) err =mtd_write (mtd, addr, mtd->erasesize, &written, iobuf);if (err || written != mtd->erasesize) { -printk (PRINT_PREF "error: write failed at %#llx\n" , addr); +pr_info ("error: write failed at %#llx\n" , addr);if (!err) err = -EINVAL ; }
@@ -100,7 +100,7 @@ static int write_eraseblock_by_page(int ebnum)for (i =0 ; i < pgcnt; i++) { err =mtd_write (mtd, addr, pgsize, &written, buf);if (err || written != pgsize) { -printk (PRINT_PREF "error: write failed at %#llx\n" , +pr_info ("error: write failed at %#llx\n" , addr);if (!err) err = -EINVAL ;
@@ -123,7 +123,7 @@ static int write_eraseblock_by_2pages(int ebnum)for (i =0 ; i < n; i++) { err =mtd_write (mtd, addr, sz, &written, buf);if (err || written != sz) { -printk (PRINT_PREF "error: write failed at %#llx\n" , +pr_info ("error: write failed at %#llx\n" , addr);if (!err) err = -EINVAL ;
@@ -135,7 +135,7 @@ static int write_eraseblock_by_2pages(int ebnum)if (pgcnt %2 ) { err =mtd_write (mtd, addr, pgsize, &written, buf);if (err || written != pgsize) { -printk (PRINT_PREF "error: write failed at %#llx\n" , +pr_info ("error: write failed at %#llx\n" , addr);if (!err) err = -EINVAL ;
@@ -156,7 +156,7 @@ static int read_eraseblock(int ebnum)if (mtd_is_bitflip (err)) err =0 ;if (err || read != mtd->erasesize) { -printk (PRINT_PREF "error: read failed at %#llx\n" , addr); +pr_info ("error: read failed at %#llx\n" , addr);if (!err) err = -EINVAL ; }
@@ -177,7 +177,7 @@ static int read_eraseblock_by_page(int ebnum)if (mtd_is_bitflip (err)) err =0 ;if (err || read != pgsize) { -printk (PRINT_PREF "error: read failed at %#llx\n" , +pr_info ("error: read failed at %#llx\n" , addr);if (!err) err = -EINVAL ;
@@ -203,7 +203,7 @@ static int read_eraseblock_by_2pages(int ebnum)if (mtd_is_bitflip (err)) err =0 ;if (err || read != sz) { -printk (PRINT_PREF "error: read failed at %#llx\n" , +pr_info ("error: read failed at %#llx\n" , addr);if (!err) err = -EINVAL ;
@@ -218,7 +218,7 @@ static int read_eraseblock_by_2pages(int ebnum)if (mtd_is_bitflip (err)) err =0 ;if (err || read != pgsize) { -printk (PRINT_PREF "error: read failed at %#llx\n" , +pr_info ("error: read failed at %#llx\n" , addr);if (!err) err = -EINVAL ;
@@ -235,7 +235,7 @@ static int is_block_bad(int ebnum) ret =mtd_block_isbad (mtd, addr);if (ret) -printk (PRINT_PREF "block %d is bad\n" , ebnum); +pr_info ("block %d is bad\n" , ebnum);return ret; }
@@ -269,21 +269,21 @@ static int scan_for_bad_eraseblocks(void) bbt =kzalloc (ebcnt,GFP_KERNEL );if (!bbt) { -printk (PRINT_PREF "error: cannot allocate memory\n" ); +pr_info ("error: cannot allocate memory\n" );return -ENOMEM ; }if (!mtd_can_have_bb (mtd)) goto out; -printk (PRINT_PREF "scanning for bad eraseblocks\n" ); +pr_info ("scanning for bad eraseblocks\n" );for (i =0 ; i < ebcnt; ++i) { bbt[i] =is_block_bad (i) ?1 :0 ;if (bbt[i]) bad +=1 ;cond_resched (); } -printk (PRINT_PREF "scanned %d eraseblocks, %d are bad\n" , i, bad); +pr_info ("scanned %d eraseblocks, %d are bad\n" , i, bad); out: goodebcnt = ebcnt - bad;return 0 ;
@@ -299,25 +299,25 @@ static int __init mtd_speedtest_init(void)printk (KERN_INFO "=================================================\n" );if (dev <0 ) { -printk (PRINT_PREF "Please specify a valid mtd-device via module paramter\n" ); -printk (KERN_CRIT "CAREFUL: This test wipes all data on the specified MTD device!\n" ); +pr_info ("Please specify a valid mtd-device via module paramter\n" ); +pr_crit ("CAREFUL: This test wipes all data on the specified MTD device!\n" );return -EINVAL ; }if (count) -printk (PRINT_PREF "MTD device: %d count: %d\n" , dev, count); +pr_info ("MTD device: %d count: %d\n" , dev, count);else -printk (PRINT_PREF "MTD device: %d\n" , dev); +pr_info ("MTD device: %d\n" , dev); mtd =get_mtd_device (NULL , dev);if (IS_ERR (mtd)) { err =PTR_ERR (mtd); -printk (PRINT_PREF "error: cannot get MTD device\n" ); +pr_info ("error: cannot get MTD device\n" );return err; }if (mtd->writesize ==1 ) { -printk (PRINT_PREF "not NAND flash, assume page size is 512 " +pr_info ("not NAND flash, assume page size is 512 " "bytes.\n" ); pgsize =512 ; }else
@@ -328,7 +328,7 @@ static int __init mtd_speedtest_init(void) ebcnt = tmp; pgcnt = mtd->erasesize / pgsize; - printk(PRINT_PREF "MTD device size %llu, eraseblock size %u, " + pr_info("MTD device size %llu, eraseblock size %u, " "page size %u, count of eraseblocks %u, pages per " "eraseblock %u, OOB size %u\n", (unsigned long long)mtd->size, mtd->erasesize,
@@ -340,7 +340,7 @@ static int __init mtd_speedtest_init(void) err = -ENOMEM ; iobuf =kmalloc (mtd->erasesize,GFP_KERNEL );if (!iobuf) { -printk (PRINT_PREF "error: cannot allocate memory\n" ); +pr_info ("error: cannot allocate memory\n" ); goto out; }
@@ -355,7 +355,7 @@ static int __init mtd_speedtest_init(void) goto out;/* Write all eraseblocks, 1 eraseblock at a time */ -printk (PRINT_PREF "testing eraseblock write speed\n" ); +pr_info ("testing eraseblock write speed\n" );start_timing ();for (i =0 ; i < ebcnt; ++i) {if (bbt[i])
@@ -367,10 +367,10 @@ static int __init mtd_speedtest_init(void) }stop_timing (); speed =calc_speed (); -printk (PRINT_PREF "eraseblock write speed is %ld KiB/s\n" , speed); +pr_info ("eraseblock write speed is %ld KiB/s\n" , speed);/* Read all eraseblocks, 1 eraseblock at a time */ -printk (PRINT_PREF "testing eraseblock read speed\n" ); +pr_info ("testing eraseblock read speed\n" );start_timing ();for (i =0 ; i < ebcnt; ++i) {if (bbt[i])
@@ -382,14 +382,14 @@ static int __init mtd_speedtest_init(void) }stop_timing (); speed =calc_speed (); -printk (PRINT_PREF "eraseblock read speed is %ld KiB/s\n" , speed); +pr_info ("eraseblock read speed is %ld KiB/s\n" , speed); err =erase_whole_device ();if (err) goto out;/* Write all eraseblocks, 1 page at a time */ -printk (PRINT_PREF "testing page write speed\n" ); +pr_info ("testing page write speed\n" );start_timing ();for (i =0 ; i < ebcnt; ++i) {if (bbt[i])
@@ -401,10 +401,10 @@ static int __init mtd_speedtest_init(void) }stop_timing (); speed =calc_speed (); -printk (PRINT_PREF "page write speed is %ld KiB/s\n" , speed); +pr_info ("page write speed is %ld KiB/s\n" , speed);/* Read all eraseblocks, 1 page at a time */ -printk (PRINT_PREF "testing page read speed\n" ); +pr_info ("testing page read speed\n" );start_timing ();for (i =0 ; i < ebcnt; ++i) {if (bbt[i])
@@ -416,14 +416,14 @@ static int __init mtd_speedtest_init(void) }stop_timing (); speed =calc_speed (); -printk (PRINT_PREF "page read speed is %ld KiB/s\n" , speed); +pr_info ("page read speed is %ld KiB/s\n" , speed); err =erase_whole_device ();if (err) goto out;/* Write all eraseblocks, 2 pages at a time */ -printk (PRINT_PREF "testing 2 page write speed\n" ); +pr_info ("testing 2 page write speed\n" );start_timing ();for (i =0 ; i < ebcnt; ++i) {if (bbt[i])
@@ -435,10 +435,10 @@ static int __init mtd_speedtest_init(void) }stop_timing (); speed =calc_speed (); -printk (PRINT_PREF "2 page write speed is %ld KiB/s\n" , speed); +pr_info ("2 page write speed is %ld KiB/s\n" , speed);/* Read all eraseblocks, 2 pages at a time */ -printk (PRINT_PREF "testing 2 page read speed\n" ); +pr_info ("testing 2 page read speed\n" );start_timing ();for (i =0 ; i < ebcnt; ++i) {if (bbt[i])
@@ -450,10 +450,10 @@ static int __init mtd_speedtest_init(void) }stop_timing (); speed =calc_speed (); -printk (PRINT_PREF "2 page read speed is %ld KiB/s\n" , speed); +pr_info ("2 page read speed is %ld KiB/s\n" , speed);/* Erase all eraseblocks */ -printk (PRINT_PREF "Testing erase speed\n" ); +pr_info ("Testing erase speed\n" );start_timing ();for (i =0 ; i < ebcnt; ++i) {if (bbt[i])
@@ -465,12 +465,12 @@ static int __init mtd_speedtest_init(void) }stop_timing (); speed =calc_speed (); -printk (PRINT_PREF "erase speed is %ld KiB/s\n" , speed); +pr_info ("erase speed is %ld KiB/s\n" , speed);/* Multi-block erase all eraseblocks */ for (k =1 ; k <7 ; k++) { blocks =1 << k; -printk (PRINT_PREF "Testing %dx multi-block erase speed\n" , +pr_info ("Testing %dx multi-block erase speed\n" , blocks);start_timing ();for (i =0 ; i < ebcnt; ) {
@@ -489,16 +489,16 @@ static int __init mtd_speedtest_init(void) }stop_timing (); speed =calc_speed (); -printk (PRINT_PREF "%dx multi-block erase speed is %ld KiB/s\n" , +pr_info ("%dx multi-block erase speed is %ld KiB/s\n" , blocks, speed); } -printk (PRINT_PREF "finished\n" ); +pr_info ("finished\n" ); out:kfree (iobuf);kfree (bbt);put_mtd_device (mtd);if (err) -printk (PRINT_PREF "error %d occurred\n" , err); +pr_info ("error %d occurred\n" , err);printk (KERN_INFO "=================================================\n" );return err; }
Signature · 1 line
1.7.4.1
PATCH 7/8 mtd_readtest: Replace printk with pr_info
In reply to Vikram NarayananRemove PRINT_PREF macro and use pr_fmt to add the prefix
--- drivers/mtd/tests/mtd_readtest.c | 42 +++++++++++++++++++------------------- 1 files changed, 21 insertions(+), 21 deletions(-)
drivers/mtd/tests/mtd_readtest.c +21 -21
@@ -19,6 +19,8 @@* Author: Adrian Hunter <[email protected]> */ +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt +#include <linux/init.h> #include <linux/module.h> #include <linux/moduleparam.h>
@@ -27,8 +29,6 @@#include <linux/slab.h> #include <linux/sched.h> -#define PRINT_PREF KERN_INFO "mtd_readtest: " -static int dev = -EINVAL ;module_param (dev, int,S_IRUGO );MODULE_PARM_DESC (dev,"MTD device number to use" );
@@ -56,7 +56,7 @@ static int read_eraseblock_by_page(int ebnum)if (ret == -EUCLEAN ) ret =0 ;if (ret || read != pgsize) { -printk (PRINT_PREF "error: read failed at %#llx\n" , +pr_info ("error: read failed at %#llx\n" , (long long )addr);if (!err) err = ret;
@@ -77,7 +77,7 @@ static int read_eraseblock_by_page(int ebnum) ret =mtd_read_oob (mtd, addr, &ops);if ((ret && !mtd_is_bitflip (ret)) || ops.oobretlen != mtd->oobsize) { -printk (PRINT_PREF "error: read oob failed at " +pr_info ("error: read oob failed at " "%#llx\n" , (long long )addr);if (!err) err = ret;
@@ -99,7 +99,7 @@ static void dump_eraseblock(int ebnum)char line[128 ];int pg, oob; -printk (PRINT_PREF "dumping eraseblock %d\n" , ebnum); +pr_info ("dumping eraseblock %d\n" , ebnum); n = mtd->erasesize;for (i =0 ; i < n;) {char *p = line;
@@ -112,7 +112,7 @@ static void dump_eraseblock(int ebnum) }if (!mtd->oobsize)return ; -printk (PRINT_PREF "dumping oob from eraseblock %d\n" , ebnum); +pr_info ("dumping oob from eraseblock %d\n" , ebnum); n = mtd->oobsize;for (pg =0 , i =0 ; pg < pgcnt; pg++)for (oob =0 ; oob < n;) {
@@ -134,7 +134,7 @@ static int is_block_bad(int ebnum) ret =mtd_block_isbad (mtd, addr);if (ret) -printk (PRINT_PREF "block %d is bad\n" , ebnum); +pr_info ("block %d is bad\n" , ebnum);return ret; }
@@ -144,21 +144,21 @@ static int scan_for_bad_eraseblocks(void) bbt =kzalloc (ebcnt,GFP_KERNEL );if (!bbt) { -printk (PRINT_PREF "error: cannot allocate memory\n" ); +pr_info ("error: cannot allocate memory\n" );return -ENOMEM ; }if (!mtd_can_have_bb (mtd))return 0 ; -printk (PRINT_PREF "scanning for bad eraseblocks\n" ); +pr_info ("scanning for bad eraseblocks\n" );for (i =0 ; i < ebcnt; ++i) { bbt[i] =is_block_bad (i) ?1 :0 ;if (bbt[i]) bad +=1 ;cond_resched (); } -printk (PRINT_PREF "scanned %d eraseblocks, %d are bad\n" , i, bad); +pr_info ("scanned %d eraseblocks, %d are bad\n" , i, bad);return 0 ; }
@@ -171,21 +171,21 @@ static int __init mtd_readtest_init(void)printk (KERN_INFO "=================================================\n" );if (dev <0 ) { -printk (PRINT_PREF "Please specify a valid mtd-device via module paramter\n" ); +pr_info ("Please specify a valid mtd-device via module paramter\n" );return -EINVAL ; } -printk (PRINT_PREF "MTD device: %d\n" , dev); +pr_info ("MTD device: %d\n" , dev); mtd =get_mtd_device (NULL , dev);if (IS_ERR (mtd)) { err =PTR_ERR (mtd); -printk (PRINT_PREF "error: Cannot get MTD device\n" ); +pr_info ("error: Cannot get MTD device\n" );return err; }if (mtd->writesize ==1 ) { -printk (PRINT_PREF "not NAND flash, assume page size is 512 " +pr_info ("not NAND flash, assume page size is 512 " "bytes.\n" ); pgsize =512 ; }else
@@ -196,7 +196,7 @@ static int __init mtd_readtest_init(void) ebcnt = tmp; pgcnt = mtd->erasesize / pgsize; - printk(PRINT_PREF "MTD device size %llu, eraseblock size %u, " + pr_info("MTD device size %llu, eraseblock size %u, " "page size %u, count of eraseblocks %u, pages per " "eraseblock %u, OOB size %u\n", (unsigned long long)mtd->size, mtd->erasesize,
@@ -205,12 +205,12 @@ static int __init mtd_readtest_init(void) err = -ENOMEM ; iobuf =kmalloc (mtd->erasesize,GFP_KERNEL );if (!iobuf) { -printk (PRINT_PREF "error: cannot allocate memory\n" ); +pr_info ("error: cannot allocate memory\n" ); goto out; } iobuf1 =kmalloc (mtd->erasesize,GFP_KERNEL );if (!iobuf1) { -printk (PRINT_PREF "error: cannot allocate memory\n" ); +pr_info ("error: cannot allocate memory\n" ); goto out; }
@@ -219,7 +219,7 @@ static int __init mtd_readtest_init(void) goto out;/* Read all eraseblocks 1 page at a time */ -printk (PRINT_PREF "testing page read\n" ); +pr_info ("testing page read\n" );for (i =0 ; i < ebcnt; ++i) {int ret;
@@ -235,9 +235,9 @@ static int __init mtd_readtest_init(void) }if (err) -printk (PRINT_PREF "finished with errors\n" ); +pr_info ("finished with errors\n" );else -printk (PRINT_PREF "finished\n" ); +pr_info ("finished\n" ); out:
@@ -246,7 +246,7 @@ out:kfree (bbt);put_mtd_device (mtd);if (err) -printk (PRINT_PREF "error %d occurred\n" , err); +pr_info ("error %d occurred\n" , err);printk (KERN_INFO "=================================================\n" );return err; }
Signature · 1 line
1.7.4.1
PATCH 8/8 mtd_nandbiterrs: Replace msg macro with pr_info
In reply to Vikram NarayananRemove msg macro and use pr_fmt to add the prefix
--- drivers/mtd/tests/mtd_nandbiterrs.c | 68 +++++++++++++++++----------------- 1 files changed, 34 insertions(+), 34 deletions(-)
drivers/mtd/tests/mtd_nandbiterrs.c +34 -34
@@ -39,6 +39,9 @@* this program; see the file COPYING. If not, write to the Free Software * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt +#include <linux/init.h> #include <linux/module.h> #include <linux/moduleparam.h>
@@ -48,8 +51,6 @@#include <linux/slab.h> #include "mtd_tests.h" -#define msg(FMT, VA...) pr_info("mtd_nandbiterrs: "FMT, ##VA) -static int dev;module_param (dev, int,S_IRUGO );MODULE_PARM_DESC (dev,"MTD device number to use" );
@@ -105,11 +106,11 @@ static int write_page(int log)size_t written;if (log) -msg ("write_page\n" ); +pr_info ("write_page\n" ); err =mtd_write (mtd, offset, mtd->writesize, &written, wbuffer);if (err || written != mtd->writesize) { -msg ("error: write failed at %#llx\n" , (long long )offset); +pr_info ("error: write failed at %#llx\n" , (long long )offset);if (!err) err = -EIO ; }
@@ -124,7 +125,7 @@ static int rewrite_page(int log)struct mtd_oob_ops ops;if (log) -msg ("rewrite page\n" ); +pr_info ("rewrite page\n" ); ops.mode =MTD_OPS_RAW ;/* No ECC */ ops.len = mtd->writesize;
@@ -137,7 +138,7 @@ static int rewrite_page(int log) err =mtd_write_oob (mtd, offset, &ops);if (err || ops.retlen != mtd->writesize) { -msg ("error: write_oob failed (%d)\n" , err); +pr_info ("error: write_oob failed (%d)\n" , err);if (!err) err = -EIO ; }
@@ -154,7 +155,7 @@ static int read_page(int log)struct mtd_ecc_stats oldstats;if (log) -msg ("read_page\n" ); +pr_info ("read_page\n" );/* Saving last mtd stats */ memcpy (&oldstats, &mtd->ecc_stats,sizeof (oldstats));
@@ -164,7 +165,7 @@ static int read_page(int log) err = mtd->ecc_stats.corrected - oldstats.corrected;if (err <0 || read != mtd->writesize) { -msg ("error: read failed at %#llx\n" , (long long )offset); +pr_info ("error: read failed at %#llx\n" , (long long )offset);if (err >=0 ) err = -EIO ; }
@@ -178,11 +179,11 @@ static int verify_page(int log)unsigned i, errs =0 ;if (log) -msg ("verify_page\n" ); +pr_info ("verify_page\n" );for (i =0 ; i < mtd->writesize; i++) {if (rbuffer[i] !=hash (i+seed)) { -msg ("Error: page offset %u, expected %02x, got %02x\n" , +pr_info ("Error: page offset %u, expected %02x, got %02x\n" , i,hash (i+seed), rbuffer[i]); errs++; }
@@ -207,13 +208,13 @@ static int insert_biterror(unsigned byte)for (bit =7 ; bit >=0 ; bit--) {if (CBIT (wbuffer[byte], bit)) {BCLR (wbuffer[byte], bit); -msg ("Inserted biterror @ %u/%u\n" , byte, bit); +pr_info ("Inserted biterror @ %u/%u\n" , byte, bit);return 0 ; } } byte++; } -msg ("biterror: Failed to find a '1' bit\n" ); +pr_info ("biterror: Failed to find a '1' bit\n" );return -EIO ; }
@@ -225,7 +226,7 @@ static int incremental_errors_test(void)unsigned i;unsigned errs_per_subpage =0 ; -msg ("incremental biterrors test\n" ); +pr_info ("incremental biterrors test\n" );for (i =0 ; i < mtd->writesize; i++) wbuffer[i] =hash (i+seed);
@@ -242,9 +243,9 @@ static int incremental_errors_test(void) err =read_page (1 );if (err >0 ) -msg ("Read reported %d corrected bit errors\n" , err); +pr_info ("Read reported %d corrected bit errors\n" , err);if (err <0 ) { -msg ("After %d biterrors per subpage, read reported error %d\n" , +pr_info ("After %d biterrors per subpage, read reported error %d\n" , errs_per_subpage, err); err =0 ; goto exit;
@@ -252,11 +253,11 @@ static int incremental_errors_test(void) err =verify_page (1 );if (err) { -msg ("ECC failure, read data is incorrect despite read success\n" ); +pr_info ("ECC failure, read data is incorrect despite read success\n" ); goto exit; } -msg ("Successfully corrected %d bit errors per subpage\n" , +pr_info ("Successfully corrected %d bit errors per subpage\n" , errs_per_subpage);for (i =0 ; i < subcount; i++) {
@@ -288,7 +289,7 @@ static int overwrite_test(void)memset (bitstats,0 ,sizeof (bitstats)); -msg ("overwrite biterrors test\n" ); +pr_info ("overwrite biterrors test\n" );for (i =0 ; i < mtd->writesize; i++) wbuffer[i] =hash (i+seed);
@@ -306,18 +307,18 @@ static int overwrite_test(void) err =read_page (0 );if (err >=0 ) {if (err >=MAXBITS ) { -msg ("Implausible number of bit errors corrected\n" ); +pr_info ("Implausible number of bit errors corrected\n" ); err = -EIO ;break ; } bitstats[err]++;if (err > max_corrected) { max_corrected = err; -msg ("Read reported %d corrected bit errors\n" , +pr_info ("Read reported %d corrected bit errors\n" , err); } }else {/* err < 0 */ -msg ("Read reported error %d\n" , err); +pr_info ("Read reported error %d\n" , err); err =0 ;break ; }
@@ -325,7 +326,7 @@ static int overwrite_test(void) err =verify_page (0 );if (err) { bitstats[max_corrected] = opno; -msg ("ECC failure, read data is incorrect despite read success\n" ); +pr_info ("ECC failure, read data is incorrect despite read success\n" );break ; }
@@ -334,9 +335,9 @@ static int overwrite_test(void)/* At this point bitstats[0] contains the number of ops with no bit * errors, bitstats[1] the number of ops with 1 bit error, etc. */ -msg ("Bit error histogram (%d operations total):\n" , opno); +pr_info ("Bit error histogram (%d operations total):\n" , opno);for (i =0 ; i < max_corrected; i++) -msg ("Page reads with %3d corrected bit errors: %d\n" , +pr_info ("Page reads with %3d corrected bit errors: %d\n" , i, bitstats[i]); exit:
@@ -347,36 +348,35 @@ static int __init mtd_nandbiterrs_init(void) {int err =0 ; -msg ("\n" ); -msg ("==================================================\n" ); -msg ("MTD device: %d\n" , dev); +printk (KERN_INFO "\n==================================================\n" ); +pr_info ("MTD device: %d\n" , dev); mtd =get_mtd_device (NULL , dev);if (IS_ERR (mtd)) { err =PTR_ERR (mtd); -msg ("error: cannot get MTD device\n" ); +pr_info ("error: cannot get MTD device\n" ); goto exit_mtddev; }if (mtd->type !=MTD_NANDFLASH ) { -msg ("this test requires NAND flash\n" ); +pr_info ("this test requires NAND flash\n" ); err = -ENODEV ; goto exit_nand; } -msg ("MTD device size %llu, eraseblock=%u, page=%u, oob=%u\n" , +pr_info ("MTD device size %llu, eraseblock=%u, page=%u, oob=%u\n" , (unsigned long long )mtd->size, mtd->erasesize, mtd->writesize, mtd->oobsize); subsize = mtd->writesize >> mtd->subpage_sft; subcount = mtd->writesize / subsize; -msg ("Device uses %d subpages of %d bytes\n" , subcount, subsize); +pr_info ("Device uses %d subpages of %d bytes\n" , subcount, subsize); offset = page_offset * mtd->writesize; eraseblock =mtd_div_by_eb (offset, mtd); -msg ("Using page=%u, offset=%llu, eraseblock=%u\n" , +pr_info ("Using page=%u, offset=%llu, eraseblock=%u\n" , page_offset, offset, eraseblock); wbuffer =kmalloc (mtd->writesize,GFP_KERNEL );
@@ -409,8 +409,8 @@ static int __init mtd_nandbiterrs_init(void) goto exit_error; err = -EIO ; -msg ("finished successfully.\n" ); -msg ("==================================================\n" ); +pr_info ("finished successfully.\n" ); +printk (KERN_INFO "==================================================\n" ); exit_error:kfree (rbuffer);
Signature · 1 line
1.7.4.1
Re: [PATCH 1/8] mtd_tests: Refactor duplicate code
In reply to Vikram NarayananQuoted 3 lines · Vikram Narayanan
Move the duplicate code from all the tests to a common header.
Signed-off-by Vikram Narayanan <[email protected]>
Could you please re-structure your patches so that you first do the 'pr_' changes, and then this one. Because 'pr_' are trivial and I can apply them right away.
This one - I think if you look at UBI and JFFS2 - you may find them also use the same pattern, and you can actually make this function go to mtdcore.c and be exported instead.
Signature · 2 lines
Best Regards, Artem Bityutskiy