Treewide: Extirpate prandom_u32_state(rnd) % range
Subsystems (3)
RFC PATCH 12/50 Treewide: Extirpate prandom_u32_state(rnd) % range
There's no prandom_u32_state_max, so we're using reciprocal_scale() here directly.
(Also add a missing "const" to drivers/gpu/drm/i915/selftests/scatterist.c)
Signed-off-by George Spelvin <[email protected]>
Cc Jani Nikula <[email protected]>
Cc Joonas Lahtinen <[email protected]>
Cc Rodrigo Vivi <[email protected]>
Cc Davidlohr Bueso <[email protected]>
Cc Chris Wilson <[email protected]>
--- drivers/gpu/drm/i915/selftests/scatterlist.c | 4 ++-- lib/interval_tree_test.c | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-)
drivers/gpu/drm/i915/selftests/scatterlist.c +2 -2
@@ -195,13 +195,13 @@ static unsigned int random_page_size_pages(unsigned long n, struct rnd_state *rnd) {/* 4K, 64K, 2M */ -static unsigned int page_count[] = { +static const unsigned int page_count[] = {BIT (12 ) >>PAGE_SHIFT ,BIT (16 ) >>PAGE_SHIFT ,BIT (21 ) >>PAGE_SHIFT , }; -return page_count[(prandom_u32_state (rnd) %3 )]; +return page_count[reciprocal_scale (prandom_u32_state (rnd),3 )]; } static inline bool page_contiguous(struct page *first,
lib/interval_tree_test.c +4 -3
@@ -43,8 +43,8 @@ static void init(void)int i;for (i =0 ; i < nnodes; i++) { -u32 b = (prandom_u32_state (&rnd) >>4 ) % max_endpoint; -u32 a = (prandom_u32_state (&rnd) >>4 ) % b; +u32 b =reciprocal_scale (prandom_u32_state (&rnd), max_endpoint); +u32 a =reciprocal_scale (prandom_u32_state (&rnd), b); nodes[i].start = a; nodes[i].last = b;
@@ -56,7 +56,8 @@ static void init(void)* which is pointless. */ for (i =0 ; i < nsearches; i++) - queries[i] = (prandom_u32_state (&rnd) >>4 ) % max_endpoint; + queries[i] =reciprocal_scale (prandom_u32_state (&rnd), + max_endpoint); }static int interval_tree_test_init (void )
Signature · 1 line
2.26.0