From 695642923624bc00853d808e7b7f52d5fbf93b6a Mon Sep 17 00:00:00 2001 From: Keunyoung Park Date: Mon, 29 Jan 2018 13:24:09 +0900 Subject: [PATCH] [COMMON] hw_random: make khwrngd freezable Change-Id: I8bc0b1561dc8b3d36fec860b0b969129326c334d Signed-off-by: Keunyoung Park --- drivers/char/hw_random/core.c | 3 +++ drivers/char/random.c | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c index 9701ac7d8b47..2b512ca91f81 100644 --- a/drivers/char/hw_random/core.c +++ b/drivers/char/hw_random/core.c @@ -24,6 +24,7 @@ #include #include #include +#include #define RNG_MODULE_NAME "hw_random" @@ -395,6 +396,8 @@ static int hwrng_fillfn(void *unused) { long rc; + set_freezable(); + while (!kthread_should_stop()) { struct hwrng *rng; diff --git a/drivers/char/random.c b/drivers/char/random.c index ea0115cf5fc0..5c3f1110d08f 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -264,6 +264,7 @@ #include #include #include +#include #include #include @@ -1632,7 +1633,7 @@ void get_random_bytes_arch(void *buf, int nbytes) if (!arch_get_random_long(&v)) break; - + memcpy(p, &v, chunk); p += chunk; nbytes -= chunk; @@ -2223,7 +2224,7 @@ void add_hwgenerator_randomness(const char *buffer, size_t count, * We'll be woken up again once below random_write_wakeup_thresh, * or when the calling thread is about to terminate. */ - wait_event_interruptible(random_write_wait, kthread_should_stop() || + wait_event_freezable(random_write_wait, kthread_should_stop() || ENTROPY_BITS(&input_pool) <= random_write_wakeup_bits); mix_pool_bytes(poolp, buffer, count); credit_entropy_bits(poolp, entropy); -- 2.20.1