Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1237884

[PATCH] misc: mic: use kstrdup() in mic_sysfs

Path csiph.com!eternal-september.org!feeder.eternal-september.org!weretis.net!feeder1.news.weretis.net!newsfeed.CARNet.hr!news.spin.it!bofh.it!news.nic.it!robomod
From Geliang Tang <geliangtang@163.com>
Newsgroups linux.kernel
Subject [PATCH] misc: mic: use kstrdup() in mic_sysfs
Date Fri, 02 Oct 2015 04:50:01 +0200
Message-ID <qeYA1-72P-1@gated-at.bofh.it> (permalink)
X-Original-To Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Sudeep Dutt <sudeep.dutt@intel.com>, Nikhil Rao <nikhil.rao@intel.com>, Ashutosh Dixit <ashutosh.dixit@intel.com>
Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=nOTBg8SUKtZciXOenX Hwg832M+md3yVGlB0EbV5Oq4k=; b=mSdY5p9ut72x8ZV0tpbQ2liUxK8t3j8J8x 40RSNsac+Pb2W4vzYIJZeTn5yOjyVp84fq5ubzxbO1p0UePTTn3TGr/6phzMMl4S Mfe8nDOT1/UuFgipcpXSIIhbYrOAVjm1BJIKACnUNmtZ5OJjhfrUIag7cO+6MWN0 G65Rlsc9o=
X-Mailer git-send-email 2.5.0
X-Cm-Transid DtGowECZVkdY7w1WECx8AA--.43606S3
X-Coremail-Antispam 1Uf129KBjvJXoWxXFW8ZF45AF4rZr43try7Wrg_yoW5Gr4fpa yxXFW3tr4rJrWkX34kCw43ur15Ww4UAay5GrWjva4kGFnxZF4Dt345J34kurykAryIkrWY qryjgr4UZF1jgF7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UzT5LUUUUU=
X-Originating-IP [115.45.187.121]
X-Cm-Senderinfo 5jhoxtpqjwt0rj6rljoofrz/1tbiNR+HmVSIJOCRYgABse
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 99
Organization linux.* mail to news gateway
X-Original-Cc Geliang Tang <geliangtang@163.com>, linux-kernel@vger.kernel.org
X-Original-Date Fri, 2 Oct 2015 10:43:34 +0800
X-Original-Message-ID <6736b3e4fdc27575cf85503eefe7d0c1aaaced33.1443753647.git.geliangtang@163.com>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1237884

Show key headers only | View raw


Use kstrdup instead of kmalloc and strncpy.

Signed-off-by: Geliang Tang <geliangtang@163.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@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

[PATCH] misc: mic: use kstrdup() in mic_sysfs Geliang Tang <geliangtang@163.com> - 2015-10-02 04:50 +0200
  Re: [PATCH] misc: mic: use kstrdup() in mic_sysfs Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2015-10-04 14:00 +0200

csiph-web