Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3091969rwb; Mon, 15 Aug 2022 17:56:02 -0700 (PDT) X-Google-Smtp-Source: AA6agR6T+jYgeQiKUAeOUG0Yf28aQgnR/TqAAVDdsXLXD0lrldcBzQAU6rPZQIqjREq06525d5gL X-Received: by 2002:a17:906:c10:b0:6f4:6c70:b00f with SMTP id s16-20020a1709060c1000b006f46c70b00fmr12213578ejf.660.1660611361828; Mon, 15 Aug 2022 17:56:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660611361; cv=none; d=google.com; s=arc-20160816; b=m7REReUF/LHPQ+nzfYj0cZtbdK44626zTA4CSs90CDmAARY3LlLdTFpv9M4k4xkRiu iU56nlblxmbaCAB/FWhRDLRilYH8yK2Kw/ft+FgbcdiQSwm9P7Id/vHkUiINsVfQatub 6e1PRcnNBHjxrrExtkFNs/NaZ6wY6llzslgRsaTl+w9rapjLItt57z650O7GOFrrJVGz JUJMgb3I5603bZXP7sil2wX+h1ElcDr9zl/Qz8wPgDh9EVeHD3NtczHZ9kdl3a/Nc2l1 A0ZgH3wUUaoiDjcDj3X5QVk8uXS7WoGy5amxrlB2RfC6QGQQDEdJBpo3RgOwzPeQXq1+ aenA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=NOxYa1OFsiC7MThWvcEhO/cslQv8+moeClLswvlsabQ=; b=P63xeZ5i6+aSYEtZedS+tpXtl1zEzWyC61prETO6+vd5oqsyth1/+Jz0hbYD1sqeYe lxf4YVRUoTknZPeJDV3vZnakbTICTWktqrVFDT1d75IgAACGP8VctNCZbAOZPsp2Jxfi yeQUDdGUjnq/lja7WIJZfELva1lRIKJe2URxaAcQSm1u4k99bevE0hZd3Je4l8H+/3h7 2/Boxlvibwgb5KI7Ebq51DHCmABH1D7Z0cbLKOhWeG3WvPez2YuTFBNmUX8LMoaZwK+/ u1JdmAu5h5I+wvsB+8SKUbGBcz8yGx4t8p8IsSybgsP6sHp471LPUIVhrR5sNSSRcpIt Hb+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=SDLQR2Ee; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lz5-20020a170906fb0500b00730c1b3d753si7069074ejb.424.2022.08.15.17.55.34; Mon, 15 Aug 2022 17:56:01 -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=@linuxfoundation.org header.s=korg header.b=SDLQR2Ee; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345982AbiHPAhm (ORCPT + 99 others); Mon, 15 Aug 2022 20:37:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350568AbiHPAgI (ORCPT ); Mon, 15 Aug 2022 20:36:08 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97B174E84D; Mon, 15 Aug 2022 13:37:36 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 76D2EB80EA9; Mon, 15 Aug 2022 20:37:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ACAC8C433C1; Mon, 15 Aug 2022 20:37:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660595843; bh=J7tXZQAKQ1Enn9d8Kao/WXR5L8k8qxeZb02P9k8WmdI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SDLQR2Ee4BWI71QtCKMh9IZyclVJgQjUpg6D/s+T+jmQuinyTq5EG7Q8pLx5K/x6d BSpLbJQI/9TW0jB/7nmrQkXJcmi4tFmpdfft25Zp7FwIPsIGBz/063ZQDOY4MhZyvR H/K9jpIUM2zI866muamL40PXDebzkjavK8AMdPME= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Adam Sindelar , David Vernet , Suren Baghdasaryan , Shuah Khan , Andrew Morton , Sasha Levin Subject: [PATCH 5.19 0865/1157] selftests/vm: fix errno handling in mrelease_test Date: Mon, 15 Aug 2022 20:03:41 +0200 Message-Id: <20220815180514.070470167@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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: Adam Sindelar [ Upstream commit 3b8e7f5c42d1aa44f71fd219717c80e34101361e ] mrelease_test should return KSFT_SKIP when process_mrelease is not defined, but due to a perror call consuming the errno, it returns KSFT_FAIL. This patch decides the exit code before calling perror. [adam@wowsignal.io: fix remaining instances of errno mishandling] Link: https://lkml.kernel.org/r/20220706141602.10159-1-adam@wowsignal.io Link: https://lkml.kernel.org/r/20220704173351.19595-1-adam@wowsignal.io Fixes: 33776141b812 ("selftests: vm: add process_mrelease tests") Signed-off-by: Adam Sindelar Reviewed-by: David Vernet Reviewed-by: Suren Baghdasaryan Cc: Shuah Khan Signed-off-by: Andrew Morton Signed-off-by: Sasha Levin --- tools/testing/selftests/vm/mrelease_test.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/vm/mrelease_test.c b/tools/testing/selftests/vm/mrelease_test.c index 96671c2f7d48..6c62966ab5db 100644 --- a/tools/testing/selftests/vm/mrelease_test.c +++ b/tools/testing/selftests/vm/mrelease_test.c @@ -62,19 +62,22 @@ static int alloc_noexit(unsigned long nr_pages, int pipefd) /* The process_mrelease calls in this test are expected to fail */ static void run_negative_tests(int pidfd) { + int res; /* Test invalid flags. Expect to fail with EINVAL error code. */ if (!syscall(__NR_process_mrelease, pidfd, (unsigned int)-1) || errno != EINVAL) { + res = (errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL); perror("process_mrelease with wrong flags"); - exit(errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL); + exit(res); } /* * Test reaping while process is alive with no pending SIGKILL. * Expect to fail with EINVAL error code. */ if (!syscall(__NR_process_mrelease, pidfd, 0) || errno != EINVAL) { + res = (errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL); perror("process_mrelease on a live process"); - exit(errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL); + exit(res); } } @@ -100,8 +103,9 @@ int main(void) /* Test a wrong pidfd */ if (!syscall(__NR_process_mrelease, -1, 0) || errno != EBADF) { + res = (errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL); perror("process_mrelease with wrong pidfd"); - exit(errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL); + exit(res); } /* Start the test with 1MB child memory allocation */ @@ -156,8 +160,9 @@ int main(void) run_negative_tests(pidfd); if (kill(pid, SIGKILL)) { + res = (errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL); perror("kill"); - exit(errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL); + exit(res); } success = (syscall(__NR_process_mrelease, pidfd, 0) == 0); @@ -172,9 +177,10 @@ int main(void) if (errno == ESRCH) { retry = (size <= MAX_SIZE_MB); } else { + res = (errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL); perror("process_mrelease"); waitpid(pid, NULL, 0); - exit(errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL); + exit(res); } } -- 2.35.1