From: Dominik Brodowski <linux@dominikbrodowski.net>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org,
"Jason A . Donenfeld" <Jason@zx2c4.com>
Subject: [PATCH 2/4] hw_random: start and stop in-kernel rngd in separate function
Date: Sun, 13 Feb 2022 21:46:29 +0100 [thread overview]
Message-ID: <20220213204631.354247-3-linux@dominikbrodowski.net> (raw)
In-Reply-To: <20220213204631.354247-1-linux@dominikbrodowski.net>
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: Dominik Brodowski <linux@dominikbrodowski.net>
---
drivers/char/hw_random/core.c | 24 ++++++++++++++----------
1 file changed, 14 insertions(+), 10 deletions(-)
diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c
index 6f09f4e5af20..29febf55b0d4 100644
--- a/drivers/char/hw_random/core.c
+++ b/drivers/char/hw_random/core.c
@@ -51,7 +51,7 @@ MODULE_PARM_DESC(default_quality,
static void drop_current_rng(void);
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,
int wait);
@@ -164,10 +164,7 @@ static int hwrng_init(struct hwrng *rng)
if (current_quality > 1024)
current_quality = 1024;
- if (current_quality == 0 && hwrng_fill)
- kthread_stop(hwrng_fill);
- if (current_quality > 0 && !hwrng_fill)
- start_khwrngd();
+ hwrng_manage_rngd();
return 0;
}
@@ -466,12 +463,19 @@ static int hwrng_fillfn(void *unused)
return 0;
}
-static void start_khwrngd(void)
+static void hwrng_manage_rngd(void)
{
- hwrng_fill = kthread_run(hwrng_fillfn, NULL, "hwrng");
- if (IS_ERR(hwrng_fill)) {
- pr_err("hwrng_fill thread creation failed\n");
- hwrng_fill = NULL;
+ if (WARN_ON(!mutex_is_locked(&rng_mutex)))
+ return;
+
+ 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;
+ }
}
}
--
2.35.1
next prev parent reply other threads:[~2022-02-13 20:50 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-13 20:46 [PATCH 0/4] hw_random: introduce rng_quality sysfs attribute Dominik Brodowski
2022-02-13 20:46 ` [PATCH 1/4] hw_random: do not bother to order list of devices by quality Dominik Brodowski
2022-02-13 20:46 ` Dominik Brodowski [this message]
2022-02-13 20:46 ` [PATCH 3/4] hw_random: use per-rng quality value instead of global setting Dominik Brodowski
2022-02-13 20:46 ` [PATCH 4/4] hw_random: introduce rng_quality sysfs attribute Dominik Brodowski
2022-02-23 2:45 ` [PATCH 0/4] " Herbert Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220213204631.354247-3-linux@dominikbrodowski.net \
--to=linux@dominikbrodowski.net \
--cc=Jason@zx2c4.com \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®