From: Anton Blanchard Date: Wed, 20 Jun 2012 19:53:03 +0000 (-0700) Subject: fault-inject: avoid call to random32() if fault injection is disabled X-Git-Tag: upstream/snapshot3+hdmi~7198^2~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f39cdaebb89dc3e6dd4f3e75b6d4e87ef12190af;p=platform%2Fadaptation%2Frenesas_rcar%2Frenesas_kernel.git fault-inject: avoid call to random32() if fault injection is disabled 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 Acked-by: 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 6805453..f7210ad 100644 --- a/lib/fault-inject.c +++ b/lib/fault-inject.c @@ -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;