Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp776116ybb; Sat, 28 Mar 2020 09:47:50 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsThX7YSnsZrH+BA5A7OvLx3BDNCchjuTONq7tO1efr89iEUXRww2CYhhZpQzbdm1UzLCkK X-Received: by 2002:a9d:4c8a:: with SMTP id m10mr3267108otf.114.1585414070029; Sat, 28 Mar 2020 09:47:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585414070; cv=none; d=google.com; s=arc-20160816; b=tEAdSNKHEGVBxefFcXi5DNR+sadnnBwxnBLv1jiljlYRNgy/AVM0scR4WWj+fx+lRv HBn2GF5FXD9a1s7plt8T189wo5+9MBLF51CcurWSMI4WS4/r3jyKhOkZfZP9ubVgRYxO hcJenTB/tPv4dgyNaUj6/JKPYqgbmLFRatCHIv3vWwapvqE8WoU8TXrtS4f9su5YkdSl A4hDMEJLFBDBgfSbZLLao/C7jxkz4t4Smee4JsMCcl9UgMfHs3xI7P/9tfaj63m5vhxd oZ6xciiob1aNmG1Jv/XBP7Lprmbi35MRJo7GbwJ2N7DHC1h3T0JojyuLE+HhF6XJPTBC ueyA== 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=oevc3T1jJv+ScbcsEfxZOfOCvPNm7xcmU0acdNx6Y5U=; b=AtWfxD27ETzBS726D397YTbXEF1X2rrgCtLEnb5zfgqckvtq1m6E/QoyG8zg+ThkAl 8+dCygwRP3BBjrnT5CEeuD/Wt6lFcX0qXi9bmL/CLjejqJMN3Xl4CvR6y/XEkZ2RCIFs c5936G6l3dPKqKIQsZl1c1edz3GE3IyfZnsgj7ztCJTY+rDT0Bh0BZkHM/xfocwueUNp xMH9aFdQ26VrC/ZXR8FzrN1APMgs/ZD34vYtH+Z9zhJH+jENX3eZdyRI4sifPQ7Y+f0m NXHbQGI4OJRRXmLC0yXwQRnVOjX7BH2iSDAymyYFlU9KLMpEfO8Rno+3+YcG8E5ICNGh pxCg== 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 l21si3641059otq.144.2020.03.28.09.47.37; Sat, 28 Mar 2020 09:47:50 -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 S1727954AbgC1Qpt (ORCPT + 99 others); Sat, 28 Mar 2020 12:45:49 -0400 Received: from mx.sdf.org ([205.166.94.20]:50018 "EHLO mx.sdf.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727722AbgC1Qnc (ORCPT ); Sat, 28 Mar 2020 12:43:32 -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 02SGhJkQ015420 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits) verified NO); Sat, 28 Mar 2020 16:43:19 GMT Received: (from lkml@localhost) by sdf.org (8.15.2/8.12.8/Submit) id 02SGhJI8005124; Sat, 28 Mar 2020 16:43:19 GMT Message-Id: <202003281643.02SGhJI8005124@sdf.org> From: George Spelvin Date: Fri, 29 Nov 2019 17:12:18 -0500 Subject: [RFC PATCH v1 32/50] lib/test*.c: Use prandom_u32_max() To: linux-kernel@vger.kernel.org, lkml@sdf.org Cc: Ferdinand Blomqvist , Thomas Gleixner , Andy Shevchenko , Vitaly Kuznetsov Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org lib/reed_solomon/test_rslib.c alreasy uses prandom_u32(); lib/test_hexdump.c and lib/test-string_helpers.c were using get_random_int() % range, which is needlessly expensive for test code. Signed-off-by: George Spelvin Cc: Ferdinand Blomqvist Cc: Thomas Gleixner Cc: Andy Shevchenko Cc: Vitaly Kuznetsov --- lib/reed_solomon/test_rslib.c | 4 ++-- lib/test-string_helpers.c | 2 +- lib/test_hexdump.c | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/reed_solomon/test_rslib.c b/lib/reed_solomon/test_rslib.c index 4eb29f365ece0..58e767c142ef8 100644 --- a/lib/reed_solomon/test_rslib.c +++ b/lib/reed_solomon/test_rslib.c @@ -183,7 +183,7 @@ static int get_rcw_we(struct rs_control *rs, struct wspace *ws, do { /* Must not choose the same location twice */ - errloc = prandom_u32() % len; + errloc = prandom_u32_max(len); } while (errlocs[errloc] != 0); errlocs[errloc] = 1; @@ -194,7 +194,7 @@ static int get_rcw_we(struct rs_control *rs, struct wspace *ws, for (i = 0; i < eras; i++) { do { /* Must not choose the same location twice */ - errloc = prandom_u32() % len; + errloc = prandom_u32_max(len); } while (errlocs[errloc] != 0); derrlocs[i] = errloc; diff --git a/lib/test-string_helpers.c b/lib/test-string_helpers.c index 25b5cbfb7615b..3349f3ddc528c 100644 --- a/lib/test-string_helpers.c +++ b/lib/test-string_helpers.c @@ -398,7 +398,7 @@ static int __init test_string_helpers_init(void) for (i = 0; i < UNESCAPE_ANY + 1; i++) test_string_unescape("unescape", i, false); test_string_unescape("unescape inplace", - get_random_int() % (UNESCAPE_ANY + 1), true); + prandom_u32_max(UNESCAPE_ANY + 1), true); /* Without dictionary */ for (i = 0; i < (ESCAPE_ANY_NP | ESCAPE_HEX) + 1; i++) diff --git a/lib/test_hexdump.c b/lib/test_hexdump.c index 5144899d3c6b8..54e4efb28b974 100644 --- a/lib/test_hexdump.c +++ b/lib/test_hexdump.c @@ -149,7 +149,7 @@ static void __init test_hexdump(size_t len, int rowsize, int groupsize, static void __init test_hexdump_set(int rowsize, bool ascii) { size_t d = min_t(size_t, sizeof(data_b), rowsize); - size_t len = get_random_int() % d + 1; + size_t len = prandom_u32_max(d) + 1; test_hexdump(len, rowsize, 4, ascii); test_hexdump(len, rowsize, 2, ascii); @@ -208,11 +208,11 @@ static void __init test_hexdump_overflow(size_t buflen, size_t len, static void __init test_hexdump_overflow_set(size_t buflen, bool ascii) { unsigned int i = 0; - int rs = (get_random_int() % 2 + 1) * 16; + int rs = (prandom_u32() % 2 + 1) * 16; do { int gs = 1 << i; - size_t len = get_random_int() % rs + gs; + size_t len = prandom_u32_max(rs) + gs; test_hexdump_overflow(buflen, rounddown(len, gs), rs, gs, ascii); } while (i++ < 3); @@ -223,11 +223,11 @@ static int __init test_hexdump_init(void) unsigned int i; int rowsize; - rowsize = (get_random_int() % 2 + 1) * 16; + rowsize = (prandom_u32() % 2 + 1) * 16; for (i = 0; i < 16; i++) test_hexdump_set(rowsize, false); - rowsize = (get_random_int() % 2 + 1) * 16; + rowsize = (prandom_u32() % 2 + 1) * 16; for (i = 0; i < 16; i++) test_hexdump_set(rowsize, true); -- 2.26.0