Skip to contentSkip to conversation

fault-inject: Avoid call to random32() if fault injection is disabled

PATCH In review Anton Blanchard 2 participants 2 messages Jun 1, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---

lib/fault-inject.c +4 -0
Index: linux-build/lib/fault-inject.c
===================================================================
@@ -101,6 +101,10 @@ static inline bool fail_stacktrace(struc
 
 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;
 
maintainer Acked-by on v1 1/1
#1 lore raw

2012/6/1 Anton Blanchard <[email protected]>:

Quoted 21 lines

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.

---

Index: linux-build/lib/fault-inject.c
===================================================================

lib/fault-inject.c      2012-02-11 22:38:10.470977505 +1100 static inline bool fail_stacktrace(struc · line 110

Quoted 10 lines
lib/fault-inject.c      2012-02-11 22:38:10.470977505 +1100 renamed from lib/fault-inject.c 2012-02-11 21:22:32.303459860 +1100 +4 -0
@@ -101,6 +101,10 @@ static inline bool fail_stacktrace(struc
 
  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;
 

Looks good to me.