The following commit has been merged into the locking/kcsan branch of tip: Commit-ID: 9a7cb2d8d6b959fc11a34668b1523f745ae5f714 Gitweb: https://git.kernel.org/tip/9a7cb2d8d6b959fc11a34668b1523f745ae5f714 Author: Will Deacon <will@xxxxxxxxxx> AuthorDate: Mon, 11 May 2020 21:41:40 +01:00 Committer: Thomas Gleixner <tglx@xxxxxxxxxxxxx> CommitterDate: Tue, 12 May 2020 11:04:12 +02:00 fault_inject: Don't rely on "return value" from WRITE_ONCE() It's a bit weird that WRITE_ONCE() evaluates to the value it stores and it's also different to smp_store_release(), which can't be used this way. In preparation for preventing this in WRITE_ONCE(), change the fault injection code to use a local variable instead. Signed-off-by: Will Deacon <will@xxxxxxxxxx> Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx> Acked-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx> Cc: Akinobu Mita <akinobu.mita@xxxxxxxxx> Link: https://lkml.kernel.org/r/20200511204150.27858-9-will@xxxxxxxxxx --- lib/fault-inject.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/fault-inject.c b/lib/fault-inject.c index 8186ca8..ce12621 100644 --- a/lib/fault-inject.c +++ b/lib/fault-inject.c @@ -106,7 +106,9 @@ bool should_fail(struct fault_attr *attr, ssize_t size) unsigned int fail_nth = READ_ONCE(current->fail_nth); if (fail_nth) { - if (!WRITE_ONCE(current->fail_nth, fail_nth - 1)) + fail_nth--; + WRITE_ONCE(current->fail_nth, fail_nth); + if (!fail_nth) goto fail; return false;