Skip to content

Commit f39cdae

Browse files
antonblanchardtorvalds
authored andcommitted
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 <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>
1 parent 10d8935 commit f39cdae

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

‎lib/fault-inject.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ static inline bool fail_stacktrace(struct fault_attr *attr)
101101

102102
bool should_fail(struct fault_attr *attr, ssize_t size)
103103
{
104+
/* No need to check any other properties if the probability is 0 */
105+
if (attr->probability == 0)
106+
return false;
107+
104108
if (attr->task_filter && !fail_task(attr, current))
105109
return false;
106110

0 commit comments

Comments
 (0)