From patchwork Wed Jun 20 22:51:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Zwisler X-Patchwork-Id: 10478811 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3A1DC60532 for ; Wed, 20 Jun 2018 22:56:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1F44529027 for ; Wed, 20 Jun 2018 22:56:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1DB8A2908A; Wed, 20 Jun 2018 22:56:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8BA0B29027 for ; Wed, 20 Jun 2018 22:51:53 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 2C76F211C6076; Wed, 20 Jun 2018 15:51:53 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: None (no SPF record) identity=mailfrom; client-ip=192.55.52.88; helo=mga01.intel.com; envelope-from=ross.zwisler@linux.intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id C7FE6211BFCDA for ; Wed, 20 Jun 2018 15:51:51 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Jun 2018 15:51:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,249,1526367600"; d="scan'208";a="68669669" Received: from theros.lm.intel.com ([10.232.112.164]) by orsmga002.jf.intel.com with ESMTP; 20 Jun 2018 15:51:50 -0700 From: Ross Zwisler To: Eryu Guan , fstests@vger.kernel.org Subject: [fstests PATCH 1/2] src/: fix up mmap() error checking Date: Wed, 20 Jun 2018 16:51:46 -0600 Message-Id: <20180620225147.12151-1-ross.zwisler@linux.intel.com> X-Mailer: git-send-email 2.14.4 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jan Kara , linux-nvdimm@lists.01.org, Dave Chinner , Christoph Hellwig , linux-ext4@vger.kernel.org MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP I noticed that in some of my C tests in src/ I was incorrectly checking for mmap() failure by looking for NULL instead of MAP_FAILED. Fix those and clean up some places where we were testing against -1 (the actual value of MAP_FAILED) which was manually being cast to a pointer. Signed-off-by: Ross Zwisler --- src/aio-dio-regress/aio-io-setup-with-nonwritable-context-pointer.c | 2 +- src/fstest.c | 2 +- src/t_ext4_dax_inline_corruption.c | 4 ++-- src/t_ext4_dax_journal_corruption.c | 4 ++-- src/t_mmap_stale_pmd.c | 2 ++ src/t_mmap_writev.c | 2 +- 6 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/aio-dio-regress/aio-io-setup-with-nonwritable-context-pointer.c b/src/aio-dio-regress/aio-io-setup-with-nonwritable-context-pointer.c index 092cbb42..af381177 100644 --- a/src/aio-dio-regress/aio-io-setup-with-nonwritable-context-pointer.c +++ b/src/aio-dio-regress/aio-io-setup-with-nonwritable-context-pointer.c @@ -40,7 +40,7 @@ main(int __attribute__((unused)) argc, char **argv) void *addr; addr = mmap(NULL, 4096, PROT_READ, MAP_SHARED|MAP_ANONYMOUS, 0, 0); - if (!addr) { + if (addr == MAP_FAILED) { perror("mmap"); exit(1); } diff --git a/src/fstest.c b/src/fstest.c index f7e2d3eb..e4b9e081 100644 --- a/src/fstest.c +++ b/src/fstest.c @@ -138,7 +138,7 @@ bozo! exit(1); } p = mmap(NULL, file_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); - if (p == (char *)-1) { + if (p == MAP_FAILED) { perror("mmap"); exit(1); } diff --git a/src/t_ext4_dax_inline_corruption.c b/src/t_ext4_dax_inline_corruption.c index 4b7d8938..b52bcc0d 100644 --- a/src/t_ext4_dax_inline_corruption.c +++ b/src/t_ext4_dax_inline_corruption.c @@ -37,14 +37,14 @@ int main(int argc, char *argv[]) err_exit("fd"); data = mmap(NULL, len, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); - if (!data) + if (data == MAP_FAILED) err_exit("mmap data"); /* this fallocate turns off inline data and turns on DAX */ fallocate(fd, 0, 0, PAGE(2)); dax_data = mmap(NULL, len, PROT_READ, MAP_SHARED, fd, 0); - if (!dax_data) + if (dax_data == MAP_FAILED) err_exit("mmap dax_data"); /* diff --git a/src/t_ext4_dax_journal_corruption.c b/src/t_ext4_dax_journal_corruption.c index 18a2acdc..fccef8f5 100644 --- a/src/t_ext4_dax_journal_corruption.c +++ b/src/t_ext4_dax_journal_corruption.c @@ -60,7 +60,7 @@ int main(int argc, char *argv[]) fallocate(fd, 0, 0, len); dax_data = mmap(NULL, len, PROT_READ, MAP_SHARED, fd, 0); - if (!dax_data) + if (dax_data == MAP_FAILED) err_exit("mmap dax_data"); /* @@ -76,7 +76,7 @@ int main(int argc, char *argv[]) chattr_cmd(chattr, "+j", file); data = mmap(NULL, len, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); - if (!data) + if (data == MAP_FAILED) err_exit("mmap data"); /* diff --git a/src/t_mmap_stale_pmd.c b/src/t_mmap_stale_pmd.c index b4472227..6a52201c 100644 --- a/src/t_mmap_stale_pmd.c +++ b/src/t_mmap_stale_pmd.c @@ -41,6 +41,8 @@ int main(int argc, char *argv[]) ftruncate(fd, MiB(4)); data = mmap(NULL, MiB(2), PROT_READ, MAP_SHARED, fd, MiB(2)); + if (data == MAP_FAILED) + err_exit("mmap"); /* * This faults in a 2MiB zero page to satisfy the read. diff --git a/src/t_mmap_writev.c b/src/t_mmap_writev.c index e5ca08ab..43acc15f 100644 --- a/src/t_mmap_writev.c +++ b/src/t_mmap_writev.c @@ -51,7 +51,7 @@ int main(int argc, char **argv) if (fd==-1) {perror("open");exit(1);} base = mmap(NULL,16384,PROT_READ,MAP_SHARED,fd,0); - if (base == (void *)-1) { perror("mmap");exit(1); } + if (base == MAP_FAILED) { perror("mmap");exit(1); } unlink(new_file);