summaryrefslogtreecommitdiff
path: root/drivers/char/random.c
diff options
context:
space:
mode:
authorGreg Price <price@MIT.EDU>2013-11-30 00:56:16 +0400
committerTheodore Ts'o <tytso@mit.edu>2014-03-20 06:18:51 +0400
commitee1de406ba6eb1e01f143fe3351e70cc772cc63e (patch)
tree9e2cd3196e964515cfcfbfcfe343201b42cfe6c9 /drivers/char/random.c
parent19fa5be1d92be3112521145bf99f77007abf6b16 (diff)
downloadlinux-ee1de406ba6eb1e01f143fe3351e70cc772cc63e.tar.xz
random: simplify accounting logic
This logic is exactly equivalent to the old logic, but it should be easier to see what it's doing. The equivalence depends on one fact from outside this function: when 'r->limit' is false, 'reserved' is zero. (Well, two facts; the other is that 'reserved' is never negative.) Cc: Jiri Kosina <jkosina@suse.cz> Cc: "H. Peter Anvin" <hpa@zytor.com> Signed-off-by: Greg Price <price@mit.edu> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Diffstat (limited to 'drivers/char/random.c')
-rw-r--r--drivers/char/random.c12
1 files changed, 4 insertions, 8 deletions
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 2c532a6b0a21..9675821b4b5a 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -984,14 +984,10 @@ retry:
ibytes = 0;
} else {
/* If limited, never pull more than available */
- if (r->limit && ibytes + reserved >= have_bytes)
- ibytes = have_bytes - reserved;
-
- if (have_bytes >= ibytes + reserved)
- entropy_count -= ibytes << (ENTROPY_SHIFT + 3);
- else
- entropy_count = reserved << (ENTROPY_SHIFT + 3);
-
+ if (r->limit)
+ ibytes = min_t(size_t, ibytes, have_bytes - reserved);
+ entropy_count = max_t(int, 0,
+ entropy_count - (ibytes << (ENTROPY_SHIFT + 3)));
if (cmpxchg(&r->entropy_count, orig, entropy_count) != orig)
goto retry;