From patchwork Fri Dec 9 07:33:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Yang X-Patchwork-Id: 31678 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp636078wrr; Thu, 8 Dec 2022 23:55:54 -0800 (PST) X-Google-Smtp-Source: AA0mqf4revt++WD8dyLMiDUBf4YiNbiXh7dNBPQhGEWz0VO3xL6hd5MsY2uxB74YDY1CM488UKuU X-Received: by 2002:a17:907:d110:b0:7ae:31a0:e1e6 with SMTP id uy16-20020a170907d11000b007ae31a0e1e6mr3910680ejc.33.1670572554643; Thu, 08 Dec 2022 23:55:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670572554; cv=none; d=google.com; s=arc-20160816; b=si3kK4O9GZaelivtV8VUqETpfynMBzNd+xoa5kpevoBRDq5Ajybgb/VJsgoUxXtAHp z5HyFZevrztduEnSLDd1CW67BS6Z9Vodb+0tXkmyNxvgIG86G4VhF4vr9oDJedVeqZZi UTrTu76X12fp0K5d2+rkwbNoXVeiM8cF9Otc1EsO9iilwLAr90Bww0g2cfYge4OmN9dP JikTZWDLzJJQbbmY5qt4UGC71qhooKApeVkOeZIhBJo+fdkbaMw7CEnt6BDpgAHj0fQp igFb17+c6NFo5wMbDw4lX0/xBHGZs/0X36ZOTLooltlyEWR3GmydaH1ZD32ok5ioUQve fskw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b23-20020aa7cd17000000b0046aee4c4eb3si736054edw.26.2022.12.08.23.55.30; Thu, 08 Dec 2022 23:55:54 -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 + 99 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?q?=5BPATCH_net-next_v2=5D_hns=3A_use_strscpy=28=29_to_inste?= =?utf-8?q?ad_of_strncpy=28=29?= 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751722287124096344?= X-GMAIL-MSGID: =?utf-8?q?1751722287124096344?= 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 Reviewed-by: Jiri Pirko Reviewed-by: Hao Lan --- 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; }