From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751284AbbJKBB7 (ORCPT ); Sat, 10 Oct 2015 21:01:59 -0400 Received: from mga14.intel.com ([192.55.52.115]:7911 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750775AbbJKBB6 (ORCPT ); Sat, 10 Oct 2015 21:01:58 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,665,1437462000"; d="scan'208";a="578143430" From: Ashutosh Dixit To: Geliang Tang Cc: Joe Perches , Greg Kroah-Hartman , "Dutt\, Sudeep" , "Rao\, Nikhil" , "linux-kernel\@vger.kernel.org" Subject: Re: [PATCH] misc: mic: use kstrdup() in cosm_sysfs References: <5099ee411bd5797e8c24a4e2daa6c58f119ab9ce.1444505802.git.geliangtang@163.com> <1444504470.8012.15.camel@perches.com> Date: Sat, 10 Oct 2015 18:01:57 -0700 In-Reply-To: <1444504470.8012.15.camel@perches.com> (Joe Perches's message of "Sat, 10 Oct 2015 13:14:30 -0600") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Oct 10 2015 at 12:14:30 PM, Joe Perches wrote: > On Sat, 2015-10-10 at 04:46 -0700, Geliang Tang wrote: >> Use kstrdup instead of kmalloc and strncpy. > >> diff --git 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); >> > As count is a function argument, this isn't the same code. > Correct, is this code safe for unterminated strings from user land?