Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751758AbdHBA2g (ORCPT ); Tue, 1 Aug 2017 20:28:36 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:34000 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751607AbdHBA2f (ORCPT ); Tue, 1 Aug 2017 20:28:35 -0400 From: Akinobu Mita To: akpm@linux-foundation.org, linux-kernel@vger.kernel.org Cc: Akinobu Mita , Dmitry Vyukov , Lu Fengqi Subject: [PATCH] fault-inject: fix wrong should_fail() decision in task context Date: Wed, 2 Aug 2017 09:28:20 +0900 Message-Id: <1501633700-3488-1-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1236 Lines: 38 Commit 1203c8e6fb0a ("fault-inject: simplify access check for fail-nth") unintentionally broke a conditional statement in should_fail(). Any faults are not injected in the task context by the change when the systematic fault injection is not used. This change restores to the previous correct behaviour. Fixes: 1203c8e6fb0a ("fault-inject: simplify access check for fail-nth") Cc: Dmitry Vyukov Cc: Lu Fengqi Reported-by: Lu Fengqi Signed-off-by: Akinobu Mita --- lib/fault-inject.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/fault-inject.c b/lib/fault-inject.c index 7d315fd..cf7b129 100644 --- a/lib/fault-inject.c +++ b/lib/fault-inject.c @@ -110,10 +110,12 @@ bool should_fail(struct fault_attr *attr, ssize_t size) if (in_task()) { unsigned int fail_nth = READ_ONCE(current->fail_nth); - if (fail_nth && !WRITE_ONCE(current->fail_nth, fail_nth - 1)) - goto fail; + if (fail_nth) { + if (!WRITE_ONCE(current->fail_nth, fail_nth - 1)) + goto fail; - return false; + return false; + } } /* No need to check any other properties if the probability is 0 */ -- 2.7.4