Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4220503pxf; Tue, 23 Mar 2021 05:58:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyUml/jyKiObOJws5Uv/uc+RrkM4tp5bkG7kLmsV7EKhZqL64TSMk2XG2Nco84wE+ErNsUA X-Received: by 2002:a17:906:39cf:: with SMTP id i15mr4787122eje.534.1616504334339; Tue, 23 Mar 2021 05:58:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616504334; cv=none; d=google.com; s=arc-20160816; b=y+bAy3pCZicJNhLQDPjn3PlZ9woH1N9GNZnwwV35aozBIOl9wMzfxo4rvK3MI97WHd 1NnCyhqf4IElpVLmrk86sjomSmDGjL0XZXYDuOlyno+QP8Dqpaqmn44TF2tS2bFbQNIY iiwhbAO+8BkMY/Mav671GWOrAZJjgwkx+gSQv52V0KrS+6PomaA1Fl9dtYWfZVNj/Au0 WBnPUCxuA+q3yKU3cfAmI6j4Q5Ng4LK5ksxkLuvbTUCNAYTbAgaVGfxxXt8XVzx7dqJZ adPkvZRzOHZuYQz+tUVmz4E+NhcO+Bd2Q+GZZmXJ4myLK6vceADjtJ4aYUA/DCw14oXU dndA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=MPUayQQdDDv5Y453mCRZ8DKnX+2d7/v+kVDq4sB/Zto=; b=O3dOjAW5jodthpit8kaWQgN5/01OJRfIclFttYSAL/XEEt3yLncXP/XnLkbAVTrkBs d1x5+7pSZpxPJUKj8VTDdr8aMA92SqCXgfMT/0wp+u+aWxIMyl3o+KWEkWsLx/A8UEVE jFgyMsJwTyuPEMj2Q9OA1Z8/7Lmq5GBJH0wrbqAk5puJD4ICIpzm6l0IxFJC7IGc7muL 3Bt8e4naUN1FlBL7LIVRqzc5T8VIu64lxIn/5YOHw7EVfrC9FTwy8GQ2BVzr6SGHk0On nfPIn1eZ6+vqyGnUxiq5c4JLnlGwvxx7AvTlbvFdCn/hZh66DLwGwkkoxB0c89u8UImX TTOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kpgeUNTp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bw19si13334097ejb.85.2021.03.23.05.58.31; Tue, 23 Mar 2021 05:58:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kpgeUNTp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231469AbhCWM4p (ORCPT + 99 others); Tue, 23 Mar 2021 08:56:45 -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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.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); -- 2.29.2