summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/char/random.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 73e52b7796f9..35487e8ded59 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -865,16 +865,24 @@ static size_t account(struct entropy_store *r, size_t nbytes, int min,
865 if (r->entropy_count / 8 < min + reserved) { 865 if (r->entropy_count / 8 < min + reserved) {
866 nbytes = 0; 866 nbytes = 0;
867 } else { 867 } else {
868 int entropy_count, orig;
869retry:
870 entropy_count = orig = ACCESS_ONCE(r->entropy_count);
868 /* If limited, never pull more than available */ 871 /* If limited, never pull more than available */
869 if (r->limit && nbytes + reserved >= r->entropy_count / 8) 872 if (r->limit && nbytes + reserved >= entropy_count / 8)
870 nbytes = r->entropy_count/8 - reserved; 873 nbytes = entropy_count/8 - reserved;
871 874
872 if (r->entropy_count / 8 >= nbytes + reserved) 875 if (entropy_count / 8 >= nbytes + reserved) {
873 r->entropy_count -= nbytes*8; 876 entropy_count -= nbytes*8;
874 else 877 if (cmpxchg(&r->entropy_count, orig, entropy_count) != orig)
875 r->entropy_count = reserved; 878 goto retry;
879 } else {
880 entropy_count = reserved;
881 if (cmpxchg(&r->entropy_count, orig, entropy_count) != orig)
882 goto retry;
883 }
876 884
877 if (r->entropy_count < random_write_wakeup_thresh) 885 if (entropy_count < random_write_wakeup_thresh)
878 wakeup_write = 1; 886 wakeup_write = 1;
879 } 887 }
880 888