diff --git a/include/linux/net.h b/include/linux/net.h index aca446b46754fe681dcb0fb99028ac62c90a68fe..b292a04355717a503b093e2d2c424cf92951415f 100644 --- a/include/linux/net.h +++ b/include/linux/net.h @@ -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 #endif /* HAVE_JUMP_LABEL */ -/* BE CAREFUL: this function is not interrupt safe */ #define net_get_random_once(buf, nbytes) \ ({ \ bool ___ret = false; \ diff --git a/net/core/utils.c b/net/core/utils.c index bf09371e19b146369a6c580e52700588440adf49..2f737bf90b3fe4235c75ccca6640c735ecaa076b 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, struct static_key *done_key) { static DEFINE_SPINLOCK(lock); + unsigned long flags; - spin_lock_bh(&lock); + spin_lock_irqsave(&lock, flags); if (*done) { - spin_unlock_bh(&lock); + spin_unlock_irqrestore(&lock, flags); return false; } get_random_bytes(buf, nbytes); *done = true; - spin_unlock_bh(&lock); + spin_unlock_irqrestore(&lock, flags); __net_random_once_disable_jump(done_key);