public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: David Carlier <devnexen@gmail.com>
To: Tony Nguyen <anthony.l.nguyen@intel.com>,
	Przemek Kitszel <przemyslaw.kitszel@intel.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>
Cc: netdev@vger.kernel.org, David Carlier <devnexen@gmail.com>
Subject: [PATCH] iavf: replace strcat chain with snprintf in iavf_print_adv_rss_cfg
Date: Wed, 18 Mar 2026 23:18:21 +0000	[thread overview]
Message-ID: <20260318231821.43551-1-devnexen@gmail.com> (raw)

The hash option string was built using memset + 11 strcat() calls,
which is both unbounded and needlessly verbose. Use a single snprintf()
instead. Also drop the static qualifier on the buffer since there's
no reason for it to persist across calls, and shrink it from 300 to
128 bytes (worst case output is ~85 bytes).

No functional change.

Signed-off-by: David Carlier <devnexen@gmail.com>
---
 .../net/ethernet/intel/iavf/iavf_adv_rss.c    | 73 ++++++++-----------
 1 file changed, 32 insertions(+), 41 deletions(-)

diff --git a/drivers/net/ethernet/intel/iavf/iavf_adv_rss.c b/drivers/net/ethernet/intel/iavf/iavf_adv_rss.c
index 4d12dfe1b481..6e1c7c39ff9d 100644
--- a/drivers/net/ethernet/intel/iavf/iavf_adv_rss.c
+++ b/drivers/net/ethernet/intel/iavf/iavf_adv_rss.c
@@ -238,7 +238,7 @@ iavf_print_adv_rss_cfg(struct iavf_adapter *adapter, struct iavf_adv_rss *rss,
 {
 	u32 packet_hdrs = rss->packet_hdrs;
 	u64 hash_flds = rss->hash_flds;
-	static char hash_opt[300];
+	char hash_opt[128];
 	const char *proto;
 
 	if (packet_hdrs & IAVF_ADV_RSS_FLOW_SEG_HDR_TCP)
@@ -252,44 +252,35 @@ iavf_print_adv_rss_cfg(struct iavf_adapter *adapter, struct iavf_adv_rss *rss,
 	else
 		return;
 
-	memset(hash_opt, 0, sizeof(hash_opt));
-
-	strcat(hash_opt, proto);
-	if (packet_hdrs & IAVF_ADV_RSS_FLOW_SEG_HDR_IPV4)
-		strcat(hash_opt, "v4 ");
-	else
-		strcat(hash_opt, "v6 ");
-
-	if (hash_flds & (IAVF_ADV_RSS_HASH_FLD_IPV4_SA |
-			 IAVF_ADV_RSS_HASH_FLD_IPV6_SA))
-		strcat(hash_opt, "IP SA,");
-	if (hash_flds & (IAVF_ADV_RSS_HASH_FLD_IPV4_DA |
-			 IAVF_ADV_RSS_HASH_FLD_IPV6_DA))
-		strcat(hash_opt, "IP DA,");
-	if (hash_flds & (IAVF_ADV_RSS_HASH_FLD_TCP_SRC_PORT |
-			 IAVF_ADV_RSS_HASH_FLD_UDP_SRC_PORT |
-			 IAVF_ADV_RSS_HASH_FLD_SCTP_SRC_PORT))
-		strcat(hash_opt, "src port,");
-	if (hash_flds & (IAVF_ADV_RSS_HASH_FLD_TCP_DST_PORT |
-			 IAVF_ADV_RSS_HASH_FLD_UDP_DST_PORT |
-			 IAVF_ADV_RSS_HASH_FLD_SCTP_DST_PORT))
-		strcat(hash_opt, "dst port,");
-	if (hash_flds & IAVF_ADV_RSS_HASH_FLD_GTPC_TEID)
-		strcat(hash_opt, "gtp-c,");
-	if (hash_flds & IAVF_ADV_RSS_HASH_FLD_GTPU_IP_TEID)
-		strcat(hash_opt, "gtp-u ip,");
-	if (hash_flds & IAVF_ADV_RSS_HASH_FLD_GTPU_EH_TEID)
-		strcat(hash_opt, "gtp-u ext,");
-	if (hash_flds & IAVF_ADV_RSS_HASH_FLD_GTPU_UP_TEID)
-		strcat(hash_opt, "gtp-u ul,");
-	if (hash_flds & IAVF_ADV_RSS_HASH_FLD_GTPU_DWN_TEID)
-		strcat(hash_opt, "gtp-u dl,");
-
-	if (!action)
-		action = "";
-
-	if (!result)
-		result = "";
-
-	dev_info(&adapter->pdev->dev, "%s %s %s\n", action, hash_opt, result);
+	snprintf(hash_opt, sizeof(hash_opt), "%s%s %s%s%s%s%s%s%s%s%s",
+		 proto,
+		 (packet_hdrs & IAVF_ADV_RSS_FLOW_SEG_HDR_IPV4) ?
+			"v4" : "v6",
+		 (hash_flds & (IAVF_ADV_RSS_HASH_FLD_IPV4_SA |
+			       IAVF_ADV_RSS_HASH_FLD_IPV6_SA)) ?
+			"IP SA," : "",
+		 (hash_flds & (IAVF_ADV_RSS_HASH_FLD_IPV4_DA |
+			       IAVF_ADV_RSS_HASH_FLD_IPV6_DA)) ?
+			"IP DA," : "",
+		 (hash_flds & (IAVF_ADV_RSS_HASH_FLD_TCP_SRC_PORT |
+			       IAVF_ADV_RSS_HASH_FLD_UDP_SRC_PORT |
+			       IAVF_ADV_RSS_HASH_FLD_SCTP_SRC_PORT)) ?
+			"src port," : "",
+		 (hash_flds & (IAVF_ADV_RSS_HASH_FLD_TCP_DST_PORT |
+			       IAVF_ADV_RSS_HASH_FLD_UDP_DST_PORT |
+			       IAVF_ADV_RSS_HASH_FLD_SCTP_DST_PORT)) ?
+			"dst port," : "",
+		 (hash_flds & IAVF_ADV_RSS_HASH_FLD_GTPC_TEID) ?
+			"gtp-c," : "",
+		 (hash_flds & IAVF_ADV_RSS_HASH_FLD_GTPU_IP_TEID) ?
+			"gtp-u ip," : "",
+		 (hash_flds & IAVF_ADV_RSS_HASH_FLD_GTPU_EH_TEID) ?
+			"gtp-u ext," : "",
+		 (hash_flds & IAVF_ADV_RSS_HASH_FLD_GTPU_UP_TEID) ?
+			"gtp-u ul," : "",
+		 (hash_flds & IAVF_ADV_RSS_HASH_FLD_GTPU_DWN_TEID) ?
+			"gtp-u dl," : "");
+
+	dev_info(&adapter->pdev->dev, "%s %s %s\n",
+		 action ? action : "", hash_opt, result ? result : "");
 }
-- 
2.53.0


                 reply	other threads:[~2026-03-18 23:18 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260318231821.43551-1-devnexen@gmail.com \
    --to=devnexen@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=anthony.l.nguyen@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=przemyslaw.kitszel@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox