From patchwork Tue Mar 23 12:56:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 12157709 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E0BBFC433C1 for ; Tue, 23 Mar 2021 12:57:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8F56260C3E for ; Tue, 23 Mar 2021 12:57:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231470AbhCWM4r (ORCPT ); Tue, 23 Mar 2021 08:56:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:41000 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231424AbhCWM4R (ORCPT ); Tue, 23 Mar 2021 08:56:17 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0AE9F60C3E; Tue, 23 Mar 2021 12:56:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616504175; bh=aqKRpulSPCrh/zMHeH6x9tZrAsAvxFVCeqlmNTkK6XU=; h=From:To:Cc:Subject:Date:From; b=kpgeUNTpkeKgQ5LtZe9cwXIrCX4EBUhQe0ntE9chwd7cZ1CAV5ThoOgemX8vzdUwf 1/AXCrmc+yGTQUcLOj32vOcYxffBmNrw3NEqwHtDWMc4qMS1S78enwBVOFmL4bDx8N ZDkqn9dFKXXaD/TD3NNoV5iqA0eQBIrdBqlzHSijpro5YZi8AZVY5d0gG6l/o5Sifd USNEIPvKeMesLNsZoZtlpeq8IwjZKBQFR0jlDFhzxyqg6wm4+dU6zJBfbwIdQ/aK8z igZlUpx+wlTakVB8uCg/pv3WuY9FX7rGOweXS655PbI8f1kD8wpCrlg/3Jd0isn+DU IFLZ//L0s3+pg== From: Arnd Bergmann To: Bin Luo , "David S. Miller" , Jakub Kicinski Cc: Arnd Bergmann , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next] hinic: avoid gcc -Wrestrict warning Date: Tue, 23 Mar 2021 13:56:05 +0100 Message-Id: <20210323125611.1905563-1-arnd@kernel.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Arnd Bergmann With extra warnings enabled, gcc complains that snprintf should not take the same buffer as source and destination: drivers/net/ethernet/huawei/hinic/hinic_ethtool.c: In function 'hinic_set_settings_to_hw': drivers/net/ethernet/huawei/hinic/hinic_ethtool.c:480:9: error: 'snprintf' argument 4 overlaps destination object 'set_link_str' [-Werror=restrict] 480 | err = snprintf(set_link_str, SET_LINK_STR_MAX_LEN, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 481 | "%sspeed %d ", set_link_str, speed); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/net/ethernet/huawei/hinic/hinic_ethtool.c:464:7: note: destination object referenced by 'restrict'-qualified argument 1 was declared here 464 | char set_link_str[SET_LINK_STR_MAX_LEN] = {0}; Rewrite this to remember the offset of the previous printf output instead. Signed-off-by: Arnd Bergmann --- drivers/net/ethernet/huawei/hinic/hinic_ethtool.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/huawei/hinic/hinic_ethtool.c b/drivers/net/ethernet/huawei/hinic/hinic_ethtool.c index c340d9acba80..74aefc8fc4d8 100644 --- a/drivers/net/ethernet/huawei/hinic/hinic_ethtool.c +++ b/drivers/net/ethernet/huawei/hinic/hinic_ethtool.c @@ -464,7 +464,7 @@ static int hinic_set_settings_to_hw(struct hinic_dev *nic_dev, char set_link_str[SET_LINK_STR_MAX_LEN] = {0}; struct net_device *netdev = nic_dev->netdev; enum nic_speed_level speed_level = 0; - int err; + int err, off; err = snprintf(set_link_str, SET_LINK_STR_MAX_LEN, "%s", (set_settings & HILINK_LINK_SET_AUTONEG) ? @@ -475,10 +475,11 @@ static int hinic_set_settings_to_hw(struct hinic_dev *nic_dev, return -EFAULT; } + off = err; if (set_settings & HILINK_LINK_SET_SPEED) { speed_level = hinic_ethtool_to_hw_speed_level(speed); - err = snprintf(set_link_str, SET_LINK_STR_MAX_LEN, - "%sspeed %d ", set_link_str, speed); + err = snprintf(set_link_str + off, SET_LINK_STR_MAX_LEN - off, + "speed %d ", speed); if (err <= 0 || err >= SET_LINK_STR_MAX_LEN) { netif_err(nic_dev, drv, netdev, "Failed to snprintf link speed, function return(%d) and dest_len(%d)\n", err, SET_LINK_STR_MAX_LEN);