Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7647702rwb; Mon, 12 Dec 2022 18:24:02 -0800 (PST) X-Google-Smtp-Source: AA0mqf4QKV797MryTYppt2sp45YBHVkrgrN2A/Mj2Y6sS0R5X9f1VfzBW7KdtbGx/+K2anqTC9po X-Received: by 2002:a05:6402:1004:b0:46b:c156:9965 with SMTP id c4-20020a056402100400b0046bc1569965mr15502994edu.38.1670898242471; Mon, 12 Dec 2022 18:24:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670898242; cv=none; d=google.com; s=arc-20160816; b=AYFcOeesY6wCrEBGj/WAF99ZsvoB7Uh/8zqCEW75oPMUIH2DvekIQDcBHAQx+SMJpr GtAzWaZjSaHKhD/LcJDZsxXqTG5F5pfWO1RK87E7aqUlme/U/AIyj+spnl4yPmFwVUGd 41guOn4FLz0vEIImyFa9Hw6Q6o1WLWOi2Gl859jULZ1PUS5ZbZDQF2AX215jt0FwBIGB S0a3f4OoAMLmeg50n3Ux4hIdd+m/2RL1jVRAE4gLGGhwUCIvEaXhXInCjLX7ubbROc5m a5O2D2g06zH6TtLSyUy7a3kwerQwVxrVWEM4qZrWAZ38q2WKtwSrZips3xjouU23o9sM gXCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject; bh=moI9kNf4uC7hVOopQFNFcm37JbWu7ObL/nUOxqXh2+M=; b=rOqRKK9ukQa5r3IyT0wWl5+5Q5kx0kGMkdyJZrhEIYgiWdGSAThB4Ji7srBymYSFAO NiprYP4JqxDsFwL5HCrAS2WQA7UMYtzK8DGPR7v1XDRiARVa2d6eXDLh4DxEuDqp19PR yTs3YXU+1cgTgHZJsgQmcjFPNsDiXl0NBpBWXXXTu57aE3oHjdZqFCNlF2FFUJV0EtUO c6UH9qzt5fUldY4CS+klIec/1bNQxljSbmHxCmxfiztobA+At8Ko/ebq1U5/nlzXrhHK GzQJ+YRo+xwmYLq6B/8973XpxeUdRhWqLMGZWWEMOAq+BI6ic64b1YWv+YeE1VDUIsLG 600Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a4-20020a05640213c400b0046b00aab3e3si7302538edx.170.2022.12.12.18.23.41; Mon, 12 Dec 2022 18:24:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234061AbiLMB10 (ORCPT + 74 others); Mon, 12 Dec 2022 20:27:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234052AbiLMB1Z (ORCPT ); Mon, 12 Dec 2022 20:27:25 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3565A13F32; Mon, 12 Dec 2022 17:27:23 -0800 (PST) Received: from dggpemm500005.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NWLRy1yYWzRptt; Tue, 13 Dec 2022 09:26:22 +0800 (CST) Received: from [10.67.102.37] (10.67.102.37) by dggpemm500005.china.huawei.com (7.185.36.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 13 Dec 2022 09:27:21 +0800 Subject: Re: [PATCH net-next v2] hns: use strscpy() to instead of strncpy() To: , References: <202212091533253334827@zte.com.cn> CC: , , , , , , , , From: Hao Lan Message-ID: Date: Tue, 13 Dec 2022 09:27:20 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.7.1 MIME-Version: 1.0 In-Reply-To: <202212091533253334827@zte.com.cn> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.67.102.37] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500005.china.huawei.com (7.185.36.74) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2022/12/9 15:33, yang.yang29@zte.com.cn wrote: > From: Xu Panda > > The implementation of strscpy() is more robust and safer. > That's now the recommended way to copy NUL terminated strings. > > Signed-off-by: Xu Panda > Signed-off-by: Yang Yang > --- > change for v2 > - change the prefix and subject: replace ethtool with hns, > and replace linux-next with net-next. > --- > drivers/net/ethernet/hisilicon/hns/hns_ethtool.c | 11 ++++------- > 1 file changed, 4 insertions(+), 7 deletions(-) > > diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c > index 54faf0f2d1d8..b54f3706fb97 100644 > --- a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c > +++ b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c > @@ -644,18 +644,15 @@ static void hns_nic_get_drvinfo(struct net_device *net_dev, > { > struct hns_nic_priv *priv = netdev_priv(net_dev); > > - strncpy(drvinfo->version, HNAE_DRIVER_VERSION, > + strscpy(drvinfo->version, HNAE_DRIVER_VERSION, > sizeof(drvinfo->version)); > - drvinfo->version[sizeof(drvinfo->version) - 1] = '\0'; > > - strncpy(drvinfo->driver, HNAE_DRIVER_NAME, sizeof(drvinfo->driver)); > - drvinfo->driver[sizeof(drvinfo->driver) - 1] = '\0'; > + strscpy(drvinfo->driver, HNAE_DRIVER_NAME, sizeof(drvinfo->driver)); > > - strncpy(drvinfo->bus_info, priv->dev->bus->name, > + strscpy(drvinfo->bus_info, priv->dev->bus->name, > sizeof(drvinfo->bus_info)); > - drvinfo->bus_info[ETHTOOL_BUSINFO_LEN - 1] = '\0'; > > - strncpy(drvinfo->fw_version, "N/A", ETHTOOL_FWVERS_LEN); > + strscpy(drvinfo->fw_version, "N/A", ETHTOOL_FWVERS_LEN); > drvinfo->eedump_len = 0; > } > Reviewed-by: Hao Lan