Skip to content

Commit

Permalink
[PATCH] fault-injection: optimize and simplify should_fail()
Browse files Browse the repository at this point in the history
Trivial optimization and simplification of should_fail().

Do cheaper disqualification tests first (performance gain not quantified).
Simplify logic; eliminate goto.

Signed-off-by: Don Mullis <[email protected]>
Cc: Akinobu Mita <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Don Mullis authored and Linus Torvalds committed Dec 8, 2006
1 parent a124c28 commit f1729c2
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions lib/fault-inject.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,6 @@ bool should_fail(struct fault_attr *attr, ssize_t size)
if (attr->task_filter && !fail_task(attr, current))
return false;

if (!fail_stacktrace(attr))
return false;

if (atomic_read(&attr->times) == 0)
return false;

Expand All @@ -159,12 +156,12 @@ bool should_fail(struct fault_attr *attr, ssize_t size)
return false;
}

if (attr->probability > random32() % 100)
goto fail;
if (attr->probability <= random32() % 100)
return false;

return false;
if (!fail_stacktrace(attr))
return false;

fail:
fail_dump(attr);

if (atomic_read(&attr->times) != -1)
Expand Down

0 comments on commit f1729c2

Please sign in to comment.