Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp774159ybb; Sat, 28 Mar 2020 09:45:00 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuUZKEN8KaxV1kPpJPnm25SiWYdliiVugI1xcR6g02hjnDd27dDfEFLjmB1VFebCAB5SYE+ X-Received: by 2002:a4a:e78b:: with SMTP id x11mr3913331oov.45.1585413900660; Sat, 28 Mar 2020 09:45:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585413900; cv=none; d=google.com; s=arc-20160816; b=JwYgrpDx40pmtSmqENq+kVjaBqumjF2Sou4aIaeWEOvVSJgWWxmI4/XG5A9KjinbgA Q7ZVuN7/HLKktg1bFKbhTXtuIf2WgUGoCC6aX/+Y8CBrioYDpC2tCFHvY0WN2wiJVpD9 rO4adujDIBgmgO+7FX38bfBzCD/fbkoAPpTTbGzB0ayNH67Mu4Mrh3uDoA7AAzW/zTS/ j1aMxxG5bI8R9+ukvyJciGlGaYfFoyNN4516/+/22iJUr/bMAIY0P1UrzXqZ43RFlRg+ E4nIHxKtT8Ff+bSLppu2OjBKYLosgkFbM7C8mZGCiyNKfutaMRocsDQWtpvkeRZJ4Zs3 cEyw== 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=BX2zH8SDe9iFCDs9qsrgyL5gy7HFeGu2BGrNP/CfA7s=; b=csIwy838SSp4JuUQGkZIPOnTHwYHrF1K5k0sJgx2+f6hcJX/0ghzAgSOA/mc+q3KZJ QQFSdMtLfDmchLEK7nuQZ1s7l54hG1DVY0HvP5geBWIQQXbU6HXJ0KayzcENRQhRM11A LVBP7zv7lYGFN8pThXBkKMgDJEhL9f36SZK4LPXYlM+67GXxfNHeuWuWCdq6JitiTfFM R80cvebXNEHKYLQFYDHZsrsdFE5hC3bmPg5xo/OFjQXmBJE1l37sGbfyLwsQ0+afP6i2 NlgTj5v4loJ9zQD0+VhaI1re7wHdtbfCDGZkTMIhnAa8+Bj001WjcoEDvJEYCqQPAjvW 2BOA== 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 n24si1559178otr.217.2020.03.28.09.44.48; Sat, 28 Mar 2020 09:45:00 -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 S1726380AbgC1Qnn (ORCPT + 99 others); Sat, 28 Mar 2020 12:43:43 -0400 Received: from mx.sdf.org ([205.166.94.20]:50097 "EHLO mx.sdf.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727627AbgC1Qn1 (ORCPT ); Sat, 28 Mar 2020 12:43:27 -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 02SGh6Cr021330 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits) verified NO); Sat, 28 Mar 2020 16:43:07 GMT Received: (from lkml@localhost) by sdf.org (8.15.2/8.12.8/Submit) id 02SGh6ii026355; Sat, 28 Mar 2020 16:43:06 GMT Message-Id: <202003281643.02SGh6ii026355@sdf.org> From: George Spelvin Date: Wed, 4 Dec 2019 00:25:58 -0500 Subject: [RFC PATCH v1 02/50] lib/fault-inject.c: Fix off-by-one error in probability To: linux-kernel@vger.kernel.org, lkml@sdf.org Cc: Akinobu Mita , Anton Blanchard Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is the combination of two fixes. First, use prandom_u32_max() for efficiency: - if (attr->probability <= prandom_u32() % 100) + if (attr->probability <= prandom_u32_max(100)) return false And then a bug-fix: - if (attr->probability <= prandom_u32_max(100)) + if (attr->probability < prandom_u32_max(100)) return false Before, probability = 1 would succeed 2% of the time and 99 would succeed 100% of the time. (0% was caught by an earlier test.) Signed-off-by: George Spelvin Cc: Akinobu Mita Cc: Anton Blanchard --- lib/fault-inject.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fault-inject.c b/lib/fault-inject.c index 8186ca84910bc..e20151fa5515e 100644 --- a/lib/fault-inject.c +++ b/lib/fault-inject.c @@ -134,7 +134,7 @@ bool should_fail(struct fault_attr *attr, ssize_t size) return false; } - if (attr->probability <= prandom_u32() % 100) + if (attr->probability < prandom_u32_max(100)) return false; if (!fail_stacktrace(attr)) -- 2.26.0