From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753396AbaHKQ5p (ORCPT ); Mon, 11 Aug 2014 12:57:45 -0400 Received: from mga14.intel.com ([192.55.52.115]:23016 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751523AbaHKQ5o (ORCPT ); Mon, 11 Aug 2014 12:57:44 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.97,862,1389772800"; d="scan'208";a="370928617" Date: Mon, 11 Aug 2014 09:57:39 -0700 From: David Cohen To: Rickard Strandqvist Cc: Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, Kuppuswamy Sathyanarayanan , Fei Yang , Fengguang Wu , linux-kernel@vger.kernel.org Subject: Re: [PATCH] arch: x86: platform: intel-mid: sfi.c: Cleaning up missing null-terminate in conjunction with strncpy Message-ID: <20140811165739.GA26362@psi-dev26.jf.intel.com> References: <1406413618-7691-1-git-send-email-rickard_strandqvist@spectrumdigital.se> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1406413618-7691-1-git-send-email-rickard_strandqvist@spectrumdigital.se> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Rickard, Sorry for the late reply. Just came back from vacation :) On Sun, Jul 27, 2014 at 12:26:58AM +0200, Rickard Strandqvist wrote: > If you are going to use memset before strncpy you must copy sizeof -1 I agree it is way safer to not reply on firmware to have the null terminator in place. But can you provide a better patch description? :) It would be better if it is not a line addressed directly to the author. Please refer the null terminator concern too. Br, David > > Signed-off-by: Rickard Strandqvist > --- > arch/x86/platform/intel-mid/sfi.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/arch/x86/platform/intel-mid/sfi.c b/arch/x86/platform/intel-mid/sfi.c > index 994c40b..97e79c9 100644 > --- a/arch/x86/platform/intel-mid/sfi.c > +++ b/arch/x86/platform/intel-mid/sfi.c > @@ -359,7 +359,7 @@ static void __init sfi_handle_spi_dev(struct sfi_device_table_entry *pentry, > void *pdata = NULL; > > memset(&spi_info, 0, sizeof(spi_info)); > - strncpy(spi_info.modalias, pentry->name, SFI_NAME_LEN); > + strncpy(spi_info.modalias, pentry->name, sizeof(spi_info.modalias) - 1); > spi_info.irq = ((pentry->irq == (u8)0xff) ? 0 : pentry->irq); > spi_info.bus_num = pentry->host_num; > spi_info.chip_select = pentry->addr; > @@ -389,7 +389,7 @@ static void __init sfi_handle_i2c_dev(struct sfi_device_table_entry *pentry, > void *pdata = NULL; > > memset(&i2c_info, 0, sizeof(i2c_info)); > - strncpy(i2c_info.type, pentry->name, SFI_NAME_LEN); > + strncpy(i2c_info.type, pentry->name, sizeof(i2c_info.type) - 1); > i2c_info.irq = ((pentry->irq == (u8)0xff) ? 0 : pentry->irq); > i2c_info.addr = pentry->addr; > pr_debug("I2C bus = %d, name = %16.16s, irq = 0x%2x, addr = 0x%x\n", > -- > 1.7.10.4 >