Skip to contentSkip to conversation

intel_th: msu: fix missing allocation failure check on a kstrndup

PATCH New Colin King 1 participant 1 message Jul 26, 2019

Subsystems (3)
lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH 1/1 intel_th: msu: fix missing allocation failure check on a kstrndup

From: Colin Ian King <[email protected]>

kstrndup can potentially return NULL, so add a null memory check to avoid a null pointer reference later on.

Addresses-Coverity: ("Dereference null return")

Fixes 615c164da0eb ("intel_th: msu: Introduce buffer interface")
---
 drivers/hwtracing/intel_th/msu.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/hwtracing/intel_th/msu.c +2 -0
index 4892ac446c01..dd7e3c304ee5 100644
@@ -1848,6 +1848,8 @@ mode_store(struct device *dev, struct device_attribute *attr, const char *buf,
 		len = cp - buf;
 
 	mode = kstrndup(buf, len, GFP_KERNEL);
+	if (!mode)
+		return -ENOMEM;
 	i = match_string(msc_mode, ARRAY_SIZE(msc_mode), mode);
 	if (i >= 0)
 		goto found;
Signature · 1 line
2.20.1