[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20131107235920.GK16018@ringworld.MIT.EDU>
Date: Thu, 7 Nov 2013 18:59:21 -0500
From: Greg Price <price@....EDU>
To: "Theodore Ts'o" <tytso@....edu>
Cc: linux-kernel@...r.kernel.org, Jiri Kosina <jkosina@...e.cz>
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@....edu>
Cc: Jiri Kosina <jkosina@...e.cz>
Signed-off-by: Greg Price <price@....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 majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists