From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755057AbcJOPc3 (ORCPT ); Sat, 15 Oct 2016 11:32:29 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:48608 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754471AbcJOPcU (ORCPT ); Sat, 15 Oct 2016 11:32:20 -0400 From: Colin King To: Dan Williams , linux-nvdimm@ml01.01.org Cc: linux-kernel@vger.kernel.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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; } -- 2.9.3