Skip to content

Commit

Permalink
fault-inject: avoid call to random32() if fault injection is disabled
Browse files Browse the repository at this point in the history
After enabling CONFIG_FAILSLAB I noticed random32 in profiles even if slub
fault injection wasn't enabled at runtime.

should_fail forces a comparison against random32() even if probability is
0:

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

Add a check up front for probability == 0 and avoid all of the more
complicated checks.

Signed-off-by: Anton Blanchard <anton@samba.org>
Acked-by: Akinobu Mita <akinobu.mita@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
antonblanchard authored and torvalds committed Jun 20, 2012
1 parent 10d8935 commit f39cdae
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/fault-inject.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ static inline bool fail_stacktrace(struct fault_attr *attr)

bool should_fail(struct fault_attr *attr, ssize_t size)
{
/* No need to check any other properties if the probability is 0 */
if (attr->probability == 0)
return false;

if (attr->task_filter && !fail_task(attr, current))
return false;

Expand Down

0 comments on commit f39cdae

Please sign in to comment.