Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp773406ybb; Sat, 28 Mar 2020 09:43:49 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtYoCaZaOACLDnLB2fyinsUbiD9k02dqerZyYyXP1VA32aTbTJXOPBoETY8u1YsiUENFqCb X-Received: by 2002:a9d:64cd:: with SMTP id n13mr3265499otl.274.1585413828948; Sat, 28 Mar 2020 09:43:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585413828; cv=none; d=google.com; s=arc-20160816; b=owFNR3QNDMRbygWw0QkOXc8af/r2GpAT2+gNuIAGN2UnmUQ5hXjQzYLIbQJ7qSzjNi 8mqySch9G6zcUhntWeo4yrCptg/d+LF1WO7+l6yn8a81yDHqwvC4dNOQ9Nt56183loya PxRyqpgaiMNYSI5ojTjWEmEa7awB6UjOVb9ghvGUP0vrnoq+NHC1jSQ/7eLvFk+2OTxV mZ6xJUZiu/0ettiZesBoCyA2IdM0TipJH+GRG749FGIK2L5bTVgogrt74AY+SQnQtoW/ WQc1/2wqm4QsF6Z1uC82mHc5O1yCNMN+HW95Lhqj59/Nj1spQMCcn/DnAygQOo2Aq0cc yiJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:date:from:message-id; bh=sYyRLPhh35ibQm86j0z42jZ+Vq5/LiCRvfRjUsvlV8c=; b=I66e3DE+a8HJFoDM09B7oKeXKLNAYYvtlaYikug7w7o2PDNHfAom+voSY1EAVXBuW0 y/CEX/jTAQ0Od90vUHWfm31y0SNxcpxvx4u7Ub46C3OSCGse0gRrDpEqo5EECTR9+7v0 n/IeKdISPWFSUK7/NgRr8TnPqR9xf0jfEQ7XXVwKujXS6hJVe3OATvPuEHr5By2K3mtE WLAc07Z2Hgv1MyxXzx/uiF0svQdahV+IivYebTfqZdvcb85GuGN83rSnXBP8qGmOh18H rF0cEcLpGLSSGmH0LMX1yMNe59I7urosfvOyXjV195uMKyqpZxTwuOu6uV3KG8P6wxU6 C1kg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v14si4249241oou.5.2020.03.28.09.43.32; Sat, 28 Mar 2020 09:43:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726282AbgC1QnM (ORCPT + 99 others); Sat, 28 Mar 2020 12:43:12 -0400 Received: from mx.sdf.org ([205.166.94.20]:50295 "EHLO mx.sdf.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726170AbgC1QnM (ORCPT ); Sat, 28 Mar 2020 12:43:12 -0400 Received: from sdf.org (IDENT:lkml@sdf.lonestar.org [205.166.94.16]) by mx.sdf.org (8.15.2/8.14.5) with ESMTPS id 02SGhBkr028015 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits) verified NO); Sat, 28 Mar 2020 16:43:11 GMT Received: (from lkml@localhost) by sdf.org (8.15.2/8.12.8/Submit) id 02SGhBxX000080; Sat, 28 Mar 2020 16:43:11 GMT Message-Id: <202003281643.02SGhBxX000080@sdf.org> From: George Spelvin Date: Mon, 18 Mar 2019 02:46:05 -0400 Subject: [RFC PATCH v1 12/50] Treewide: Extirpate prandom_u32_state(rnd) % range To: linux-kernel@vger.kernel.org, lkml@sdf.org Cc: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , intel-gfx@lists.freedesktop.org, Davidlohr Bueso , Chris Wilson Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Cc: Jani Nikula Cc: Joonas Lahtinen Cc: Rodrigo Vivi Cc: intel-gfx@lists.freedesktop.org Cc: Davidlohr Bueso Cc: Chris Wilson --- drivers/gpu/drm/i915/selftests/scatterlist.c | 4 ++-- lib/interval_tree_test.c | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/i915/selftests/scatterlist.c b/drivers/gpu/drm/i915/selftests/scatterlist.c index d599186d5b714..be9ff9d03eada 100644 --- a/drivers/gpu/drm/i915/selftests/scatterlist.c +++ b/drivers/gpu/drm/i915/selftests/scatterlist.c @@ -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, diff --git a/lib/interval_tree_test.c b/lib/interval_tree_test.c index f37f4d44faa90..8c129c8c638b9 100644 --- a/lib/interval_tree_test.c +++ b/lib/interval_tree_test.c @@ -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) -- 2.26.0