aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char
diff options
context:
space:
mode:
authorMatt Mackall <mpm@selenic.com>2009-01-06 17:42:55 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2009-01-06 18:59:30 -0500
commitcda796a3d572059d64f5429dfc1d00ca6fcbaf8d (patch)
tree622c2b4d01d99e6c26a4f0ea554f866151becb2f /drivers/char
parent71183c94804e8e19be32acccc8a019ffb445ec2b (diff)
random: don't try to look at entropy_count outside the lock
As a non-atomic value, it's only safe to look at entropy_count when the pool lock is held, so we move the BUG_ON inside the lock for correctness. Also remove the spurious comment. It's ok for entropy_count to temporarily exceed POOLBITS so long as it's left in a consistent state when the lock is released. This is a more correct, simple, and idiomatic fix for the bug in 8b76f46a2db. I've left the reorderings introduced by that patch in place as they're harmless, even though they don't properly deal with potential atomicity issues. Signed-off-by: Matt Mackall <mpm@selenic.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/char')
-rw-r--r--drivers/char/random.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/drivers/char/random.c b/drivers/char/random.c
index c7afc068c28d..7c13581ca9cd 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -407,7 +407,7 @@ struct entropy_store {
407 /* read-write data: */ 407 /* read-write data: */
408 spinlock_t lock; 408 spinlock_t lock;
409 unsigned add_ptr; 409 unsigned add_ptr;
410 int entropy_count; /* Must at no time exceed ->POOLBITS! */ 410 int entropy_count;
411 int input_rotate; 411 int input_rotate;
412}; 412};
413 413
@@ -767,11 +767,10 @@ static size_t account(struct entropy_store *r, size_t nbytes, int min,
767{ 767{
768 unsigned long flags; 768 unsigned long flags;
769 769
770 BUG_ON(r->entropy_count > r->poolinfo->POOLBITS);
771
772 /* Hold lock while accounting */ 770 /* Hold lock while accounting */
773 spin_lock_irqsave(&r->lock, flags); 771 spin_lock_irqsave(&r->lock, flags);
774 772
773 BUG_ON(r->entropy_count > r->poolinfo->POOLBITS);
775 DEBUG_ENT("trying to extract %d bits from %s\n", 774 DEBUG_ENT("trying to extract %d bits from %s\n",
776 nbytes * 8, r->name); 775 nbytes * 8, r->name);
777 776