Thread (24 messages) 24 messages, 6 authors, 2022-11-17

Re: [PATCH v2 3/3] treewide: use get_random_u32_between() when possible

From: Kees Cook <hidden>
Date: 2022-11-16 22:43:35
Also in: linux-arm-kernel, linux-block, linux-crypto, linux-fsdevel, linux-media, linux-mips, linux-mmc, linux-patches, lkml, loongarch, netdev

On Mon, Nov 14, 2022 at 05:45:58PM +0100, Jason A. Donenfeld wrote:
-				(get_random_u32_below(1024) + 1) * PAGE_SIZE;
+				get_random_u32_between(1, 1024 + 1) * PAGE_SIZE;
I really don't like "between". Can't this be named "inclusive" (and
avoid adding 1 everywhere, which seems ugly), or at least named
something less ambiguous?
-		n = get_random_u32_below(100) + 1;
+		n = get_random_u32_between(1, 101);
Because I find this much less readable. "Below 100" is clear: 0-99
inclusive, plus 1, so 1-100 inclusive. "Between 1 and 101" is not obvious
to me to mean: 1-100 inclusive.

These seem so much nicer:
	get_random_u32_inclusive(1, 1024)
	get_random_u32_inclusive(1, 100)

-- 
Kees Cook
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help