diff options
author | Theodore Ts'o <tytso@mit.edu> | 2013-11-08 00:14:53 -0500 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2013-11-08 00:14:53 -0500 |
commit | dd1f723bf56bd96efc9d90e9e60dc511c79de48f (patch) | |
tree | 3860500165c69c225ccd5121f2ffde93dfbf4f02 | |
parent | f2754114400afe38ad5ade3b588451c4f36a61af (diff) |
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>
-rw-r--r-- | fs/ext4/ialloc.c | 2 | ||||
-rw-r--r-- | fs/ext4/mmp.c | 2 | ||||
-rw-r--r-- | fs/ext4/super.c | 7 |
3 files changed, 4 insertions, 7 deletions
diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c index 137193ff389b..0ee59a6644e2 100644 --- a/fs/ext4/ialloc.c +++ b/fs/ext4/ialloc.c | |||
@@ -432,7 +432,7 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent, | |||
432 | ext4fs_dirhash(qstr->name, qstr->len, &hinfo); | 432 | ext4fs_dirhash(qstr->name, qstr->len, &hinfo); |
433 | grp = hinfo.hash; | 433 | grp = hinfo.hash; |
434 | } else | 434 | } else |
435 | get_random_bytes(&grp, sizeof(grp)); | 435 | grp = prandom_u32(); |
436 | parent_group = (unsigned)grp % ngroups; | 436 | parent_group = (unsigned)grp % ngroups; |
437 | for (i = 0; i < ngroups; i++) { | 437 | for (i = 0; i < ngroups; i++) { |
438 | g = (parent_group + i) % ngroups; | 438 | g = (parent_group + i) % ngroups; |
diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c index 214461e42a05..04434ad3e8e0 100644 --- a/fs/ext4/mmp.c +++ b/fs/ext4/mmp.c | |||
@@ -259,7 +259,7 @@ static unsigned int mmp_new_seq(void) | |||
259 | u32 new_seq; | 259 | u32 new_seq; |
260 | 260 | ||
261 | do { | 261 | do { |
262 | get_random_bytes(&new_seq, sizeof(u32)); | 262 | new_seq = prandom_u32(); |
263 | } while (new_seq > EXT4_MMP_SEQ_MAX); | 263 | } while (new_seq > EXT4_MMP_SEQ_MAX); |
264 | 264 | ||
265 | return new_seq; | 265 | return new_seq; |
diff --git a/fs/ext4/super.c b/fs/ext4/super.c index d3a857bfae47..c977f4e4e63b 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c | |||
@@ -3068,7 +3068,6 @@ static struct ext4_li_request *ext4_li_request_new(struct super_block *sb, | |||
3068 | { | 3068 | { |
3069 | struct ext4_sb_info *sbi = EXT4_SB(sb); | 3069 | struct ext4_sb_info *sbi = EXT4_SB(sb); |
3070 | struct ext4_li_request *elr; | 3070 | struct ext4_li_request *elr; |
3071 | unsigned long rnd; | ||
3072 | 3071 | ||
3073 | elr = kzalloc(sizeof(*elr), GFP_KERNEL); | 3072 | elr = kzalloc(sizeof(*elr), GFP_KERNEL); |
3074 | if (!elr) | 3073 | if (!elr) |
@@ -3083,10 +3082,8 @@ static struct ext4_li_request *ext4_li_request_new(struct super_block *sb, | |||
3083 | * spread the inode table initialization requests | 3082 | * spread the inode table initialization requests |
3084 | * better. | 3083 | * better. |
3085 | */ | 3084 | */ |
3086 | get_random_bytes(&rnd, sizeof(rnd)); | 3085 | elr->lr_next_sched = jiffies + (prandom_u32() % |
3087 | elr->lr_next_sched = jiffies + (unsigned long)rnd % | 3086 | (EXT4_DEF_LI_MAX_START_DELAY * HZ)); |
3088 | (EXT4_DEF_LI_MAX_START_DELAY * HZ); | ||
3089 | |||
3090 | return elr; | 3087 | return elr; |
3091 | } | 3088 | } |
3092 | 3089 | ||