fault-inject: simplify access check for fail-nth
[muen/linux.git] / lib / fault-inject.c
index 09ac73c177fd555b86ef8b3a155ee1043258b532..7d315fdb9f13d9b17d8a2aa129c75790c7599bdb 100644 (file)
@@ -107,9 +107,12 @@ static inline bool fail_stacktrace(struct fault_attr *attr)
 
 bool should_fail(struct fault_attr *attr, ssize_t size)
 {
-       if (in_task() && current->fail_nth) {
-               if (--current->fail_nth == 0)
+       if (in_task()) {
+               unsigned int fail_nth = READ_ONCE(current->fail_nth);
+
+               if (fail_nth && !WRITE_ONCE(current->fail_nth, fail_nth - 1))
                        goto fail;
+
                return false;
        }