Skip to content

Commit

Permalink
fault_inject: Don't rely on "return value" from WRITE_ONCE()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Will Deacon committed Apr 15, 2020
1 parent 9a89394 commit 9b4fb5c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/fault-inject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 9b4fb5c

Please sign in to comment.