Commit 077bb7a1 authored by Dominik Brodowski's avatar Dominik Brodowski Committed by Herbert Xu

hwrng: core - start and stop in-kernel rngd in separate function

Extract the start/stop logic for the in-kernel rngd thread to
a separate function.

Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: default avatarDominik Brodowski <linux@dominikbrodowski.net>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent c90e4539
...@@ -51,7 +51,7 @@ MODULE_PARM_DESC(default_quality, ...@@ -51,7 +51,7 @@ MODULE_PARM_DESC(default_quality,
static void drop_current_rng(void); static void drop_current_rng(void);
static int hwrng_init(struct hwrng *rng); static int hwrng_init(struct hwrng *rng);
static void start_khwrngd(void); static void hwrng_manage_rngd(void);
static inline int rng_get_data(struct hwrng *rng, u8 *buffer, size_t size, static inline int rng_get_data(struct hwrng *rng, u8 *buffer, size_t size,
int wait); int wait);
...@@ -164,10 +164,7 @@ static int hwrng_init(struct hwrng *rng) ...@@ -164,10 +164,7 @@ static int hwrng_init(struct hwrng *rng)
if (current_quality > 1024) if (current_quality > 1024)
current_quality = 1024; current_quality = 1024;
if (current_quality == 0 && hwrng_fill) hwrng_manage_rngd();
kthread_stop(hwrng_fill);
if (current_quality > 0 && !hwrng_fill)
start_khwrngd();
return 0; return 0;
} }
...@@ -466,12 +463,19 @@ static int hwrng_fillfn(void *unused) ...@@ -466,12 +463,19 @@ static int hwrng_fillfn(void *unused)
return 0; return 0;
} }
static void start_khwrngd(void) static void hwrng_manage_rngd(void)
{ {
hwrng_fill = kthread_run(hwrng_fillfn, NULL, "hwrng"); if (WARN_ON(!mutex_is_locked(&rng_mutex)))
if (IS_ERR(hwrng_fill)) { return;
pr_err("hwrng_fill thread creation failed\n");
hwrng_fill = NULL; if (current_quality == 0 && hwrng_fill)
kthread_stop(hwrng_fill);
if (current_quality > 0 && !hwrng_fill) {
hwrng_fill = kthread_run(hwrng_fillfn, NULL, "hwrng");
if (IS_ERR(hwrng_fill)) {
pr_err("hwrng_fill thread creation failed\n");
hwrng_fill = NULL;
}
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment