aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/char/random.c27
1 files changed, 10 insertions, 17 deletions
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 70b8ebf08edd..ded4339be8f9 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -964,8 +964,6 @@ static void push_to_pool(struct work_struct *work)
964static size_t account(struct entropy_store *r, size_t nbytes, int min, 964static size_t account(struct entropy_store *r, size_t nbytes, int min,
965 int reserved) 965 int reserved)
966{ 966{
967 unsigned long flags;
968 int wakeup_write = 0;
969 int have_bytes; 967 int have_bytes;
970 int entropy_count, orig; 968 int entropy_count, orig;
971 size_t ibytes; 969 size_t ibytes;
@@ -977,24 +975,19 @@ retry:
977 entropy_count = orig = ACCESS_ONCE(r->entropy_count); 975 entropy_count = orig = ACCESS_ONCE(r->entropy_count);
978 have_bytes = entropy_count >> (ENTROPY_SHIFT + 3); 976 have_bytes = entropy_count >> (ENTROPY_SHIFT + 3);
979 ibytes = nbytes; 977 ibytes = nbytes;
980 if (have_bytes < min + reserved) { 978 /* If limited, never pull more than available */
979 if (r->limit)
980 ibytes = min_t(size_t, ibytes, have_bytes - reserved);
981 if (ibytes < min)
981 ibytes = 0; 982 ibytes = 0;
982 } else { 983 entropy_count = max_t(int, 0,
983 /* If limited, never pull more than available */ 984 entropy_count - (ibytes << (ENTROPY_SHIFT + 3)));
984 if (r->limit) 985 if (cmpxchg(&r->entropy_count, orig, entropy_count) != orig)
985 ibytes = min_t(size_t, ibytes, have_bytes - reserved); 986 goto retry;
986 entropy_count = max_t(int, 0,
987 entropy_count - (ibytes << (ENTROPY_SHIFT + 3)));
988 if (cmpxchg(&r->entropy_count, orig, entropy_count) != orig)
989 goto retry;
990
991 if ((r->entropy_count >> ENTROPY_SHIFT)
992 < random_write_wakeup_thresh)
993 wakeup_write = 1;
994 }
995 987
996 trace_debit_entropy(r->name, 8 * ibytes); 988 trace_debit_entropy(r->name, 8 * ibytes);
997 if (wakeup_write) { 989 if (ibytes &&
990 (r->entropy_count >> ENTROPY_SHIFT) < random_write_wakeup_thresh) {
998 wake_up_interruptible(&random_write_wait); 991 wake_up_interruptible(&random_write_wait);
999 kill_fasync(&fasync, SIGIO, POLL_OUT); 992 kill_fasync(&fasync, SIGIO, POLL_OUT);
1000 } 993 }