mtd: tests: don't use mtd0 as a default
authorWolfram Sang <w.sang@pengutronix.de>
Sat, 29 Oct 2011 22:11:53 +0000 (00:11 +0200)
committerArtem Bityutskiy <Artem.Bityutskiy@intel.com>
Sun, 30 Oct 2011 12:31:04 +0000 (14:31 +0200)
mtd tests may erase the mtd device, so force the user to specify which
mtd device to test by using the module parameter. Disable the default
(using mtd0) since this may destroy a vital part of the flash if the
module is inserted accidently or carelessly.

Reported-by: Roland Kletzing <devzero@web.de>
Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@intel.com>
drivers/mtd/tests/mtd_oobtest.c
drivers/mtd/tests/mtd_pagetest.c
drivers/mtd/tests/mtd_readtest.c
drivers/mtd/tests/mtd_speedtest.c
drivers/mtd/tests/mtd_stresstest.c
drivers/mtd/tests/mtd_subpagetest.c
drivers/mtd/tests/mtd_torturetest.c

index 6bcff42296a92db0acdf290a62242dd8de51603f..933f7e5f32d301a90f7256750b03c8a1542a9609 100644 (file)
@@ -30,7 +30,7 @@
 
 #define PRINT_PREF KERN_INFO "mtd_oobtest: "
 
-static int dev;
+static int dev = -EINVAL;
 module_param(dev, int, S_IRUGO);
 MODULE_PARM_DESC(dev, "MTD device number to use");
 
@@ -366,6 +366,13 @@ static int __init mtd_oobtest_init(void)
 
        printk(KERN_INFO "\n");
        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");
+               return -EINVAL;
+       }
+
        printk(PRINT_PREF "MTD device: %d\n", dev);
 
        mtd = get_mtd_device(NULL, dev);
index 186b14c02307d6348d54f930450dac8588eeba72..afafb6935fd0870707d13f9b7ea12cfbbb69af56 100644 (file)
@@ -30,7 +30,7 @@
 
 #define PRINT_PREF KERN_INFO "mtd_pagetest: "
 
-static int dev;
+static int dev = -EINVAL;
 module_param(dev, int, S_IRUGO);
 MODULE_PARM_DESC(dev, "MTD device number to use");
 
@@ -504,6 +504,13 @@ static int __init mtd_pagetest_init(void)
 
        printk(KERN_INFO "\n");
        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");
+               return -EINVAL;
+       }
+
        printk(PRINT_PREF "MTD device: %d\n", dev);
 
        mtd = get_mtd_device(NULL, dev);
index 756045345f009e5f6d4be831c48d67358512b86d..550fe51225a731bcc434ac04ef8890588521b0a6 100644 (file)
@@ -29,7 +29,7 @@
 
 #define PRINT_PREF KERN_INFO "mtd_readtest: "
 
-static int dev;
+static int dev = -EINVAL;
 module_param(dev, int, S_IRUGO);
 MODULE_PARM_DESC(dev, "MTD device number to use");
 
@@ -170,6 +170,12 @@ static int __init mtd_readtest_init(void)
 
        printk(KERN_INFO "\n");
        printk(KERN_INFO "=================================================\n");
+
+       if (dev < 0) {
+               printk(PRINT_PREF "Please specify a valid mtd-device via module paramter\n");
+               return -EINVAL;
+       }
+
        printk(PRINT_PREF "MTD device: %d\n", dev);
 
        mtd = get_mtd_device(NULL, dev);
index 79d53ee622951d19e84dbf619ccbdb5d5929d3d8..493b367bdd35211af2db7273d981398a938dd039 100644 (file)
@@ -29,7 +29,7 @@
 
 #define PRINT_PREF KERN_INFO "mtd_speedtest: "
 
-static int dev;
+static int dev = -EINVAL;
 module_param(dev, int, S_IRUGO);
 MODULE_PARM_DESC(dev, "MTD device number to use");
 
@@ -361,6 +361,13 @@ static int __init mtd_speedtest_init(void)
 
        printk(KERN_INFO "\n");
        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");
+               return -EINVAL;
+       }
+
        if (count)
                printk(PRINT_PREF "MTD device: %d    count: %d\n", dev, count);
        else
index 3c9008adbe3b9478598884f2d8c54a0abd11ecac..52ffd9120e0ded0eaf45d262cb4b6f115aad0ada 100644 (file)
@@ -30,7 +30,7 @@
 
 #define PRINT_PREF KERN_INFO "mtd_stresstest: "
 
-static int dev;
+static int dev = -EINVAL;
 module_param(dev, int, S_IRUGO);
 MODULE_PARM_DESC(dev, "MTD device number to use");
 
@@ -250,6 +250,13 @@ static int __init mtd_stresstest_init(void)
 
        printk(KERN_INFO "\n");
        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");
+               return -EINVAL;
+       }
+
        printk(PRINT_PREF "MTD device: %d\n", dev);
 
        mtd = get_mtd_device(NULL, dev);
index 2b51842d08faacc24d1cf3c9c234dfab3626af2a..1a05bfac4eeee5f6f9406b469ab27a74760c3cc8 100644 (file)
@@ -29,7 +29,7 @@
 
 #define PRINT_PREF KERN_INFO "mtd_subpagetest: "
 
-static int dev;
+static int dev = -EINVAL;
 module_param(dev, int, S_IRUGO);
 MODULE_PARM_DESC(dev, "MTD device number to use");
 
@@ -379,6 +379,13 @@ static int __init mtd_subpagetest_init(void)
 
        printk(KERN_INFO "\n");
        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");
+               return -EINVAL;
+       }
+
        printk(PRINT_PREF "MTD device: %d\n", dev);
 
        mtd = get_mtd_device(NULL, dev);
index 25786ce97c8e16c509f06272d10b10f891cba6dd..03ab649a6964292f50f40f9073c45ae097a47b8e 100644 (file)
@@ -46,7 +46,7 @@ static int pgcnt;
 module_param(pgcnt, int, S_IRUGO);
 MODULE_PARM_DESC(pgcnt, "number of pages per eraseblock to torture (0 => all)");
 
-static int dev;
+static int dev = -EINVAL;
 module_param(dev, int, S_IRUGO);
 MODULE_PARM_DESC(dev, "MTD device number to use");
 
@@ -213,6 +213,13 @@ static int __init tort_init(void)
        printk(KERN_INFO "=================================================\n");
        printk(PRINT_PREF "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");
+               return -EINVAL;
+       }
+
        printk(PRINT_PREF "MTD device: %d\n", dev);
        printk(PRINT_PREF "torture %d eraseblocks (%d-%d) of mtd%d\n",
               ebcnt, eb, eb + ebcnt - 1, dev);