Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp4552686rwe; Mon, 17 Apr 2023 14:40:56 -0700 (PDT) X-Google-Smtp-Source: AKy350bO82gKhpvvgHUPdcbnDYHhjWXYcvtseD0Tcx8pygNuJJc6vr9vgEcVT0pone/7P//0Joxq X-Received: by 2002:a05:6a20:72a4:b0:f0:4dbf:5f9f with SMTP id o36-20020a056a2072a400b000f04dbf5f9fmr2991551pzk.29.1681767655988; Mon, 17 Apr 2023 14:40:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681767655; cv=none; d=google.com; s=arc-20160816; b=FDkVV8tEEQUVmwepugzKJBdOleVGI9VVagktqt49zbSqb+WfNrKwqQS4tRakrV5ksx CAhB0nyEnnYgZ17X9XNXMhgeGJHHCGQbbxxK2epdlkFn3OKbyMAj8IJ2xhhwwmx2xsuK gW0/F+IAOnLoG+7a+klasxD8ZelosEIBkk6CPNnl8IWV8hbBYV42rTHbT4Eh2J95mqTo JB+oCKDsp1UcgsIgGyFu0S38RdBHZdDCL8KJE5YfYajstAHoexeEJZ6H/wHKbObuQ9Xa TG8yFekmdZpRqY0sqejFPxWzbbrQ87TMwsiWp2W8mGN9ZTN/l+WfJzMByRqdk3qE8MuT omhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:sender:dkim-signature; bh=55hC0C6PEmc4uh5DYwJYIxp6KDXjWnD+6ic8XLUbNJk=; b=io3Ble78mK279KiEYSjwaQJz7xjpGss87uQmltUmoREzhRI5ED0vY5RDqQHttveDQy 8vqzsfPl8/80tEu2UnZps1pE6j52xEUuLdPcTs6g2BTustV9EdEbsz+FuAY6dd0osGpQ KkETtrWsIKUzIVBhlnku4RGS3fjtCnbz0aZHn7eVuIHDMcmE28iyYNbUaQ0bEaJvX9V0 OgMT+E0zSbfqevHENduj4iiW1BtWsQo7tIUR19cH9cyPMthpOO2xwPBzcX6/5j/EmQTD NXQD37ef8rvWmdAhYTx11j296N6Z6Y98DavIDt8EAk3dVQ+blY6frzOgxeG9XZPCNhaD toLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=YKbaQH88; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v202-20020a6361d3000000b0051b54dc77aasi12285619pgb.289.2023.04.17.14.40.41; Mon, 17 Apr 2023 14:40:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=YKbaQH88; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230375AbjDQV3N (ORCPT + 99 others); Mon, 17 Apr 2023 17:29:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229643AbjDQV3L (ORCPT ); Mon, 17 Apr 2023 17:29:11 -0400 Received: from mail-yw1-x112d.google.com (mail-yw1-x112d.google.com [IPv6:2607:f8b0:4864:20::112d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9006FF; Mon, 17 Apr 2023 14:29:09 -0700 (PDT) Received: by mail-yw1-x112d.google.com with SMTP id 00721157ae682-552ae3e2cbeso61562807b3.13; Mon, 17 Apr 2023 14:29:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681766948; x=1684358948; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:from:to:cc:subject:date:message-id:reply-to; bh=55hC0C6PEmc4uh5DYwJYIxp6KDXjWnD+6ic8XLUbNJk=; b=YKbaQH880ffbrD1wSOeYaho611fZvl8uvV2IkFui1/mpcsuGl8HTmTKzTVyNAeeWRv K2HCmGqXq9q9RWCBtcngTm57FIzo6bzfEBLWPGXhcknNkGBtu/JWCSUGP994oL9GdPs1 BXU6gnQ18K9Yy8NqmxORm35quAoZireqRWLj4qXR7WhrabKwun03lI1kOWmO6B8EyO95 zagmJFtTWpSdzvCaZOb7G5RHn8+Ohcw55170PB6SgxcEysKW6yrM5vqkLbQ2DNaYhKGL so8Hv47MKZSHkTptbG3Tp0ZjZM6r8NOfl1kiqxIEU+uxEy7RT8ZMjzyS7CUnFb7LhFf+ 1byw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681766948; x=1684358948; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=55hC0C6PEmc4uh5DYwJYIxp6KDXjWnD+6ic8XLUbNJk=; b=Ycge3riNQ6QRU/LPs3RLP4IW+BZD/tC62Nqu5zOOcGD/TEqnJhr99BUvNIODKcXU/v xHC3UF+AWQ4hxJ7HEIbQfEC1WOv3k4j2hulcyQAwlpYItcLLPft4uBO6wvnYOBif/Obd nfakUcbWWjju7wc9tt/1EzpfobDsaCJLdx+bntDbsyZntxkEKWm4mp1ptYVRsBDycaJA 7gXZvBQCxpIlM1/nDroGal9QMoxmZkQuSIv4N3wRpUGDbINe+EEEEOA//muDUNobFcxh p8WBNCTz4La08SH7H/iVZHPDiRUtVwSgtbshIm1vbWVMC4R5auy9qdbNh0HR9mowpxT/ ZrSw== X-Gm-Message-State: AAQBX9el1gMj2A8qjVDReFD2r8NP+y6zjv3CkxLexFsVBYVe0StCvkVa gvDEkCzg64bN6g9eZSdc8cLfI581dUM= X-Received: by 2002:a81:4f09:0:b0:541:66e8:d4da with SMTP id d9-20020a814f09000000b0054166e8d4damr14851383ywb.29.1681766947164; Mon, 17 Apr 2023 14:29:07 -0700 (PDT) Received: from tachyon.tail92c87.ts.net ([192.159.180.233]) by smtp.gmail.com with ESMTPSA id cl22-20020a05690c0c1600b0054fbadd96c4sm3332372ywb.126.2023.04.17.14.29.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Apr 2023 14:29:06 -0700 (PDT) Sender: Tavian Barnes From: tavianator@tavianator.com To: linux-kernel@vger.kernel.org Cc: Tavian Barnes , Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Darren Hart , Davidlohr Bueso , =?UTF-8?q?Andr=C3=A9=20Almeida?= , Shuah Khan , linux-kselftest@vger.kernel.org Subject: [PATCH] selftests/futex: Fix pthread_create() error handling Date: Mon, 17 Apr 2023 17:28:57 -0400 Message-Id: <42a8405a78936a3ec96bbd0c6b5d983291faf646.1681766292.git.tavianator@tavianator.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tavian Barnes The pthread APIs return error codes, rather than setting errno. Signed-off-by: Tavian Barnes --- .../selftests/futex/functional/futex_requeue.c | 10 ++++++---- .../functional/futex_requeue_pi_mismatched_ops.c | 5 +++-- .../selftests/futex/functional/futex_wait.c | 15 +++++++++------ .../functional/futex_wait_private_mapped_file.c | 2 +- .../functional/futex_wait_uninitialized_heap.c | 2 +- .../selftests/futex/functional/futex_waitv.c | 10 ++++++---- 6 files changed, 26 insertions(+), 18 deletions(-) diff --git a/tools/testing/selftests/futex/functional/futex_requeue.c b/tools/testing/selftests/futex/functional/futex_requeue.c index 51485be6eb2f..76f672ad5263 100644 --- a/tools/testing/selftests/futex/functional/futex_requeue.c +++ b/tools/testing/selftests/futex/functional/futex_requeue.c @@ -73,8 +73,9 @@ int main(int argc, char *argv[]) /* * Requeue a waiter from f1 to f2, and wake f2. */ - if (pthread_create(&waiter[0], NULL, waiterfn, NULL)) - error("pthread_create failed\n", errno); + res = pthread_create(&waiter[0], NULL, waiterfn, NULL); + if (res) + error("pthread_create failed\n", res); usleep(WAKE_WAIT_US); @@ -105,8 +106,9 @@ int main(int argc, char *argv[]) * At futex_wake, wake INT_MAX (should be exactly 7). */ for (i = 0; i < 10; i++) { - if (pthread_create(&waiter[i], NULL, waiterfn, NULL)) - error("pthread_create failed\n", errno); + res = pthread_create(&waiter[i], NULL, waiterfn, NULL); + if (res) + error("pthread_create failed\n", res); } usleep(WAKE_WAIT_US); diff --git a/tools/testing/selftests/futex/functional/futex_requeue_pi_mismatched_ops.c b/tools/testing/selftests/futex/functional/futex_requeue_pi_mismatched_ops.c index d0a4d332ea44..e28de62bc03a 100644 --- a/tools/testing/selftests/futex/functional/futex_requeue_pi_mismatched_ops.c +++ b/tools/testing/selftests/futex/functional/futex_requeue_pi_mismatched_ops.c @@ -79,8 +79,9 @@ int main(int argc, char *argv[]) ksft_print_msg("%s: Detect mismatched requeue_pi operations\n", basename(argv[0])); - if (pthread_create(&child, NULL, blocking_child, NULL)) { - error("pthread_create\n", errno); + ret = pthread_create(&child, NULL, blocking_child, NULL); + if (ret) { + error("pthread_create\n", ret); ret = RET_ERROR; goto out; } diff --git a/tools/testing/selftests/futex/functional/futex_wait.c b/tools/testing/selftests/futex/functional/futex_wait.c index 685140d9b93d..2e06539e5bb7 100644 --- a/tools/testing/selftests/futex/functional/futex_wait.c +++ b/tools/testing/selftests/futex/functional/futex_wait.c @@ -78,8 +78,9 @@ int main(int argc, char *argv[]) /* Testing a private futex */ info("Calling private futex_wait on futex: %p\n", futex); - if (pthread_create(&waiter, NULL, waiterfn, (void *) &flags)) - error("pthread_create failed\n", errno); + res = pthread_create(&waiter, NULL, waiterfn, (void *) &flags); + if (res) + error("pthread_create failed\n", res); usleep(WAKE_WAIT_US); @@ -106,8 +107,9 @@ int main(int argc, char *argv[]) futex = shared_data; info("Calling shared (page anon) futex_wait on futex: %p\n", futex); - if (pthread_create(&waiter, NULL, waiterfn, NULL)) - error("pthread_create failed\n", errno); + res = pthread_create(&waiter, NULL, waiterfn, NULL); + if (res) + error("pthread_create failed\n", res); usleep(WAKE_WAIT_US); @@ -145,8 +147,9 @@ int main(int argc, char *argv[]) futex = shm; info("Calling shared (file backed) futex_wait on futex: %p\n", futex); - if (pthread_create(&waiter, NULL, waiterfn, NULL)) - error("pthread_create failed\n", errno); + res = pthread_create(&waiter, NULL, waiterfn, NULL); + if (res) + error("pthread_create failed\n", res); usleep(WAKE_WAIT_US); diff --git a/tools/testing/selftests/futex/functional/futex_wait_private_mapped_file.c b/tools/testing/selftests/futex/functional/futex_wait_private_mapped_file.c index fb4148f23fa3..7b4a28e8dc1a 100644 --- a/tools/testing/selftests/futex/functional/futex_wait_private_mapped_file.c +++ b/tools/testing/selftests/futex/functional/futex_wait_private_mapped_file.c @@ -100,7 +100,7 @@ int main(int argc, char **argv) basename(argv[0])); ret = pthread_create(&thr, NULL, thr_futex_wait, NULL); - if (ret < 0) { + if (ret) { fprintf(stderr, "pthread_create error\n"); ret = RET_ERROR; goto out; diff --git a/tools/testing/selftests/futex/functional/futex_wait_uninitialized_heap.c b/tools/testing/selftests/futex/functional/futex_wait_uninitialized_heap.c index ed9cd07e31c1..bf7529bd7f0d 100644 --- a/tools/testing/selftests/futex/functional/futex_wait_uninitialized_heap.c +++ b/tools/testing/selftests/futex/functional/futex_wait_uninitialized_heap.c @@ -103,7 +103,7 @@ int main(int argc, char **argv) ret = pthread_create(&thr, NULL, wait_thread, NULL); if (ret) { - error("pthread_create\n", errno); + error("pthread_create\n", ret); ret = RET_ERROR; goto out; } diff --git a/tools/testing/selftests/futex/functional/futex_waitv.c b/tools/testing/selftests/futex/functional/futex_waitv.c index a94337f677e1..d2400b3c7d0a 100644 --- a/tools/testing/selftests/futex/functional/futex_waitv.c +++ b/tools/testing/selftests/futex/functional/futex_waitv.c @@ -94,8 +94,9 @@ int main(int argc, char *argv[]) } /* Private waitv */ - if (pthread_create(&waiter, NULL, waiterfn, NULL)) - error("pthread_create failed\n", errno); + res = pthread_create(&waiter, NULL, waiterfn, NULL); + if (res) + error("pthread_create failed\n", res); usleep(WAKE_WAIT_US); @@ -127,8 +128,9 @@ int main(int argc, char *argv[]) waitv[i].__reserved = 0; } - if (pthread_create(&waiter, NULL, waiterfn, NULL)) - error("pthread_create failed\n", errno); + res = pthread_create(&waiter, NULL, waiterfn, NULL); + if (res) + error("pthread_create failed\n", res); usleep(WAKE_WAIT_US); -- 2.40.0