From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751356AbbJJLw2 (ORCPT ); Sat, 10 Oct 2015 07:52:28 -0400 Received: from m12-16.163.com ([220.181.12.16]:47595 "EHLO m12-16.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750731AbbJJLw1 (ORCPT ); Sat, 10 Oct 2015 07:52:27 -0400 From: Geliang Tang To: Greg Kroah-Hartman Cc: Geliang Tang , Sudeep Dutt , Nikhil Rao , Ashutosh Dixit , linux-kernel@vger.kernel.org Subject: [PATCH] misc: mic: use kstrdup() in cosm_sysfs Date: Sat, 10 Oct 2015 04:46:36 -0700 Message-Id: <5099ee411bd5797e8c24a4e2daa6c58f119ab9ce.1444505802.git.geliangtang@163.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <20151004115614.GA29316@kroah.com> X-CM-TRANSID: EMCowECJYViv+hhWXpF8DQ--.9059S3 X-Coremail-Antispam: 1Uf129KBjvJXoWxCw4UKw15GF18AF17GrW3KFg_yoW5GrWUpa 4fXFW3tw4rXrykXrykJa13Wr13Ww4UWa13Gryjyas5WFn8AF1Dt345Jry0kr93CF92kFWa qryYgr45ZF1UWr7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UYYL9UUUUU= X-Originating-IP: [218.17.162.133] X-CM-SenderInfo: 5jhoxtpqjwt0rj6rljoofrz/1tbiNRGPmVSIJZ7PiAAAsS Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use kstrdup instead of kmalloc and strncpy. Signed-off-by: Geliang Tang --- 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