Thread (26 messages) 26 messages, 3 authors, 2015-06-05

Re: [PATCH v6 1/5] random: Blocking API for accessing nonblocking_pool

From: Herbert Xu <herbert@gondor.apana.org.au>
Date: 2015-05-19 22:55:47
Also in: lkml

On Tue, May 19, 2015 at 04:36:58PM +0200, Stephan Mueller wrote:
quoted hunk ↗ jump to hunk
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 9cd6968..6f71354 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1245,6 +1245,20 @@ void get_random_bytes(void *buf, int nbytes)
 EXPORT_SYMBOL(get_random_bytes);
 
 /*
+ * Equivalent function to get_random_bytes with the difference that this
+ * function blocks the request until the nonblocking_pool is initialized.
+ */
+void get_blocking_random_bytes(void *buf, int nbytes)
+{
+       if (unlikely(nonblocking_pool.initialized == 0))
+               wait_event_interruptible(urandom_init_wait,
+                                        nonblocking_pool.initialized);
+       extract_entropy(&nonblocking_pool, buf, nbytes, 0, 0);
+}
+EXPORT_SYMBOL(get_blocking_random_bytes);
You still need to handle the case where wait_event_interruptible
returns an error.  Otherwise this looks fine.

Thanks,
-- 
Email: Herbert Xu [off-list ref]
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help