From patchwork Mon Oct 26 16:47:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Doucha X-Patchwork-Id: 1387889 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CKgl13c7kz9sV1 for ; Tue, 27 Oct 2020 03:48:28 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 28DC33C25FD for ; Mon, 26 Oct 2020 17:48:18 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [IPv6:2001:4b78:1:20::4]) by picard.linux.it (Postfix) with ESMTP id 1217E3C12E6 for ; Mon, 26 Oct 2020 17:48:05 +0100 (CET) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-4.smtp.seeweb.it (Postfix) with ESMTPS id 9BA9A1000A44 for ; Mon, 26 Oct 2020 17:48:05 +0100 (CET) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 19D06AD2C for ; Mon, 26 Oct 2020 16:48:05 +0000 (UTC) From: Martin Doucha To: ltp@lists.linux.it Date: Mon, 26 Oct 2020 17:47:40 +0100 Message-Id: <20201026164756.30556-4-mdoucha@suse.cz> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201026164756.30556-1-mdoucha@suse.cz> References: <20201026164756.30556-1-mdoucha@suse.cz> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-4.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.0 required=7.0 tests=SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-4.smtp.seeweb.it Subject: [LTP] [PATCH 03/19] Unify error handling in lib/tst_safe_timerfd.c X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" - Properly format caller file:line locations - Pedantically check for invalid syscall return values Signed-off-by: Martin Doucha --- lib/tst_safe_timerfd.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/lib/tst_safe_timerfd.c b/lib/tst_safe_timerfd.c index ffe7b2ef7..4c36a309c 100644 --- a/lib/tst_safe_timerfd.c +++ b/lib/tst_safe_timerfd.c @@ -17,9 +17,14 @@ int safe_timerfd_create(const char *file, const int lineno, int fd; fd = timerfd_create(clockid, flags); - if (fd < 0) { - tst_brk(TTYPE | TERRNO, "%s:%d timerfd_create(%s) failed", - file, lineno, tst_clock_name(clockid)); + + if (fd == -1) { + tst_brk_(file, lineno, TTYPE | TERRNO, + "timerfd_create(%s) failed", tst_clock_name(clockid)); + } else if (fd < 0) { + tst_brk_(file, lineno, TBROK | TERRNO, + "Invalid timerfd_create(%s) return value %d", + tst_clock_name(clockid), fd); } return fd; @@ -31,9 +36,14 @@ int safe_timerfd_gettime(const char *file, const int lineno, int rval; rval = timerfd_gettime(fd, curr_value); - if (rval != 0) { - tst_brk(TTYPE | TERRNO, "%s:%d timerfd_gettime() failed", - file, lineno); + + if (rval == -1) { + tst_brk_(file, lineno, TTYPE | TERRNO, + "timerfd_gettime() failed"); + } + if (rval) { + tst_brk_(file, lineno, TBROK | TERRNO, + "Invalid timerfd_gettime() return value %d", rval); } return rval; @@ -47,9 +57,13 @@ int safe_timerfd_settime(const char *file, const int lineno, int rval; rval = timerfd_settime(fd, flags, new_value, old_value); - if (rval != 0) { - tst_brk(TTYPE | TERRNO, "%s:%d timerfd_settime() failed", - file, lineno); + + if (rval == -1) { + tst_brk_(file, lineno, TTYPE | TERRNO, + "timerfd_settime() failed"); + } else if (rval) { + tst_brk_(file, lineno, TBROK | TERRNO, + "Invalid timerfd_settime() return value %d", rval); } return rval;