mirror of
https://github.com/Fishwaldo/linux-bl808.git
synced 2025-06-17 20:25:19 +00:00
net: move net_get_random_once to lib
There's no good reason why users outside of networking should not be using this facility, f.e. for initializing their seeds. Therefore, make it accessible from there as get_random_once(). Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
28335a7445
commit
46234253b9
5 changed files with 84 additions and 67 deletions
24
include/linux/once.h
Normal file
24
include/linux/once.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
#ifndef _LINUX_ONCE_H
|
||||
#define _LINUX_ONCE_H
|
||||
|
||||
#include <linux/types.h>
|
||||
#include <linux/jump_label.h>
|
||||
|
||||
bool __get_random_once(void *buf, int nbytes, bool *done,
|
||||
struct static_key *once_key);
|
||||
|
||||
#define get_random_once(buf, nbytes) \
|
||||
({ \
|
||||
bool ___ret = false; \
|
||||
static bool ___done = false; \
|
||||
static struct static_key ___once_key = \
|
||||
STATIC_KEY_INIT_TRUE; \
|
||||
if (static_key_true(&___once_key)) \
|
||||
___ret = __get_random_once((buf), \
|
||||
(nbytes), \
|
||||
&___done, \
|
||||
&___once_key); \
|
||||
___ret; \
|
||||
})
|
||||
|
||||
#endif /* _LINUX_ONCE_H */
|
Loading…
Add table
Add a link
Reference in a new issue