From patchwork Fri Jan 12 11:46:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiongfeng Wang X-Patchwork-Id: 124303 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1951822qgn; Fri, 12 Jan 2018 03:41:02 -0800 (PST) X-Google-Smtp-Source: ACJfBouH0G8kdipfOy3gUf3X9f28hK9hlAsiKjjZSIwvBmCiJrK7NWboKmJJkOhHvn2T14T8t9LX X-Received: by 10.99.56.8 with SMTP id f8mr20132103pga.438.1515757262671; Fri, 12 Jan 2018 03:41:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515757262; cv=none; d=google.com; s=arc-20160816; b=DBgr+lSL8AwXcl83afre7/90eBtOwulC2566SwTjkhWpfpqxSYwg0Xgq24AZDGyED4 lYe0N7EXmfXvcLqZxJyZd4HcSY+CG+f+C11yAg7gKT1X99RNt6aOG+NAOYr1+hwLhOso NuGbthUakbesfPlqn6TjvPinlOZwR7iJMMnDXkxLskpHmDKUg/ruczREXRd1KpODI+Oz ivIF0DuQHQ6pn3CgpieJhu3PEnPFj+SInnDUPlpfTVe6VbU885hx8Ud1CsJ636oSIkpS BySE67EfFdAuSziYXnIxcYAW1FESH9wNI2ziI4g4eVNrnkWPuRbctv3U4rV8Riwf3pZb 81fA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:arc-authentication-results; bh=NA1MuTF1MsutKVu6zhnGZiC/ZkFLhJEv1BokYrPvd+w=; b=OVtE4Wx3fQZsHMYg/0uFni8fJGI/mxP9mc5hXvSlQ4ERk2Ooq77yZ+C8u+ASRMbb5F ERqV7gwIDy17MWXSfIlzbPuE0kFG3V9Oj9eiaibaKZSYcnsmRmFQ+jOiIFiVz9mkr4qs DONyCZq6sDd237eMmZDP8oKfxuA0f3Qw7W8ckx6P5x+ivNnMyRuiYfew5I3Fd0o8s+Th 483a/EMEhSZcueHQftM67O8LEHUl0h9X0K0wNkc+SjOW81/YanL9CEoyVDEA4unq8fgA LevVFRHV83FLFYUEZyE+CuSvR1IEDIQ3dWS/fVpssM1ucdBSzQ6u5J8K/T3P57NR55th IVBw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-scsi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c22si1921254plz.127.2018.01.12.03.41.02; Fri, 12 Jan 2018 03:41:02 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-scsi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-scsi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754514AbeALLlB (ORCPT + 1 other); Fri, 12 Jan 2018 06:41:01 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:3781 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754403AbeALLlB (ORCPT ); Fri, 12 Jan 2018 06:41:01 -0500 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 186A3130C756B; Fri, 12 Jan 2018 19:40:45 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.361.1; Fri, 12 Jan 2018 19:40:37 +0800 From: Xiongfeng Wang To: , , CC: , Subject: [PATCH] mptfusion: use strlcpy() instead of strncpy() Date: Fri, 12 Jan 2018 19:46:59 +0800 Message-ID: <1515757619-29651-1-git-send-email-wangxiongfeng2@huawei.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-CFilter-Loop: Reflected Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Xiongfeng Wang drivers/message/fusion/mptctl.c: In function '__mptctl_ioctl.isra.3': ./include/linux/string.h:245:9: warning: '__builtin_strncpy' specified bound 12 equals destination size [-Wstringop-truncation] The compiler requires that the destination size should be greater than the length we copy to make sure the dest string is nul-terminated. We can just use strlcpy() to avoid this warning. Signed-off-by: Xiongfeng Wang --- drivers/message/fusion/mptctl.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) -- 1.8.3.1 diff --git a/drivers/message/fusion/mptctl.c b/drivers/message/fusion/mptctl.c index 7b3b413..15f2aca 100644 --- a/drivers/message/fusion/mptctl.c +++ b/drivers/message/fusion/mptctl.c @@ -1353,8 +1353,7 @@ static int mptctl_do_reset(unsigned long arg) /* Set the Version Strings. */ - strncpy (karg->driverVersion, MPT_LINUX_PACKAGE_NAME, MPT_IOCTL_VERSION_LENGTH); - karg->driverVersion[MPT_IOCTL_VERSION_LENGTH-1]='\0'; + strlcpy (karg->driverVersion, MPT_LINUX_PACKAGE_NAME, MPT_IOCTL_VERSION_LENGTH); karg->busChangeEvent = 0; karg->hostId = ioc->pfacts[port].PortSCSIID; @@ -1542,10 +1541,8 @@ static int mptctl_do_reset(unsigned long arg) #else karg.chip_type = ioc->pcidev->device; #endif - strncpy (karg.name, ioc->name, MPT_MAX_NAME); - karg.name[MPT_MAX_NAME-1]='\0'; - strncpy (karg.product, ioc->prod_name, MPT_PRODUCT_LENGTH); - karg.product[MPT_PRODUCT_LENGTH-1]='\0'; + strlcpy (karg.name, ioc->name, MPT_MAX_NAME); + strlcpy (karg.product, ioc->prod_name, MPT_PRODUCT_LENGTH); /* Copy the data from kernel memory to user memory */ @@ -2513,7 +2510,7 @@ static int mptctl_do_reset(unsigned long arg) cfg.dir = 0; /* read */ cfg.timeout = 10; - strncpy(karg.serial_number, " ", 24); + strlcpy(karg.serial_number, " ", 24); if (mpt_config(ioc, &cfg) == 0) { if (cfg.cfghdr.hdr->PageLength > 0) { /* Issue the second config page request */ @@ -2525,8 +2522,8 @@ static int mptctl_do_reset(unsigned long arg) if (mpt_config(ioc, &cfg) == 0) { ManufacturingPage0_t *pdata = (ManufacturingPage0_t *) pbuf; if (strlen(pdata->BoardTracerNumber) > 1) { - strncpy(karg.serial_number, pdata->BoardTracerNumber, 24); - karg.serial_number[24-1]='\0'; + strlcpy(karg.serial_number, + pdata->BoardTracerNumber, 24); } } pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, pbuf, buf_dma);