treewide: use prandom_u32_max() when possible, part 2
authorJason A. Donenfeld <Jason@zx2c4.com>
Wed, 5 Oct 2022 14:43:38 +0000 (16:43 +0200)
committerJason A. Donenfeld <Jason@zx2c4.com>
Tue, 11 Oct 2022 23:42:58 +0000 (17:42 -0600)
commit8b3ccbc1f1f91847160951aa15dd27c22dddcb49
treeb145d918cbcfc9c326136e1939d8b787c9983055
parent81895a65ec63ee1daec3255dc1a06675d2fbe915
treewide: use prandom_u32_max() when possible, part 2

Rather than incurring a division or requesting too many random bytes for
the given range, use the prandom_u32_max() function, which only takes
the minimum required bytes from the RNG and avoids divisions. This was
done by hand, covering things that coccinelle could not do on its own.

Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Yury Norov <yury.norov@gmail.com>
Reviewed-by: Jan Kara <jack@suse.cz> # for ext2, ext4, and sbitmap
Acked-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
fs/ext2/ialloc.c
fs/ext4/ialloc.c
lib/sbitmap.c
lib/test_vmalloc.c