From patchwork Mon Nov 6 23:16:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Verma, Vishal L" X-Patchwork-Id: 10044657 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 606566032D for ; Mon, 6 Nov 2017 23:18:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 430C92A0A0 for ; Mon, 6 Nov 2017 23:18:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 37EA62A0A4; Mon, 6 Nov 2017 23:18:34 +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=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham 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 2C4C72A0A3 for ; Mon, 6 Nov 2017 23:18:33 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 8DAB12035D0E6; Mon, 6 Nov 2017 15:14:33 -0800 (PST) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.20; helo=mga02.intel.com; envelope-from=vishal.l.verma@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (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 D8F42202E5E59 for ; Mon, 6 Nov 2017 15:14:32 -0800 (PST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Nov 2017 15:18:31 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.44,355,1505804400"; d="scan'208"; a="1240542285" Received: from omniknight.lm.intel.com ([10.232.112.27]) by fmsmga002.fm.intel.com with ESMTP; 06 Nov 2017 15:18:31 -0800 From: Vishal Verma To: Subject: [ndctl PATCH 2/3] libndctl: add missing error handling in _wait_for_scrub_completion Date: Mon, 6 Nov 2017 16:16:09 -0700 Message-Id: <20171106231610.8271-2-vishal.l.verma@intel.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171106231610.8271-1-vishal.l.verma@intel.com> References: <20171106231610.8271-1-vishal.l.verma@intel.com> X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP Static analysis complains that we could be passing a negative value to close(). The root of the problem is that we neglect to error-check the return from open(). Add that to correctly fix the problem. Also fix a whitespace error in close(). Cc: Dan Williams Signed-off-by: Vishal Verma --- ndctl/lib/libndctl.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c index e78a32c..6737705 100644 --- a/ndctl/lib/libndctl.c +++ b/ndctl/lib/libndctl.c @@ -1114,6 +1114,12 @@ NDCTL_EXPORT int ndctl_bus_wait_for_scrub_completion(struct ndctl_bus *bus) int fd = 0, rc; fd = open(bus->scrub_path, O_RDONLY|O_CLOEXEC); + if (fd < 0) { + err(ctx, "failed to open %s: %s\n", bus->scrub_path, + strerror(errno)); + return -errno; + } + fds.fd = fd; fds.events = POLLPRI | POLLIN; do { @@ -1154,7 +1160,7 @@ NDCTL_EXPORT int ndctl_bus_wait_for_scrub_completion(struct ndctl_bus *bus) dbg(ctx, "bus%d: scrub complete\n", ndctl_bus_get_id(bus)); if (fd) - close (fd); + close(fd); return rc < 0 ? -ENXIO : 0; }