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-next>] [day] [month] [year] [list]
Message-Id: <6736b3e4fdc27575cf85503eefe7d0c1aaaced33.1443753647.git.geliangtang@163.com>
Date:	Fri,  2 Oct 2015 10:43:34 +0800
From:	Geliang Tang <geliangtang@....com>
To:	Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
	Sudeep Dutt <sudeep.dutt@...el.com>,
	Nikhil Rao <nikhil.rao@...el.com>,
	Ashutosh Dixit <ashutosh.dixit@...el.com>
Cc:	Geliang Tang <geliangtang@....com>, linux-kernel@...r.kernel.org
Subject: [PATCH] misc: mic: use kstrdup() in mic_sysfs

Use kstrdup instead of kmalloc and strncpy.

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

diff --git a/drivers/misc/mic/host/mic_sysfs.c b/drivers/misc/mic/host/mic_sysfs.c
index 6dd864e..7b67aea 100644
--- a/drivers/misc/mic/host/mic_sysfs.c
+++ b/drivers/misc/mic/host/mic_sysfs.c
@@ -210,18 +210,14 @@ cmdline_store(struct device *dev, struct device_attribute *attr,
 	mutex_lock(&mdev->mic_mutex);
 	kfree(mdev->cmdline);
 
-	mdev->cmdline = kmalloc(count + 1, GFP_KERNEL);
+	mdev->cmdline = kstrdup(buf, GFP_KERNEL);
 	if (!mdev->cmdline) {
 		count = -ENOMEM;
 		goto unlock;
 	}
 
-	strncpy(mdev->cmdline, buf, count);
-
 	if (mdev->cmdline[count - 1] == '\n')
 		mdev->cmdline[count - 1] = '\0';
-	else
-		mdev->cmdline[count] = '\0';
 unlock:
 	mutex_unlock(&mdev->mic_mutex);
 	return count;
@@ -256,17 +252,14 @@ firmware_store(struct device *dev, struct device_attribute *attr,
 	mutex_lock(&mdev->mic_mutex);
 	kfree(mdev->firmware);
 
-	mdev->firmware = kmalloc(count + 1, GFP_KERNEL);
+	mdev->firmware = kstrdup(buf, GFP_KERNEL);
 	if (!mdev->firmware) {
 		count = -ENOMEM;
 		goto unlock;
 	}
-	strncpy(mdev->firmware, buf, count);
 
 	if (mdev->firmware[count - 1] == '\n')
 		mdev->firmware[count - 1] = '\0';
-	else
-		mdev->firmware[count] = '\0';
 unlock:
 	mutex_unlock(&mdev->mic_mutex);
 	return count;
@@ -301,18 +294,14 @@ ramdisk_store(struct device *dev, struct device_attribute *attr,
 	mutex_lock(&mdev->mic_mutex);
 	kfree(mdev->ramdisk);
 
-	mdev->ramdisk = kmalloc(count + 1, GFP_KERNEL);
+	mdev->ramdisk = kstrdup(buf, GFP_KERNEL);
 	if (!mdev->ramdisk) {
 		count = -ENOMEM;
 		goto unlock;
 	}
 
-	strncpy(mdev->ramdisk, buf, count);
-
 	if (mdev->ramdisk[count - 1] == '\n')
 		mdev->ramdisk[count - 1] = '\0';
-	else
-		mdev->ramdisk[count] = '\0';
 unlock:
 	mutex_unlock(&mdev->mic_mutex);
 	return count;
@@ -350,18 +339,14 @@ bootmode_store(struct device *dev, struct device_attribute *attr,
 	mutex_lock(&mdev->mic_mutex);
 	kfree(mdev->bootmode);
 
-	mdev->bootmode = kmalloc(count + 1, GFP_KERNEL);
+	mdev->bootmode = kstrdup(buf, GFP_KERNEL);
 	if (!mdev->bootmode) {
 		count = -ENOMEM;
 		goto unlock;
 	}
 
-	strncpy(mdev->bootmode, buf, count);
-
 	if (mdev->bootmode[count - 1] == '\n')
 		mdev->bootmode[count - 1] = '\0';
-	else
-		mdev->bootmode[count] = '\0';
 unlock:
 	mutex_unlock(&mdev->mic_mutex);
 	return count;
-- 
2.5.0


--
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