Commit dd1f723bf56bd96efc9d90e9e60dc511c79de48f

Authored by Theodore Ts'o
1 parent f275411440

ext4: use prandom_u32() instead of get_random_bytes()

Many of the uses of get_random_bytes() do not actually need
cryptographically secure random numbers.  Replace those uses with a
call to prandom_u32(), which is faster and which doesn't consume
entropy from the /dev/random driver.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>

Showing 3 changed files with 4 additions and 7 deletions Side-by-side Diff

... ... @@ -432,7 +432,7 @@
432 432 ext4fs_dirhash(qstr->name, qstr->len, &hinfo);
433 433 grp = hinfo.hash;
434 434 } else
435   - get_random_bytes(&grp, sizeof(grp));
  435 + grp = prandom_u32();
436 436 parent_group = (unsigned)grp % ngroups;
437 437 for (i = 0; i < ngroups; i++) {
438 438 g = (parent_group + i) % ngroups;
... ... @@ -259,7 +259,7 @@
259 259 u32 new_seq;
260 260  
261 261 do {
262   - get_random_bytes(&new_seq, sizeof(u32));
  262 + new_seq = prandom_u32();
263 263 } while (new_seq > EXT4_MMP_SEQ_MAX);
264 264  
265 265 return new_seq;
... ... @@ -3068,7 +3068,6 @@
3068 3068 {
3069 3069 struct ext4_sb_info *sbi = EXT4_SB(sb);
3070 3070 struct ext4_li_request *elr;
3071   - unsigned long rnd;
3072 3071  
3073 3072 elr = kzalloc(sizeof(*elr), GFP_KERNEL);
3074 3073 if (!elr)
... ... @@ -3083,10 +3082,8 @@
3083 3082 * spread the inode table initialization requests
3084 3083 * better.
3085 3084 */
3086   - get_random_bytes(&rnd, sizeof(rnd));
3087   - elr->lr_next_sched = jiffies + (unsigned long)rnd %
3088   - (EXT4_DEF_LI_MAX_START_DELAY * HZ);
3089   -
  3085 + elr->lr_next_sched = jiffies + (prandom_u32() %
  3086 + (EXT4_DEF_LI_MAX_START_DELAY * HZ));
3090 3087 return elr;
3091 3088 }
3092 3089