summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorWill Deacon <will@kernel.org>2019-12-19 17:40:21 +0000
committerWill Deacon <will@kernel.org>2020-04-15 21:36:41 +0100
commit9b4fb5cec031f81ef436bf2cfd9fc265e25f6e45 (patch)
treeb33080e6d87ae7af66b5ad77987d6a4fa321b0fe /lib
parent9a8939490d401fefddf53cd5e4cb3e20a52b98a7 (diff)
downloadlinux-9b4fb5cec031f81ef436bf2cfd9fc265e25f6e45.tar.gz
linux-9b4fb5cec031f81ef436bf2cfd9fc265e25f6e45.tar.bz2
linux-9b4fb5cec031f81ef436bf2cfd9fc265e25f6e45.zip
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 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. Cc: Akinobu Mita <akinobu.mita@gmail.com> Signed-off-by: Will Deacon <will@kernel.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/fault-inject.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/fault-inject.c b/lib/fault-inject.c
index 8186ca84910b..ce12621b4275 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;