From: Don Mullis Date: Fri, 8 Dec 2006 10:39:53 +0000 (-0800) Subject: [PATCH] fault-injection: optimize and simplify should_fail() X-Git-Url: http://git.cdn.openwrt.org/?a=commitdiff_plain;h=f1729c28a37e4f11ea5d9f468ab26adadb1aadab;p=openwrt%2Fstaging%2Fblogic.git [PATCH] fault-injection: optimize and simplify should_fail() 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 Cc: Akinobu Mita Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/lib/fault-inject.c b/lib/fault-inject.c index 5da665ac2d89..d143c0faf248 100644 --- a/lib/fault-inject.c +++ b/lib/fault-inject.c @@ -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; @@ -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)