Messages in this thread Patch in this message | | | Date | Thu, 7 Nov 2013 18:59:21 -0500 | From | Greg Price <> | Subject | [PATCH 08/11] 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.)
Which is a good thing, too, because the "entropy_count = reserved" line would have had a bug otherwise -- 'reserved' counts bytes and 'entropy_count' counts bits. Fortunately that line could only be reached if 'r->limit' was false, and zero bytes is zero bits.
Cc: "Theodore Ts'o" <tytso@mit.edu> Cc: Jiri Kosina <jkosina@suse.cz> Signed-off-by: Greg Price <price@mit.edu> --- drivers/char/random.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/drivers/char/random.c b/drivers/char/random.c index 8824e8d..9e4645e 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -860,12 +860,7 @@ retry: /* If limited, never pull more than available */ if (r->limit) nbytes = min_t(size_t, nbytes, entropy_count/8 - reserved); - - if (entropy_count / 8 >= nbytes + reserved) { - entropy_count -= nbytes*8; - } else { - entropy_count = reserved; - } + entropy_count = max_t(int, entropy_count - nbytes*8, 0); if (cmpxchg(&r->entropy_count, orig, entropy_count) != orig) goto retry; -- 1.8.3.2
| |