2
0
mirror of https://github.com/edk2-porting/linux-next.git synced 2024-12-14 00:04:00 +08:00

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>
This commit is contained in:
Hannes Frederic Sowa 2013-10-23 20:05:27 +02:00 committed by David S. Miller
parent 974daef7f8
commit f84be2bd96
2 changed files with 4 additions and 4 deletions

View File

@ -250,7 +250,6 @@ bool __net_get_random_once(void *buf, int nbytes, bool *done,
#define ___NET_RANDOM_STATIC_KEY_INIT STATIC_KEY_INIT_FALSE #define ___NET_RANDOM_STATIC_KEY_INIT STATIC_KEY_INIT_FALSE
#endif /* HAVE_JUMP_LABEL */ #endif /* HAVE_JUMP_LABEL */
/* BE CAREFUL: this function is not interrupt safe */
#define net_get_random_once(buf, nbytes) \ #define net_get_random_once(buf, nbytes) \
({ \ ({ \
bool ___ret = false; \ bool ___ret = false; \

View File

@ -370,16 +370,17 @@ bool __net_get_random_once(void *buf, int nbytes, bool *done,
struct static_key *done_key) struct static_key *done_key)
{ {
static DEFINE_SPINLOCK(lock); static DEFINE_SPINLOCK(lock);
unsigned long flags;
spin_lock_bh(&lock); spin_lock_irqsave(&lock, flags);
if (*done) { if (*done) {
spin_unlock_bh(&lock); spin_unlock_irqrestore(&lock, flags);
return false; return false;
} }
get_random_bytes(buf, nbytes); get_random_bytes(buf, nbytes);
*done = true; *done = true;
spin_unlock_bh(&lock); spin_unlock_irqrestore(&lock, flags);
__net_random_once_disable_jump(done_key); __net_random_once_disable_jump(done_key);