]> git.baikalelectronics.ru Git - kernel.git/commit
prandom: make use of smaller types in prandom_u32_max
authorJason A. Donenfeld <Jason@zx2c4.com>
Thu, 29 Sep 2022 09:49:35 +0000 (11:49 +0200)
committerJason A. Donenfeld <Jason@zx2c4.com>
Thu, 29 Sep 2022 19:37:27 +0000 (21:37 +0200)
commit8bc55fc37ced215cccde2f676c6f3b61a868af2a
tree4333db791a8239ca83a9f2b3d7b3cfeadb07e6ee
parent0d45f1d5b7cb88cccefe7c65a36518c46eabbad1
prandom: make use of smaller types in prandom_u32_max

When possible at compile-time, make use of smaller types in
prandom_u32_max(), so that we can use smaller batches from random.c,
which in turn leads to a 2x or 4x performance boost. This makes a
difference, for example, in kfence, which needs a fast stream of small
numbers (booleans).

At the same time, we use the occasion to update the old documentation on
these functions. prandom_u32() and prandom_bytes() have direct
replacements now in random.h, while prandom_u32_max() remains useful as
a prandom.h function, since it's not cryptographically secure by virtue
of not being evenly distributed.

Cc: Dominik Brodowski <linux@dominikbrodowski.net>
Acked-by: Marco Elver <elver@google.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
include/linux/prandom.h