Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0c21fd6e authored by Linus Torvalds's avatar Linus Torvalds
Browse files
Pull /dev/random updates from Ted Ts'o:
 "A few random (cough, cough) cleanups for the /dev/random driver"

* tag 'random_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/random:
  drivers/char/random.c: remove unused dont_count_entropy
  random: optimize add_interrupt_randomness
  random: always fill buffer in get_random_bytes_wait
  random: use a tighter cap in credit_entropy_bits_safe()
parents 3e968c9f 5e747dd9
Loading
Loading
Loading
Loading
+28 −30
Original line number Diff line number Diff line
@@ -709,7 +709,8 @@ static void credit_entropy_bits(struct entropy_store *r, int nbits)
		}

		/* should we wake readers? */
		if (entropy_bits >= random_read_wakeup_bits) {
		if (entropy_bits >= random_read_wakeup_bits &&
		    wq_has_sleeper(&random_read_wait)) {
			wake_up_interruptible(&random_read_wait);
			kill_fasync(&fasync, SIGIO, POLL_IN);
		}
@@ -732,7 +733,7 @@ static void credit_entropy_bits(struct entropy_store *r, int nbits)

static int credit_entropy_bits_safe(struct entropy_store *r, int nbits)
{
	const int nbits_max = (int)(~0U >> (ENTROPY_SHIFT + 1));
	const int nbits_max = r->poolinfo->poolwords * 32;

	if (nbits < 0)
		return -EINVAL;
@@ -963,7 +964,6 @@ static ssize_t extract_crng_user(void __user *buf, size_t nbytes)
struct timer_rand_state {
	cycles_t last_time;
	long last_delta, last_delta2;
	unsigned dont_count_entropy:1;
};

#define INIT_TIMER_RAND_STATE { INITIAL_JIFFIES, };
@@ -1029,8 +1029,6 @@ static void add_timer_randomness(struct timer_rand_state *state, unsigned num)
	 * We take into account the first, second and third-order deltas
	 * in order to make our estimate.
	 */

	if (!state->dont_count_entropy) {
	delta = sample.jiffies - state->last_time;
	state->last_time = sample.jiffies;

@@ -1057,7 +1055,7 @@ static void add_timer_randomness(struct timer_rand_state *state, unsigned num)
	 * and limit entropy entimate to 12 bits.
	 */
	credit_entropy_bits(r, min_t(int, fls(delta>>1), 11));
	}

	preempt_enable();
}

+1 −3
Original line number Diff line number Diff line
@@ -85,10 +85,8 @@ static inline unsigned long get_random_canary(void)
static inline int get_random_bytes_wait(void *buf, int nbytes)
{
	int ret = wait_for_random_bytes();
	if (unlikely(ret))
		return ret;
	get_random_bytes(buf, nbytes);
	return 0;
	return ret;
}

#define declare_get_random_var_wait(var) \