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 <[email protected]>
AuthorDate:    Mon, 11 May 2020 21:41:40 +01:00
Committer:     Thomas Gleixner <[email protected]>
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 <[email protected]>
Signed-off-by: Thomas Gleixner <[email protected]>
Acked-by: Peter Zijlstra (Intel) <[email protected]>
Cc: Akinobu Mita <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]

---
 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;

Reply via email to