diff options
author | Hannes Frederic Sowa <hannes@stressinduktion.org> | 2013-10-23 14:05:27 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2013-10-25 19:03:39 -0400 |
commit | f84be2bd96a108b09c8440263fa3adb3fb225fa3 (patch) | |
tree | ad341d7bcd581cba4d38d39296692256d8a747d5 /net/core/utils.c | |
parent | 974daef7f8bb5d7be78fae3a240fcce43cae0135 (diff) |
net: make net_get_random_once irq safe
I initial build non irq safe version of net_get_random_once because I
would liked to have the freedom to defer even the extraction process of
get_random_bytes until the nonblocking pool is fully seeded.
I don't think this is a good idea anymore and thus this patch makes
net_get_random_once irq safe. Now someone using net_get_random_once does
not need to care from where it is called.
Cc: David S. Miller <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@google.com>
Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core/utils.c')
-rw-r--r-- | net/core/utils.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/net/core/utils.c b/net/core/utils.c index bf09371e19b1..2f737bf90b3f 100644 --- a/net/core/utils.c +++ b/net/core/utils.c | |||
@@ -370,16 +370,17 @@ bool __net_get_random_once(void *buf, int nbytes, bool *done, | |||
370 | struct static_key *done_key) | 370 | struct static_key *done_key) |
371 | { | 371 | { |
372 | static DEFINE_SPINLOCK(lock); | 372 | static DEFINE_SPINLOCK(lock); |
373 | unsigned long flags; | ||
373 | 374 | ||
374 | spin_lock_bh(&lock); | 375 | spin_lock_irqsave(&lock, flags); |
375 | if (*done) { | 376 | if (*done) { |
376 | spin_unlock_bh(&lock); | 377 | spin_unlock_irqrestore(&lock, flags); |
377 | return false; | 378 | return false; |
378 | } | 379 | } |
379 | 380 | ||
380 | get_random_bytes(buf, nbytes); | 381 | get_random_bytes(buf, nbytes); |
381 | *done = true; | 382 | *done = true; |
382 | spin_unlock_bh(&lock); | 383 | spin_unlock_irqrestore(&lock, flags); |
383 | 384 | ||
384 | __net_random_once_disable_jump(done_key); | 385 | __net_random_once_disable_jump(done_key); |
385 | 386 | ||