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" <ty...@mit.edu> Cc: Jiri Kosina <jkos...@suse.cz> Signed-off-by: Greg Price <pr...@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 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/