From patchwork Fri Aug 23 22:04:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Safonov via B4 Relay X-Patchwork-Id: 13776067 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F09751C7B97; Fri, 23 Aug 2024 22:05:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724450719; cv=none; b=gT5xigPQJk9u87oGmJCv4aen97f8gO6oz8DAulBs8MV2cZmP+zhO3a95YEn7v9Cj5uf5oC1B+eM1/MzETUCCmX7gcGaZhH/iEe6a4mo599Q2hZg3ZT429uQXtaRjOqA9IkvMPenM2Fn6MIXOfv0gVcTHpI+1K7rETlj5/dLWW8Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724450719; c=relaxed/simple; bh=gdo0igheQhF6s/jKqqf8T/+Oo8XxPTB3fpPf+BCe4so=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=q2/G8nZnXq6oO7hCUfgpQwNmCUdFPKlMOGue/rsVE0mricAsXDO0ydEisf1V+ZcgHHD4YS0z9b0hVQQ8/dwyI6biOZQCqn7ZWGddrI8nCFgFtMOjBN9ikHHzTq51DMBYPVxjU+uApy50Ad0ks+M40pj/OEuFbNiUimidpe0gE4M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UevetXRs; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UevetXRs" Received: by smtp.kernel.org (Postfix) with ESMTPS id 9E5F1C4AF12; Fri, 23 Aug 2024 22:05:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724450718; bh=gdo0igheQhF6s/jKqqf8T/+Oo8XxPTB3fpPf+BCe4so=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=UevetXRspiY1Z+mNMx/u/3CrdyyvGDqzNTNjXcDEFLOLS+fbIo6vuiElnhdiXO5HP CxTy+51Q7lesu1Dgh/PF14OFuGoWU4L/lNIiVuyG+r6R76qpm2blI3kw36uS1JGdcV DmDCIHq9f6k5c8PuPdvno6sIOFhIWs51z0hr3/oYD5/wa9qmxqU1aOn1Uwc0Hifm9p /CodefhDvihyiLXnTYQtdxa5T21rIHBVK2H0tstzGizeGnnusaXUUr/tYPyIKvUD5c c1REpZc9X6C12bzM3DtO8ugxII2L4dKuryKgUC9eQkNELsSuUuWKHSsHXFvmPEMNvt ffC/JUZDrp0KQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 975ECC5472D; Fri, 23 Aug 2024 22:05:18 +0000 (UTC) From: Dmitry Safonov via B4 Relay Date: Fri, 23 Aug 2024 23:04:53 +0100 Subject: [PATCH net-next v4 3/8] selftests/net: Be consistent in kconfig checks Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240823-tcp-ao-selftests-upd-6-12-v4-3-05623636fe8c@gmail.com> References: <20240823-tcp-ao-selftests-upd-6-12-v4-0-05623636fe8c@gmail.com> In-Reply-To: <20240823-tcp-ao-selftests-upd-6-12-v4-0-05623636fe8c@gmail.com> To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Shuah Khan Cc: Mohammad Nassiri , netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Safonov <0x7f454c46@gmail.com> X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1724450716; l=2700; i=0x7f454c46@gmail.com; s=20240410; h=from:subject:message-id; bh=PdEStG299EXQfXQVBhomcx2f3Galb07Vq+9A5L4s+Lw=; b=QljIGU07uBRWtFmpN29gpMr9krB0sCeYVKF8Jx8eOi93jHrT1WgQisAS0hJtb1/efZM+BARuj 43Za6YJvfn9CzJiJi25FDA/rmwVycQjRS5L5wwJgQU9jIF0IfKj2FxP X-Developer-Key: i=0x7f454c46@gmail.com; a=ed25519; pk=cFSWovqtkx0HrT5O9jFCEC/Cef4DY8a2FPeqP4THeZQ= X-Endpoint-Received: by B4 Relay for 0x7f454c46@gmail.com/20240410 with auth_id=152 X-Original-From: Dmitry Safonov <0x7f454c46@gmail.com> Reply-To: 0x7f454c46@gmail.com X-Patchwork-Delegate: kuba@kernel.org From: Dmitry Safonov <0x7f454c46@gmail.com> Most of the functions in tcp-ao lib/ return negative errno or -1 in case of a failure. That creates inconsistencies in lib/kconfig, which saves what was the error code. As well as the uninitialized kconfig value is -1, which also may be the result of a check. Define KCONFIG_UNKNOWN and save negative return code, rather than libc-style errno. Signed-off-by: Dmitry Safonov <0x7f454c46@gmail.com> --- tools/testing/selftests/net/tcp_ao/lib/kconfig.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/tools/testing/selftests/net/tcp_ao/lib/kconfig.c b/tools/testing/selftests/net/tcp_ao/lib/kconfig.c index f279ffc3843b..3bf4a7e4b3c9 100644 --- a/tools/testing/selftests/net/tcp_ao/lib/kconfig.c +++ b/tools/testing/selftests/net/tcp_ao/lib/kconfig.c @@ -6,7 +6,7 @@ #include "aolib.h" struct kconfig_t { - int _errno; /* the returned error if not supported */ + int _error; /* negative errno if not supported */ int (*check_kconfig)(int *error); }; @@ -62,7 +62,7 @@ static int has_tcp_ao(int *err) memcpy(&tmp.addr, &addr, sizeof(addr)); *err = 0; if (setsockopt(sk, IPPROTO_TCP, TCP_AO_ADD_KEY, &tmp, sizeof(tmp)) < 0) { - *err = errno; + *err = -errno; if (errno != ENOPROTOOPT) ret = -errno; } @@ -87,7 +87,7 @@ static int has_tcp_md5(int *err) */ *err = 0; if (test_set_md5(sk, addr_any, 0, -1, DEFAULT_TEST_PASSWORD)) { - *err = errno; + *err = -errno; if (errno != ENOPROTOOPT && errno == ENOMEM) { test_print("setsockopt(TCP_MD5SIG_EXT): %m"); ret = -errno; @@ -116,13 +116,14 @@ static int has_vrfs(int *err) return ret; } +#define KCONFIG_UNKNOWN 1 static pthread_mutex_t kconfig_lock = PTHREAD_MUTEX_INITIALIZER; static struct kconfig_t kconfig[__KCONFIG_LAST__] = { - { -1, has_net_ns }, - { -1, has_veth }, - { -1, has_tcp_ao }, - { -1, has_tcp_md5 }, - { -1, has_vrfs }, + { KCONFIG_UNKNOWN, has_net_ns }, + { KCONFIG_UNKNOWN, has_veth }, + { KCONFIG_UNKNOWN, has_tcp_ao }, + { KCONFIG_UNKNOWN, has_tcp_md5 }, + { KCONFIG_UNKNOWN, has_vrfs }, }; const char *tests_skip_reason[__KCONFIG_LAST__] = { @@ -138,11 +139,11 @@ bool kernel_config_has(enum test_needs_kconfig k) bool ret; pthread_mutex_lock(&kconfig_lock); - if (kconfig[k]._errno == -1) { - if (kconfig[k].check_kconfig(&kconfig[k]._errno)) + if (kconfig[k]._error == KCONFIG_UNKNOWN) { + if (kconfig[k].check_kconfig(&kconfig[k]._error)) test_error("Failed to initialize kconfig %u", k); } - ret = kconfig[k]._errno == 0; + ret = kconfig[k]._error == 0; pthread_mutex_unlock(&kconfig_lock); return ret; }