From patchwork Wed May 8 08:32:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Horman X-Patchwork-Id: 13658246 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 511C95338F; Wed, 8 May 2024 08:32:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715157152; cv=none; b=eX98XKmSJoLGEvXvpAFDh1yVIvPcCYYmGobqc05ag7T+9L+0Oe8nHuQVBssf5MvPoF5n9UY3DiucJReZ7MkB2Q7yz+Hz8ZMP7pNUnm00eC9aAapHyqt2UodpNPCZjVF24GwCfoLsL9Bja0jQWPcfp5ZDWxLk4riBvmNtIgeCBEc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715157152; c=relaxed/simple; bh=DqcOk4T4gJZ0/xWAo81NsY8g+OvkcV1E42NwKE8Z8Bc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=a2nA7ENuM3aWkl3EWXMFVaj2UIDGVNaVR2HnUpi1VbG9ymasDLkMGQYpaOADqPk8kO3N3wvh+fDUkRAuxZSauBcLlrEIdcDfpnBG4HoB/RF4Rzh411f1nToh6UD57x9pg1pT2CwHTREpObwfIAxOch/Nvhwj45hTX+HmhVlMuZw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=J/PLj6bV; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="J/PLj6bV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DC2B4C4AF66; Wed, 8 May 2024 08:32:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715157151; bh=DqcOk4T4gJZ0/xWAo81NsY8g+OvkcV1E42NwKE8Z8Bc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=J/PLj6bVUDhWgnFyIlijornibU5SPrNBSyCHikPctQQEY1lEgAgMxBsERxkgtQAGl DOwGX4K7PPc9afntxd4CJdsWCbOVINHxKVgX0pEoZM2FSIWLK6kz/TzPlZ+xRnGOo9 jVCBD8jJsDmxKQQNxKaiOzkBZ/f3y2CRttxJ4cXzYCn6lHd0+ual6ENy2iMGcG8Ogx ig2xICE2m9PJJmCm77wmCsvZpWO1Q7jecpLY6enzzOqofyVdQGRgj59ZEI07CqIJ47 m8e8JwVdDxp5NHdNoRqxUyzq5zkHUoekMyzaJgszhcwe7zIpYb6omADJbZxlultLuB 2umwEYOlh+2Kg== From: Simon Horman Date: Wed, 08 May 2024 09:32:20 +0100 Subject: [PATCH net-next v2 2/2] gve: Use ethtool_sprintf/puts() to fill stats strings Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240508-gve-comma-v2-2-1ac919225f13@kernel.org> References: <20240508-gve-comma-v2-0-1ac919225f13@kernel.org> In-Reply-To: <20240508-gve-comma-v2-0-1ac919225f13@kernel.org> To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Jeroen de Borst , Praveen Kaligineedi , Shailend Chand , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Larysa Zaremba , Dan Carpenter , Kees Cook , netdev@vger.kernel.org, llvm@lists.linux.dev, linux-hardening@vger.kernel.org X-Mailer: b4 0.12.3 X-Patchwork-Delegate: kuba@kernel.org Make use of standard helpers to simplify filling in stats strings. The first two ethtool_puts() changes address the following fortification warnings flagged by W=1 builds with clang-18. (The last ethtool_puts change does not because the warning relates to writing beyond the first element of an array, and gve_gstrings_priv_flags only has one element.) .../fortify-string.h:562:4: warning: call to '__read_overflow2_field' declared with 'warning' attribute: detected read beyond size of field (2nd parameter); maybe use struct_group()? [-Wattribute-warning] 562 | __read_overflow2_field(q_size_field, size); | ^ .../fortify-string.h:562:4: warning: call to '__read_overflow2_field' declared with 'warning' attribute: detected read beyond size of field (2nd parameter); maybe use struct_group()? [-Wattribute-warning] Likewise, the same changes resolve the same problems flagged by Smatch. .../gve_ethtool.c:100 gve_get_strings() error: __builtin_memcpy() '*gve_gstrings_main_stats' too small (32 vs 576) .../gve_ethtool.c:120 gve_get_strings() error: __builtin_memcpy() '*gve_gstrings_adminq_stats' too small (32 vs 512) Compile tested only. Reviewed-by: Shailend Chand Reviewed-by: Larysa Zaremba Signed-off-by: Simon Horman Acked-by: Justin Stitt --- drivers/net/ethernet/google/gve/gve_ethtool.c | 42 +++++++++++---------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/drivers/net/ethernet/google/gve/gve_ethtool.c b/drivers/net/ethernet/google/gve/gve_ethtool.c index 156b7e128b53..fe1741d482b4 100644 --- a/drivers/net/ethernet/google/gve/gve_ethtool.c +++ b/drivers/net/ethernet/google/gve/gve_ethtool.c @@ -90,42 +90,34 @@ static const char gve_gstrings_priv_flags[][ETH_GSTRING_LEN] = { static void gve_get_strings(struct net_device *netdev, u32 stringset, u8 *data) { struct gve_priv *priv = netdev_priv(netdev); - char *s = (char *)data; + u8 *s = (char *)data; int num_tx_queues; int i, j; num_tx_queues = gve_num_tx_queues(priv); switch (stringset) { case ETH_SS_STATS: - memcpy(s, *gve_gstrings_main_stats, - sizeof(gve_gstrings_main_stats)); - s += sizeof(gve_gstrings_main_stats); - - for (i = 0; i < priv->rx_cfg.num_queues; i++) { - for (j = 0; j < NUM_GVE_RX_CNTS; j++) { - snprintf(s, ETH_GSTRING_LEN, - gve_gstrings_rx_stats[j], i); - s += ETH_GSTRING_LEN; - } - } + for (i = 0; i < ARRAY_SIZE(gve_gstrings_main_stats); i++) + ethtool_puts(&s, gve_gstrings_main_stats[i]); - for (i = 0; i < num_tx_queues; i++) { - for (j = 0; j < NUM_GVE_TX_CNTS; j++) { - snprintf(s, ETH_GSTRING_LEN, - gve_gstrings_tx_stats[j], i); - s += ETH_GSTRING_LEN; - } - } + for (i = 0; i < priv->rx_cfg.num_queues; i++) + for (j = 0; j < NUM_GVE_RX_CNTS; j++) + ethtool_sprintf(&s, gve_gstrings_rx_stats[j], + i); + + for (i = 0; i < num_tx_queues; i++) + for (j = 0; j < NUM_GVE_TX_CNTS; j++) + ethtool_sprintf(&s, gve_gstrings_tx_stats[j], + i); + + for (i = 0; i < ARRAY_SIZE(gve_gstrings_adminq_stats); i++) + ethtool_puts(&s, gve_gstrings_adminq_stats[i]); - memcpy(s, *gve_gstrings_adminq_stats, - sizeof(gve_gstrings_adminq_stats)); - s += sizeof(gve_gstrings_adminq_stats); break; case ETH_SS_PRIV_FLAGS: - memcpy(s, *gve_gstrings_priv_flags, - sizeof(gve_gstrings_priv_flags)); - s += sizeof(gve_gstrings_priv_flags); + for (i = 0; i < ARRAY_SIZE(gve_gstrings_priv_flags); i++) + ethtool_puts(&s, gve_gstrings_priv_flags[i]); break; default: