lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Sat, 10 Oct 2015 04:46:36 -0700
From:	Geliang Tang <geliangtang@....com>
To:	Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc:	Geliang Tang <geliangtang@....com>,
	Sudeep Dutt <sudeep.dutt@...el.com>,
	Nikhil Rao <nikhil.rao@...el.com>,
	Ashutosh Dixit <ashutosh.dixit@...el.com>,
	linux-kernel@...r.kernel.org
Subject: [PATCH] misc: mic: use kstrdup() in cosm_sysfs

Use kstrdup instead of kmalloc and strncpy.

Signed-off-by: Geliang Tang <geliangtang@....com>
---
 drivers/misc/mic/cosm/cosm_sysfs.c | 23 ++++-------------------
 1 file changed, 4 insertions(+), 19 deletions(-)

diff --git a/drivers/misc/mic/cosm/cosm_sysfs.c b/drivers/misc/mic/cosm/cosm_sysfs.c
index 29d6863..c3db466 100644
--- a/drivers/misc/mic/cosm/cosm_sysfs.c
+++ b/drivers/misc/mic/cosm/cosm_sysfs.c
@@ -211,18 +211,14 @@ cmdline_store(struct device *dev, struct device_attribute *attr,
 	mutex_lock(&cdev->cosm_mutex);
 	kfree(cdev->cmdline);
 
-	cdev->cmdline = kmalloc(count + 1, GFP_KERNEL);
+	cdev->cmdline = kstrdup(buf, GFP_KERNEL);
 	if (!cdev->cmdline) {
 		count = -ENOMEM;
 		goto unlock;
 	}
 
-	strncpy(cdev->cmdline, buf, count);
-
 	if (cdev->cmdline[count - 1] == '\n')
 		cdev->cmdline[count - 1] = '\0';
-	else
-		cdev->cmdline[count] = '\0';
 unlock:
 	mutex_unlock(&cdev->cosm_mutex);
 	return count;
@@ -257,17 +253,14 @@ firmware_store(struct device *dev, struct device_attribute *attr,
 	mutex_lock(&cdev->cosm_mutex);
 	kfree(cdev->firmware);
 
-	cdev->firmware = kmalloc(count + 1, GFP_KERNEL);
+	cdev->firmware = kstrdup(buf, GFP_KERNEL);
 	if (!cdev->firmware) {
 		count = -ENOMEM;
 		goto unlock;
 	}
-	strncpy(cdev->firmware, buf, count);
 
 	if (cdev->firmware[count - 1] == '\n')
 		cdev->firmware[count - 1] = '\0';
-	else
-		cdev->firmware[count] = '\0';
 unlock:
 	mutex_unlock(&cdev->cosm_mutex);
 	return count;
@@ -302,18 +295,14 @@ ramdisk_store(struct device *dev, struct device_attribute *attr,
 	mutex_lock(&cdev->cosm_mutex);
 	kfree(cdev->ramdisk);
 
-	cdev->ramdisk = kmalloc(count + 1, GFP_KERNEL);
+	cdev->ramdisk = kstrdup(buf, GFP_KERNEL);
 	if (!cdev->ramdisk) {
 		count = -ENOMEM;
 		goto unlock;
 	}
 
-	strncpy(cdev->ramdisk, buf, count);
-
 	if (cdev->ramdisk[count - 1] == '\n')
 		cdev->ramdisk[count - 1] = '\0';
-	else
-		cdev->ramdisk[count] = '\0';
 unlock:
 	mutex_unlock(&cdev->cosm_mutex);
 	return count;
@@ -351,18 +340,14 @@ bootmode_store(struct device *dev, struct device_attribute *attr,
 	mutex_lock(&cdev->cosm_mutex);
 	kfree(cdev->bootmode);
 
-	cdev->bootmode = kmalloc(count + 1, GFP_KERNEL);
+	cdev->bootmode = kstrdup(buf, GFP_KERNEL);
 	if (!cdev->bootmode) {
 		count = -ENOMEM;
 		goto unlock;
 	}
 
-	strncpy(cdev->bootmode, buf, count);
-
 	if (cdev->bootmode[count - 1] == '\n')
 		cdev->bootmode[count - 1] = '\0';
-	else
-		cdev->bootmode[count] = '\0';
 unlock:
 	mutex_unlock(&cdev->cosm_mutex);
 	return count;
-- 
1.9.1


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ