From: "Jason A. Donenfeld" <Jason@zx2c4.com>
To: Kees Cook <keescook@chromium.org>,
LKML <linux-kernel@vger.kernel.org>,
linux-crypto@vger.kernel.org, herbert@gondor.apana.org.au,
tytso@mit.edu, gregkh@linuxfoundation.org
Cc: "Jason A. Donenfeld" <Jason@zx2c4.com>
Subject: [PATCH 1/2] random: always call random ready function
Date: Thu, 19 Oct 2017 22:45:05 +0200 [thread overview]
Message-ID: <20171019204506.25090-1-Jason@zx2c4.com> (raw)
In-Reply-To: <CAHmME9qwoSwFi7fsg1Z+gcEh1fBY+KY2rJ81UTHYn2ZMcjjwFA@mail.gmail.com>
As this interface becomes more heavily used, it will be painful for
callers to always need to check for -EALREADY.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
drivers/char/random.c | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 8ad92707e45f..e161acf35d4a 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1556,40 +1556,45 @@ EXPORT_SYMBOL(wait_for_random_bytes);
/*
* Add a callback function that will be invoked when the nonblocking
- * pool is initialised.
+ * pool is initialised, or calls that function if it already is.
*
* returns: 0 if callback is successfully added
- * -EALREADY if pool is already initialised (callback not called)
* -ENOENT if module for callback is not alive
*/
int add_random_ready_callback(struct random_ready_callback *rdy)
{
struct module *owner;
unsigned long flags;
- int err = -EALREADY;
- if (crng_ready())
- return err;
+ BUG_ON(!rdy->func);
+
+ if (crng_ready()) {
+ rdy->func(rdy);
+ rdy->func = NULL;
+ return 0;
+ }
owner = rdy->owner;
if (!try_module_get(owner))
return -ENOENT;
spin_lock_irqsave(&random_ready_list_lock, flags);
- if (crng_ready())
+ if (crng_ready()) {
+ rdy->func(rdy);
+ rdy->func = NULL;
goto out;
+ }
owner = NULL;
list_add(&rdy->list, &random_ready_list);
- err = 0;
out:
spin_unlock_irqrestore(&random_ready_list_lock, flags);
module_put(owner);
- return err;
+ return 0;
}
EXPORT_SYMBOL(add_random_ready_callback);
@@ -1601,6 +1606,9 @@ void del_random_ready_callback(struct random_ready_callback *rdy)
unsigned long flags;
struct module *owner = NULL;
+ if (!rdy->func)
+ return;
+
spin_lock_irqsave(&random_ready_list_lock, flags);
if (!list_empty(&rdy->list)) {
list_del_init(&rdy->list);
--
2.14.2
next parent reply other threads:[~2017-10-19 20:45 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CAHmME9qwoSwFi7fsg1Z+gcEh1fBY+KY2rJ81UTHYn2ZMcjjwFA@mail.gmail.com>
2017-10-19 20:45 ` Jason A. Donenfeld [this message]
2017-10-19 20:45 ` [PATCH 2/2] crypto/drbg: account for no longer returning -EALREADY Jason A. Donenfeld
2017-10-21 19:22 ` Stephan Mueller
2017-10-19 20:45 ` [PATCH 1/2] random: always call random ready function Jason A. Donenfeld
2017-10-19 20:58 ` Kees Cook
2017-10-19 21:12 ` Jason A. Donenfeld
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=20171019204506.25090-1-Jason@zx2c4.com \
--to=jason@zx2c4.com \
--cc=gregkh@linuxfoundation.org \
--cc=herbert@gondor.apana.org.au \
--cc=keescook@chromium.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tytso@mit.edu \
/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