From patchwork Sat Oct 15 15:32:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin King X-Patchwork-Id: 9377811 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 F09AB600CA for ; Sat, 15 Oct 2016 15:32:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E17FD294A6 for ; Sat, 15 Oct 2016 15:32:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D5DD4294AA; Sat, 15 Oct 2016 15:32:21 +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=-0.0 required=2.0 tests=BAYES_40, 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 68584294A6 for ; Sat, 15 Oct 2016 15:32:20 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 7D9A61A1E3A; Sat, 15 Oct 2016 08:32:20 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from youngberry.canonical.com (youngberry.canonical.com [91.189.89.112]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 1457B1A1E3A for ; Sat, 15 Oct 2016 08:32:19 -0700 (PDT) Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.76) (envelope-from ) id 1bvQwZ-0005Wt-0x; Sat, 15 Oct 2016 15:32:15 +0000 From: Colin King To: Dan Williams , linux-nvdimm@lists.01.org Subject: [PATCH] libnvdimm: fix dereference on null devs on error exit path Date: Sat, 15 Oct 2016 16:32:14 +0100 Message-Id: <20161015153214.26783-1-colin.king@canonical.com> X-Mailer: git-send-email 2.9.3 MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP From: Colin Ian King If devs cannot be allocated then the error exit path jumps to a cleanup loop that iterates over a null array of devs which is incorrect. Fix this by jumping instead to the end of the function where NULL is returned. Signed-off-by: Colin Ian King --- drivers/nvdimm/namespace_devs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_devs.c index 3509cff..5d2755a 100644 --- a/drivers/nvdimm/namespace_devs.c +++ b/drivers/nvdimm/namespace_devs.c @@ -2125,7 +2125,7 @@ static struct device **scan_labels(struct nd_region *nd_region) devs = kcalloc(2, sizeof(dev), GFP_KERNEL); if (!devs) - goto err; + goto err_ret; if (is_nd_blk(&nd_region->dev)) { struct nd_namespace_blk *nsblk; @@ -2182,6 +2182,7 @@ static struct device **scan_labels(struct nd_region *nd_region) else namespace_pmem_release(devs[i]); kfree(devs); + err_ret: return NULL; }