From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7553C4332F for ; Tue, 13 Dec 2022 01:27:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234056AbiLMB10 (ORCPT ); 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 Precedence: bulk List-ID: X-Mailing-List: netdev@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