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: 406868 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp4426104jai; Tue, 23 Mar 2021 05:57:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzfxg80185Wckr4IhcFNHUDqCZsmq4ujHvC7pkPo+If4owkh+htvuZLUNT/2o9Y4LDWZ2Cj X-Received: by 2002:a05:6402:2695:: with SMTP id w21mr4460690edd.99.1616504235394; Tue, 23 Mar 2021 05:57:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616504235; cv=none; d=google.com; s=arc-20160816; b=S2F55P+CyIDYwsxQMeskrZ7ksJdmYV5Qd8wALHKA0HIKAYkwm7S4v97G6jYWkd00EI Y3HYvK4vC+rxQ2JVsDE5neCY/BTZppKi/YnzNY5Xfha8KWZM/9KB5rRv6m+K2A1vmdtS bV3c/BLLJYqgbdRwVex8HSbdXBDtPkK0g+SR6uhywj0NwXY8crTIq7NtGWlltbcFNK9r UKIANr+uXX6pXedVmCbXN+8BoWMv8QlCdv917LCoNKIhqVZLniFnER1D4OnNteIucJ8x CGNsTdqtvtQ9YBn3h12yaQakj1PM7t7jj6o4BrY1l3So2TNuyc+acamMAg4T38iZy5Zk Wojg== 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=gFv3bQaln9o7tnPrrLba/npiVQxWuQyLbVwnGD2iAUIJwnY1dqDQ6gpwBSp3gWY6iT qb2D+a0v95enJ625EokzB3CXpfkTsBlzCo/ikW0ub9g32vHZYBHaBn4eqZ/ccqQRcWnf +kKp0lTB8YBixp9AkhtcF4j9HGBQwK1IzIhQCfl3Nx/V/gnh1T9WvXAK30PxIG9f2Yh1 b7oZoWkPF4BJjXsEQ2YV0ry88wPOgtDbLh5af1nRaXSSdLJesAh+2T/m/LCwj3a0PJz2 wXV0vVJ7ndXur++lJHTv4nbvMa9sFxvVTqfSJuxAVq/nwhKavQzyBlKKfKBAIx67Ewnf l3ig== 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 netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-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 l11si13444206edv.488.2021.03.23.05.57.15; Tue, 23 Mar 2021 05:57:15 -0700 (PDT) Received-SPF: pass (google.com: domain of netdev-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 netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-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 S231470AbhCWM4r (ORCPT + 8 others); 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 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(-) -- 2.29.2 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);