Netdev List
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: netdev@vger.kernel.org
Cc: Stephen Hemminger <stephen@networkplumber.org>
Subject: [PATCH iproute 2/3] rdma: don't build printf formats out of keys
Date: Mon, 19 Oct 2026 13:03:03 -0700	[thread overview]
Message-ID: <20261019200623.816470-3-stephen@networkplumber.org> (raw)
In-Reply-To: <20261019200623.816470-1-stephen@networkplumber.org>

print_key(), res_print_u32(), res_print_u64(), print_driver_string() and
print_ipaddr() passed the attribute key as both the json key and the
printf format, so a '%' in a kernel-supplied driver or hwcounter key was
taken as a conversion. Pass the key as a string argument with a literal
format; output is unchanged.

Fixes: 9b578bbaded6 ("rdma: use print_XXX instead of COLOR_NONE")
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 rdma/res-cmid.c |  3 ++-
 rdma/res.c      | 10 +++++-----
 rdma/utils.c    |  4 ++--
 3 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/rdma/res-cmid.c b/rdma/res-cmid.c
index 17a89cc4..956253fe 100644
--- a/rdma/res-cmid.c
+++ b/rdma/res-cmid.c
@@ -53,7 +53,8 @@ static void print_ipaddr(const char *key, char *addrstr, uint16_t port)
 	char json_name[name_size];
 
 	snprintf(json_name, name_size, "%s:%u", addrstr, port);
-	print_string(PRINT_ANY, key, key, json_name);
+	print_string(PRINT_JSON, key, NULL, json_name);
+	print_string(PRINT_FP, NULL, "%s", key);
 	print_string(PRINT_FP, NULL, " %s:", addrstr);
 	print_uint(PRINT_FP, NULL, "%u ", port);
 }
diff --git a/rdma/res.c b/rdma/res.c
index 7efced8d..185612f7 100644
--- a/rdma/res.c
+++ b/rdma/res.c
@@ -222,7 +222,7 @@ void print_key(const char *name, uint64_t val, struct nlattr *nlattr)
 {
 	if (!nlattr)
 		return;
-	print_string(PRINT_FP, NULL, name, NULL);
+	print_string(PRINT_FP, NULL, "%s", name);
 	print_hex(PRINT_ANY, name, " 0x%" PRIx64 " ", val);
 }
 
@@ -230,16 +230,16 @@ void res_print_u32(const char *name, uint32_t val, struct nlattr *nlattr)
 {
 	if (!nlattr)
 		return;
-	print_uint(PRINT_ANY, name, name, val);
-	print_uint(PRINT_FP, NULL, " %" PRIu32 " ", val);
+	print_string(PRINT_FP, NULL, "%s", name);
+	print_uint(PRINT_ANY, name, " %" PRIu32 " ", val);
 }
 
 void res_print_u64(const char *name, uint64_t val, struct nlattr *nlattr)
 {
 	if (!nlattr)
 		return;
-	print_u64(PRINT_ANY, name, name, val);
-	print_u64(PRINT_FP, NULL, " %" PRIu64 " ", val);
+	print_string(PRINT_FP, NULL, "%s", name);
+	print_u64(PRINT_ANY, name, " %" PRIu64 " ", val);
 }
 
 RES_FUNC(res_no_args,	RDMA_NLDEV_CMD_RES_GET,	NULL, true, 0);
diff --git a/rdma/utils.c b/rdma/utils.c
index 90ea1c55..f6605eef 100644
--- a/rdma/utils.c
+++ b/rdma/utils.c
@@ -795,8 +795,8 @@ void newline_indent(void)
 
 static int print_driver_string(const char *key_str, const char *val_str)
 {
-	print_string(PRINT_ANY, key_str, key_str, val_str);
-	print_string(PRINT_FP, NULL, " %s ", val_str);
+	print_string(PRINT_FP, NULL, "%s", key_str);
+	print_string(PRINT_ANY, key_str, " %s ", val_str);
 	return 0;
 }
 
-- 
2.53.0


  parent reply	other threads:[~2026-10-19 20:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-19 20:03 [PATCH iproute2 0/3] don't build printf formats out of names Stephen Hemminger
2026-10-19 20:03 ` [PATCH iproute 1/3] lib: " Stephen Hemminger
2026-10-19 20:03 ` Stephen Hemminger [this message]
2026-10-19 20:03 ` [PATCH iproute 3/3] vdpa: don't build printf format out of vendor stats name Stephen Hemminger

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=20261019200623.816470-3-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=netdev@vger.kernel.org \
    /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