Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp327704pxf; Wed, 24 Mar 2021 06:13:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJysnSI6m6HyhXwXegbWUZUoxZjxINerxp2/OmAlMznM0/qf3rgvJVwMD26hPBxmPrVWauiJ X-Received: by 2002:aa7:ccd7:: with SMTP id y23mr3399561edt.190.1616591581448; Wed, 24 Mar 2021 06:13:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616591581; cv=none; d=google.com; s=arc-20160816; b=q7m2Onm5xpz2Ak3LBPTDMbkFZxAlGIRYXVPPaOSVtDZygaholL/OzYC9jCEdhwCqJT tNUo3okLJyupvAN41kJJ+xhcwJwQ7RWEs9s56fkdgO8bNKutUQWBjD4UZuTgy1gH24UH N26H0oZdCAVbLLzryoCoc50FkHZfPwFGxjbwf3MY5Znp1MQFlBMZEUOJDUf9vSXPM4oa iCWOQ9h9uK6SusAKpRK6cUWvB2hdRxW7eNFxNA/zbj6eQOZA8twVmdnQuusv+GN/NCX3 57bN9vua4qpeLyUJvn2uUwFxbIQuBAEir6rJni6Q4FPkbpwHls2lvDSe0c+2dq9pIfDT PVHw== 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=1sUe68v9i2q87wzJY/xOaL12xmqtYBGKyhXtfrYdLmk=; b=c0AszIRCe03jtcJpDgeNiqRXYGz/EKfPpuaz8v9Aotm0Vy3rWO33f6CFEJkIbqMl9m YDtnzk/RipTfSEenKl8mZvS1Lt9e8E/5Wf8/QFRbQAReK4V8v6Gvx190XZ1uOg466k4U hULHGrEoFB5DDrcBkNtDDdULzNKVsOsU+KZC10n5xjC6QIYmOoXjRImsCg6cxF8YKoDM 8HDCgoPq7dXhzLvqLc9JJYFl+1M5N+bNuarWZYxw470xSYeMEdtBIxG6g9ATuApFwitB u6WvTXNeX38NsnQ8+T3osz0P0loKjfp55nfzExjh+3jARIfeK9NZkpMtANMYAXTmZ2Jr TNRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aIu1IF6B; 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 bx3si1736376edb.594.2021.03.24.06.12.34; Wed, 24 Mar 2021 06:13:01 -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=aIu1IF6B; 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 S234706AbhCXNHv (ORCPT + 99 others); Wed, 24 Mar 2021 09:07:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:43574 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234381AbhCXNHg (ORCPT ); Wed, 24 Mar 2021 09:07:36 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2E67B619F2; Wed, 24 Mar 2021 13:07:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616591255; bh=ipRkHJfSO7gbOj1+Zj4KAE72qEZRW4QoMykE1Mghsjk=; h=From:To:Cc:Subject:Date:From; b=aIu1IF6BxPI3ZLsSx8wcxgzU/yjCf/1AM9NW1GiG1k4hxH0JsER0b80LwZbhgdjrf VZNMLqrf0M1n5pvx1NGxvr12ah9aXrKw4ELo0PtcCdeRK5ix2NjzOWkofkutFq2WIj IVkeLd6x38+ijiCHKXw6hJZ+sBdFO+mGKoIzG4hHFb4scFpXWvgOIv4xHAxrydTFpl QyilaMTk58IWbvEpUL9aybINMxVNztsmbVAs50Zk3MMwQRhUS3weNGGMbSjxhx18Wi 8h5Evy4SravyouqCKe2py+5vF1azderK9mUu/gLYgakX/Uwo+ijSnsfh6RsYU0oDjd CVAKOrqJNDhkw== From: Arnd Bergmann To: Bin Luo , "David S. Miller" , Jakub Kicinski Cc: Arnd Bergmann , Rasmus Villemoes , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] [v2] hinic: avoid gcc -Wrestrict warning Date: Wed, 24 Mar 2021 14:07:22 +0100 Message-Id: <20210324130731.1513798-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 avoid the nested sprintf and instead use separate buffers, which is simpler. Cc: Rasmus Villemoes Signed-off-by: Arnd Bergmann --- v2: rework according to feedback from Rasmus. This one could easily avoid most of the pitfalls --- .../net/ethernet/huawei/hinic/hinic_ethtool.c | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/drivers/net/ethernet/huawei/hinic/hinic_ethtool.c b/drivers/net/ethernet/huawei/hinic/hinic_ethtool.c index c340d9acba80..d7e20dab6e48 100644 --- a/drivers/net/ethernet/huawei/hinic/hinic_ethtool.c +++ b/drivers/net/ethernet/huawei/hinic/hinic_ethtool.c @@ -34,7 +34,7 @@ #include "hinic_rx.h" #include "hinic_dev.h" -#define SET_LINK_STR_MAX_LEN 128 +#define SET_LINK_STR_MAX_LEN 16 #define GET_SUPPORTED_MODE 0 #define GET_ADVERTISED_MODE 1 @@ -462,24 +462,19 @@ static int hinic_set_settings_to_hw(struct hinic_dev *nic_dev, { struct hinic_link_ksettings_info settings = {0}; char set_link_str[SET_LINK_STR_MAX_LEN] = {0}; + const char *autoneg_str; struct net_device *netdev = nic_dev->netdev; enum nic_speed_level speed_level = 0; int err; - err = snprintf(set_link_str, SET_LINK_STR_MAX_LEN, "%s", - (set_settings & HILINK_LINK_SET_AUTONEG) ? - (autoneg ? "autong enable " : "autong disable ") : ""); - if (err < 0 || err >= SET_LINK_STR_MAX_LEN) { - netif_err(nic_dev, drv, netdev, "Failed to snprintf link state, function return(%d) and dest_len(%d)\n", - err, SET_LINK_STR_MAX_LEN); - return -EFAULT; - } + autoneg_str = (set_settings & HILINK_LINK_SET_AUTONEG) ? + (autoneg ? "autong enable " : "autong disable ") : ""; 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); - if (err <= 0 || err >= SET_LINK_STR_MAX_LEN) { + "speed %d ", speed); + if (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); return -EFAULT; @@ -494,11 +489,11 @@ static int hinic_set_settings_to_hw(struct hinic_dev *nic_dev, err = hinic_set_link_settings(nic_dev->hwdev, &settings); if (err != HINIC_MGMT_CMD_UNSUPPORTED) { if (err) - netif_err(nic_dev, drv, netdev, "Set %s failed\n", - set_link_str); + netif_err(nic_dev, drv, netdev, "Set %s%sfailed\n", + autoneg_str, set_link_str); else - netif_info(nic_dev, drv, netdev, "Set %s successfully\n", - set_link_str); + netif_info(nic_dev, drv, netdev, "Set %s%ssuccessfully\n", + autoneg_str, set_link_str); return err; } -- 2.29.2