Skip to content

Commit

Permalink
random: add 8-bit and 16-bit batches
Browse files Browse the repository at this point in the history
There are numerous places in the kernel that would be sped up by having
smaller batches. Currently those callsites do `get_random_u32() & 0xff`
or similar. Since these are pretty spread out, and will require patches
to multiple different trees, let's get ahead of the curve and lay the
foundation for `get_random_u8()` and `get_random_u16()`, so that it's
then possible to start submitting conversion patches leisurely.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
  • Loading branch information
Jason A. Donenfeld authored and Jason A. Donenfeld committed Sep 29, 2022
1 parent 37608ba commit 585cd5f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions drivers/char/random.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,8 @@ EXPORT_SYMBOL(get_random_ ##type);

DEFINE_BATCHED_ENTROPY(u64)
DEFINE_BATCHED_ENTROPY(u32)
DEFINE_BATCHED_ENTROPY(u16)
DEFINE_BATCHED_ENTROPY(u8)

#ifdef CONFIG_SMP
/*
Expand Down
2 changes: 2 additions & 0 deletions include/linux/random.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ static inline int unregister_random_vmfork_notifier(struct notifier_block *nb) {
#endif

void get_random_bytes(void *buf, size_t len);
u8 get_random_u8(void);
u16 get_random_u16(void);
u32 get_random_u32(void);
u64 get_random_u64(void);
static inline unsigned int get_random_int(void)
Expand Down

0 comments on commit 585cd5f

Please sign in to comment.