Commit aca662a3 authored by Akinobu Mita's avatar Akinobu Mita Committed by Artem Bityutskiy

mtd: rename random32() to prandom_u32()

Use more preferable function name which implies using a pseudo-random
number generator.
Signed-off-by: default avatarAkinobu Mita <akinobu.mita@gmail.com>
Signed-off-by: default avatarArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
parent bd6ce5ef
...@@ -1476,12 +1476,12 @@ int do_read_error(struct nandsim *ns, int num) ...@@ -1476,12 +1476,12 @@ int do_read_error(struct nandsim *ns, int num)
void do_bit_flips(struct nandsim *ns, int num) void do_bit_flips(struct nandsim *ns, int num)
{ {
if (bitflips && random32() < (1 << 22)) { if (bitflips && prandom_u32() < (1 << 22)) {
int flips = 1; int flips = 1;
if (bitflips > 1) if (bitflips > 1)
flips = (random32() % (int) bitflips) + 1; flips = (prandom_u32() % (int) bitflips) + 1;
while (flips--) { while (flips--) {
int pos = random32() % (num * 8); int pos = prandom_u32() % (num * 8);
ns->buf.byte[pos / 8] ^= (1 << (pos % 8)); ns->buf.byte[pos / 8] ^= (1 << (pos % 8));
NS_WARN("read_page: flipping bit %d in page %d " NS_WARN("read_page: flipping bit %d in page %d "
"reading from %d ecc: corrected=%u failed=%u\n", "reading from %d ecc: corrected=%u failed=%u\n",
......
...@@ -44,7 +44,7 @@ struct nand_ecc_test { ...@@ -44,7 +44,7 @@ struct nand_ecc_test {
static void single_bit_error_data(void *error_data, void *correct_data, static void single_bit_error_data(void *error_data, void *correct_data,
size_t size) size_t size)
{ {
unsigned int offset = random32() % (size * BITS_PER_BYTE); unsigned int offset = prandom_u32() % (size * BITS_PER_BYTE);
memcpy(error_data, correct_data, size); memcpy(error_data, correct_data, size);
__change_bit_le(offset, error_data); __change_bit_le(offset, error_data);
...@@ -55,9 +55,9 @@ static void double_bit_error_data(void *error_data, void *correct_data, ...@@ -55,9 +55,9 @@ static void double_bit_error_data(void *error_data, void *correct_data,
{ {
unsigned int offset[2]; unsigned int offset[2];
offset[0] = random32() % (size * BITS_PER_BYTE); offset[0] = prandom_u32() % (size * BITS_PER_BYTE);
do { do {
offset[1] = random32() % (size * BITS_PER_BYTE); offset[1] = prandom_u32() % (size * BITS_PER_BYTE);
} while (offset[0] == offset[1]); } while (offset[0] == offset[1]);
memcpy(error_data, correct_data, size); memcpy(error_data, correct_data, size);
...@@ -68,7 +68,7 @@ static void double_bit_error_data(void *error_data, void *correct_data, ...@@ -68,7 +68,7 @@ static void double_bit_error_data(void *error_data, void *correct_data,
static unsigned int random_ecc_bit(size_t size) static unsigned int random_ecc_bit(size_t size)
{ {
unsigned int offset = random32() % (3 * BITS_PER_BYTE); unsigned int offset = prandom_u32() % (3 * BITS_PER_BYTE);
if (size == 256) { if (size == 256) {
/* /*
...@@ -76,7 +76,7 @@ static unsigned int random_ecc_bit(size_t size) ...@@ -76,7 +76,7 @@ static unsigned int random_ecc_bit(size_t size)
* and 17th bit) in ECC code for 256 byte data block * and 17th bit) in ECC code for 256 byte data block
*/ */
while (offset == 16 || offset == 17) while (offset == 16 || offset == 17)
offset = random32() % (3 * BITS_PER_BYTE); offset = prandom_u32() % (3 * BITS_PER_BYTE);
} }
return offset; return offset;
......
...@@ -55,7 +55,7 @@ static int rand_eb(void) ...@@ -55,7 +55,7 @@ static int rand_eb(void)
unsigned int eb; unsigned int eb;
again: again:
eb = random32(); eb = prandom_u32();
/* Read or write up 2 eraseblocks at a time - hence 'ebcnt - 1' */ /* Read or write up 2 eraseblocks at a time - hence 'ebcnt - 1' */
eb %= (ebcnt - 1); eb %= (ebcnt - 1);
if (bbt[eb]) if (bbt[eb])
...@@ -67,7 +67,7 @@ static int rand_offs(void) ...@@ -67,7 +67,7 @@ static int rand_offs(void)
{ {
unsigned int offs; unsigned int offs;
offs = random32(); offs = prandom_u32();
offs %= bufsize; offs %= bufsize;
return offs; return offs;
} }
...@@ -76,7 +76,7 @@ static int rand_len(int offs) ...@@ -76,7 +76,7 @@ static int rand_len(int offs)
{ {
unsigned int len; unsigned int len;
len = random32(); len = prandom_u32();
len %= (bufsize - offs); len %= (bufsize - offs);
return len; return len;
} }
...@@ -191,7 +191,7 @@ static int do_write(void) ...@@ -191,7 +191,7 @@ static int do_write(void)
static int do_operation(void) static int do_operation(void)
{ {
if (random32() & 1) if (prandom_u32() & 1)
return do_read(); return do_read();
else else
return do_write(); return do_write();
......
...@@ -86,7 +86,7 @@ static inline int ubi_dbg_is_bgt_disabled(const struct ubi_device *ubi) ...@@ -86,7 +86,7 @@ static inline int ubi_dbg_is_bgt_disabled(const struct ubi_device *ubi)
static inline int ubi_dbg_is_bitflip(const struct ubi_device *ubi) static inline int ubi_dbg_is_bitflip(const struct ubi_device *ubi)
{ {
if (ubi->dbg.emulate_bitflips) if (ubi->dbg.emulate_bitflips)
return !(random32() % 200); return !(prandom_u32() % 200);
return 0; return 0;
} }
...@@ -100,7 +100,7 @@ static inline int ubi_dbg_is_bitflip(const struct ubi_device *ubi) ...@@ -100,7 +100,7 @@ static inline int ubi_dbg_is_bitflip(const struct ubi_device *ubi)
static inline int ubi_dbg_is_write_failure(const struct ubi_device *ubi) static inline int ubi_dbg_is_write_failure(const struct ubi_device *ubi)
{ {
if (ubi->dbg.emulate_io_failures) if (ubi->dbg.emulate_io_failures)
return !(random32() % 500); return !(prandom_u32() % 500);
return 0; return 0;
} }
...@@ -114,7 +114,7 @@ static inline int ubi_dbg_is_write_failure(const struct ubi_device *ubi) ...@@ -114,7 +114,7 @@ static inline int ubi_dbg_is_write_failure(const struct ubi_device *ubi)
static inline int ubi_dbg_is_erase_failure(const struct ubi_device *ubi) static inline int ubi_dbg_is_erase_failure(const struct ubi_device *ubi)
{ {
if (ubi->dbg.emulate_io_failures) if (ubi->dbg.emulate_io_failures)
return !(random32() % 400); return !(prandom_u32() % 400);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment