Skip to content

Commit 9b4fb5c

Browse files
committed
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 <[email protected]> Signed-off-by: Will Deacon <[email protected]>
1 parent 9a89394 commit 9b4fb5c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/fault-inject.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ bool should_fail(struct fault_attr *attr, ssize_t size)
106106
unsigned int fail_nth = READ_ONCE(current->fail_nth);
107107

108108
if (fail_nth) {
109-
if (!WRITE_ONCE(current->fail_nth, fail_nth - 1))
109+
fail_nth--;
110+
WRITE_ONCE(current->fail_nth, fail_nth);
111+
if (!fail_nth)
110112
goto fail;
111113

112114
return false;

0 commit comments

Comments
 (0)