forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/drivers/mtd/tests/torturetest.c
....@@ -1,20 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (C) 2006-2008 Artem Bityutskiy
34 * Copyright (C) 2006-2008 Jarkko Lavinen
45 * Copyright (C) 2006-2008 Adrian Hunter
5
- *
6
- * This program is free software; you can redistribute it and/or modify it
7
- * under the terms of the GNU General Public License version 2 as published by
8
- * the Free Software Foundation.
9
- *
10
- * This program is distributed in the hope that it will be useful, but WITHOUT
11
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13
- * more details.
14
- *
15
- * You should have received a copy of the GNU General Public License along with
16
- * this program; see the file COPYING. If not, write to the Free Software
17
- * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
186 *
197 * Authors: Artem Bityutskiy, Jarkko Lavinen, Adria Hunter
208 *
....@@ -31,6 +19,7 @@
3119 #include <linux/moduleparam.h>
3220 #include <linux/err.h>
3321 #include <linux/mtd/mtd.h>
22
+#include <linux/random.h>
3423 #include <linux/slab.h>
3524 #include <linux/sched.h>
3625 #include "mtd_test.h"
....@@ -66,8 +55,14 @@
6655 MODULE_PARM_DESC(cycles_count, "how many erase cycles to do "
6756 "(infinite by default)");
6857
58
+static int random_pattern;
59
+module_param(random_pattern, int, S_IRUGO);
60
+MODULE_PARM_DESC(random_pattern, "if choose random pattern to program");
61
+
6962 static struct mtd_info *mtd;
7063
64
+/* This buffer contains random pattern */
65
+static unsigned char *patt_random;
7166 /* This buffer contains 0x555555...0xAAAAAA... pattern */
7267 static unsigned char *patt_5A5;
7368 /* This buffer contains 0xAAAAAA...0x555555... pattern */
....@@ -222,9 +217,13 @@
222217 }
223218
224219 err = -ENOMEM;
220
+ patt_random = kmalloc(mtd->erasesize, GFP_KERNEL);
221
+ if (!patt_random)
222
+ goto out_mtd;
223
+
225224 patt_5A5 = kmalloc(mtd->erasesize, GFP_KERNEL);
226225 if (!patt_5A5)
227
- goto out_mtd;
226
+ goto out_patt_random;
228227
229228 patt_A5A = kmalloc(mtd->erasesize, GFP_KERNEL);
230229 if (!patt_A5A)
....@@ -255,6 +254,8 @@
255254 memset(patt_A5A + i * pgsize, 0x55, pgsize);
256255 }
257256 }
257
+
258
+ prandom_bytes(patt_random, mtd->erasesize);
258259
259260 err = mtdtest_scan_for_bad_eraseblocks(mtd, bad_ebs, eb, ebcnt);
260261 if (err)
....@@ -295,6 +296,8 @@
295296 patt = patt_5A5;
296297 else
297298 patt = patt_A5A;
299
+ if (random_pattern)
300
+ patt = patt_random;
298301 err = write_pattern(i, patt);
299302 if (err)
300303 goto out;
....@@ -313,8 +316,14 @@
313316 patt = patt_5A5;
314317 else
315318 patt = patt_A5A;
319
+ if (random_pattern)
320
+ patt = patt_random;
316321 err = check_eraseblock(i, patt);
317322 if (err) {
323
+ if (random_pattern) {
324
+ pr_info("verify failed for random pattern\n");
325
+ goto out;
326
+ }
318327 pr_info("verify failed for %s"
319328 " pattern\n",
320329 ((eb + erase_cycles) & 1) ?
....@@ -357,6 +366,8 @@
357366 kfree(patt_A5A);
358367 out_patt_5A5:
359368 kfree(patt_5A5);
369
+out_patt_random:
370
+ kfree(patt_random);
360371 out_mtd:
361372 put_mtd_device(mtd);
362373 if (err)