Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2358390rwb; Fri, 9 Dec 2022 00:45:33 -0800 (PST) X-Google-Smtp-Source: AA0mqf4+o2lbnAAYB902y6YZZcMh3McNEUx1wHSRcQ5dfZKLpD/S7GUnwqsXzG85pLKAF73tdwlA X-Received: by 2002:a17:902:a70b:b0:187:ede:e014 with SMTP id w11-20020a170902a70b00b001870edee014mr4877851plq.44.1670575533137; Fri, 09 Dec 2022 00:45:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670575533; cv=none; d=google.com; s=arc-20160816; b=LtVQEoRDffTPE3VmRMSm18RdQL2xwJlLDrZrG0y10XfOpS5NZ2amdVO6G7Zw0lpSrg LXjE6h9NmIdmThR24W0FflRGVYxSu7zdvVuma7HUhc07vsvE4PX3SfaSrxjF5o+R8GYp jsVm43K23u5Rcjk1P9n8FcoY6qEcSM9Chc2/pRxRlc1fxFv6yOwssW+cHRvqIYMQ94il +0rIJtcoyxJZeWfG4NXUjZbQUXeS+dHCRa0Egl/3ekn/bekVA7bJAWtQ0WAM5/OmLd70 nKLLlXJ+QIG9RJFKFm+MUJR6nvvwtx/7Wvgjye3HvzkXAuD9MS4XdynTfaeAOYuZhnku vglA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:cc:to:from:mime-version:message-id:date; bh=DIGpUp8KTxjKyp/Y4jMZQdBbNqkbzaH3BDHsL/G9GWY=; b=ArjyYngX+yKeIAoWVgqyazcYVe2UDq1vDqoh5XLJdO6FzleZ3Xe17w3cIstFjpR2s3 hmWXSylygaSj8TQe1QZBc0HQXrshvYCRUR0lioAugImmy/PZf7vee4IysU89/q3LGVrt IRq4ZcNw1nW9MYiEd5HYcM2StXNlAEztc5Lg3rggtEUnq1fOYacoUNwxiI7GuWpvEcnv PuHcz/KqohYkXS0FLymNDdFAq8dqOTCb6Ik3+KiZ8RgWf7pDqw2GSHi6xQwvv50yVdvy YE6dSsd5zVIx3XNX+18zHVszVeG1EUNUxzNJTar94uS0EbHwdfpGsK9O0Z/WBjEYSSdf 5Neg== 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=NONE sp=NONE dis=NONE) header.from=zte.com.cn Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s15-20020a17090302cf00b001782ecb617dsi1082693plk.412.2022.12.09.00.45.23; Fri, 09 Dec 2022 00:45:33 -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=NONE sp=NONE dis=NONE) header.from=zte.com.cn Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229963AbiLIHdg (ORCPT + 74 others); Fri, 9 Dec 2022 02:33:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229850AbiLIHde (ORCPT ); Fri, 9 Dec 2022 02:33:34 -0500 Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [63.216.63.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 028B7DC8; Thu, 8 Dec 2022 23:33:31 -0800 (PST) Received: from mse-fl2.zte.com.cn (unknown [10.5.228.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mxhk.zte.com.cn (FangMail) with ESMTPS id 4NT2nQ36GHz8R039; Fri, 9 Dec 2022 15:33:30 +0800 (CST) Received: from szxlzmapp04.zte.com.cn ([10.5.231.166]) by mse-fl2.zte.com.cn with SMTP id 2B97XNdM002470; Fri, 9 Dec 2022 15:33:23 +0800 (+08) (envelope-from yang.yang29@zte.com.cn) Received: from mapi (szxlzmapp04[null]) by mapi (Zmail) with MAPI id mid14; Fri, 9 Dec 2022 15:33:25 +0800 (CST) Date: Fri, 9 Dec 2022 15:33:25 +0800 (CST) X-Zmail-TransId: 2b066392e4c554cc8088 X-Mailer: Zmail v1.0 Message-ID: <202212091533253334827@zte.com.cn> Mime-Version: 1.0 From: To: Cc: , , , , , , , , , Subject: =?UTF-8?B?W1BBVENIIG5ldC1uZXh0IHYyXSBobnM6IHVzZSBzdHJzY3B5KCkgdG8gaW5zdGVhZCBvZiBzdHJuY3B5KCk=?= Content-Type: text/plain; charset="UTF-8" X-MAIL: mse-fl2.zte.com.cn 2B97XNdM002470 X-Fangmail-Gw-Spam-Type: 0 X-FangMail-Miltered: at cgslv5.04-192.168.250.137.novalocal with ID 6392E4CA.000 by FangMail milter! X-FangMail-Envelope: 1670571210/4NT2nQ36GHz8R039/6392E4CA.000/10.5.228.133/[10.5.228.133]/mse-fl2.zte.com.cn/ X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 6392E4CA.000/4NT2nQ36GHz8R039 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY 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 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; } -- 2.15.2