public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Aditya Pakki <pakki001@umn.edu>,
	Dan Williams <dan.j.williams@intel.com>,
	Sasha Levin <sashal@kernel.org>,
	linux-nvdimm@lists.01.org
Subject: [PATCH AUTOSEL 4.9 06/25] libnvdimm/btt: Fix a kmemdup failure check
Date: Tue,  7 May 2019 01:41:03 -0400	[thread overview]
Message-ID: <20190507054123.32514-6-sashal@kernel.org> (raw)
In-Reply-To: <20190507054123.32514-1-sashal@kernel.org>

From: Aditya Pakki <pakki001@umn.edu>

[ Upstream commit 486fa92df4707b5df58d6508728bdb9321a59766 ]

In case kmemdup fails, the fix releases resources and returns to
avoid the NULL pointer dereference.

Signed-off-by: Aditya Pakki <pakki001@umn.edu>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/nvdimm/btt_devs.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/drivers/nvdimm/btt_devs.c b/drivers/nvdimm/btt_devs.c
index 97dd2925ed6e..5d2c76682848 100644
--- a/drivers/nvdimm/btt_devs.c
+++ b/drivers/nvdimm/btt_devs.c
@@ -190,14 +190,15 @@ static struct device *__nd_btt_create(struct nd_region *nd_region,
 		return NULL;
 
 	nd_btt->id = ida_simple_get(&nd_region->btt_ida, 0, 0, GFP_KERNEL);
-	if (nd_btt->id < 0) {
-		kfree(nd_btt);
-		return NULL;
-	}
+	if (nd_btt->id < 0)
+		goto out_nd_btt;
 
 	nd_btt->lbasize = lbasize;
-	if (uuid)
+	if (uuid) {
 		uuid = kmemdup(uuid, 16, GFP_KERNEL);
+		if (!uuid)
+			goto out_put_id;
+	}
 	nd_btt->uuid = uuid;
 	dev = &nd_btt->dev;
 	dev_set_name(dev, "btt%d.%d", nd_region->id, nd_btt->id);
@@ -212,6 +213,13 @@ static struct device *__nd_btt_create(struct nd_region *nd_region,
 		return NULL;
 	}
 	return dev;
+
+out_put_id:
+	ida_simple_remove(&nd_region->btt_ida, nd_btt->id);
+
+out_nd_btt:
+	kfree(nd_btt);
+	return NULL;
 }
 
 struct device *nd_btt_create(struct nd_region *nd_region)
-- 
2.20.1


  parent reply	other threads:[~2019-05-07  5:46 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-07  5:40 [PATCH AUTOSEL 4.9 01/25] iio: adc: xilinx: fix potential use-after-free on remove Sasha Levin
2019-05-07  5:40 ` [PATCH AUTOSEL 4.9 02/25] libnvdimm/namespace: Fix a potential NULL pointer dereference Sasha Levin
2019-05-07  5:41 ` [PATCH AUTOSEL 4.9 03/25] HID: input: add mapping for Expose/Overview key Sasha Levin
2019-05-07  5:41 ` [PATCH AUTOSEL 4.9 04/25] HID: input: add mapping for keyboard Brightness Up/Down/Toggle keys Sasha Levin
2019-05-07  5:41 ` [PATCH AUTOSEL 4.9 05/25] HID: input: add mapping for "Toggle Display" key Sasha Levin
2019-05-07  5:41 ` Sasha Levin [this message]
2019-05-07  5:41 ` [PATCH AUTOSEL 4.9 07/25] s390/dasd: Fix capacity calculation for large volumes Sasha Levin
2019-05-07  5:41 ` [PATCH AUTOSEL 4.9 08/25] mac80211: fix unaligned access in mesh table hash function Sasha Levin
2019-05-07  5:41 ` [PATCH AUTOSEL 4.9 09/25] Input: snvs_pwrkey - initialize necessary driver data before enabling IRQ Sasha Levin
2019-05-07  5:41 ` [PATCH AUTOSEL 4.9 10/25] s390/3270: fix lockdep false positive on view->lock Sasha Levin
2019-05-07  5:41 ` [PATCH AUTOSEL 4.9 11/25] mISDN: Check address length before reading address family Sasha Levin
2019-05-07  5:41 ` [PATCH AUTOSEL 4.9 12/25] x86/reboot, efi: Use EFI reboot for Acer TravelMate X514-51T Sasha Levin
2019-05-07  5:41 ` [PATCH AUTOSEL 4.9 13/25] KVM: x86: avoid misreporting level-triggered irqs as edge-triggered in tracing Sasha Levin
2019-05-07  5:41 ` [PATCH AUTOSEL 4.9 14/25] tools lib traceevent: Fix missing equality check for strcmp Sasha Levin
2019-05-07  5:41 ` [PATCH AUTOSEL 4.9 15/25] init: initialize jump labels before command line option parsing Sasha Levin
2019-05-07  5:41 ` [PATCH AUTOSEL 4.9 16/25] selftests: netfilter: check icmp pkttoobig errors are set as related Sasha Levin
2019-05-07  5:41 ` [PATCH AUTOSEL 4.9 17/25] ipvs: do not schedule icmp errors from tunnels Sasha Levin
2019-05-07  5:41 ` [PATCH AUTOSEL 4.9 18/25] MIPS: perf: ath79: Fix perfcount IRQ assignment Sasha Levin
2019-06-06 21:28   ` Petr Štetiar
2019-06-09 10:05     ` Greg KH
2019-05-07  5:41 ` [PATCH AUTOSEL 4.9 19/25] s390: ctcm: fix ctcm_new_device error return code Sasha Levin
2019-05-07  5:41 ` [PATCH AUTOSEL 4.9 20/25] drm/sun4i: Set device driver data at bind time for use in unbind Sasha Levin
2019-05-07  5:41 ` [PATCH AUTOSEL 4.9 21/25] selftests/net: correct the return value for run_netsocktests Sasha Levin
2019-05-07  5:41 ` [PATCH AUTOSEL 4.9 22/25] gpu: ipu-v3: dp: fix CSC handling Sasha Levin
2019-05-07  5:41 ` [PATCH AUTOSEL 4.9 23/25] spi: Micrel eth switch: declare missing of table Sasha Levin
2019-05-07  5:41 ` [PATCH AUTOSEL 4.9 24/25] spi: ST ST95HF NFC: " Sasha Levin
2019-05-07  5:41 ` [PATCH AUTOSEL 4.9 25/25] Input: synaptics-rmi4 - fix possible double free Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190507054123.32514-6-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=dan.j.williams@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nvdimm@lists.01.org \
    --cc=pakki001@umn.edu \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox