Netdev List
 help / color / mirror / Atom feed
From: David Ahern <dsahern@kernel.org>
To: Tao Cui <cui.tao@linux.dev>, leonro@nvidia.com
Cc: linux-rdma@vger.kernel.org, netdev@vger.kernel.org,
	Tao Cui <cuitao@kylinos.cn>
Subject: Re: [PATCH iproute2-next v6 2/2] rdma: display resource limits in curr/max format
Date: Wed, 15 Jul 2026 09:11:35 -0600	[thread overview]
Message-ID: <2d83ccf4-952c-466e-a79a-ee93bf072380@kernel.org> (raw)
In-Reply-To: <20260713131238.955962-3-cui.tao@linux.dev>

On 7/13/26 7:12 AM, Tao Cui wrote:
> @@ -55,7 +55,26 @@ static int res_print_summary(struct nlattr **tb)
>  
>  		name = mnl_attr_get_str(nla_line[RDMA_NLDEV_ATTR_RES_SUMMARY_ENTRY_NAME]);
>  		curr = mnl_attr_get_u64(nla_line[RDMA_NLDEV_ATTR_RES_SUMMARY_ENTRY_CURR]);
> -		res_print_u64(name, curr, nla_line[RDMA_NLDEV_ATTR_RES_SUMMARY_ENTRY_CURR]);
> +		if (nla_line[RDMA_NLDEV_ATTR_RES_SUMMARY_ENTRY_MAX]) {
> +			uint64_t max;
> +			char max_name[64];
> +
> +			max = mnl_attr_get_u64(
> +				nla_line[RDMA_NLDEV_ATTR_RES_SUMMARY_ENTRY_MAX]);
> +			snprintf(max_name, sizeof(max_name), "%s-max", name);
> +			print_u64(PRINT_JSON, name, NULL, curr);
> +			print_u64(PRINT_JSON, max_name, NULL, max);
> +			if (!is_json_context()) {
> +				char buf[64];
> +
> +				snprintf(buf, sizeof(buf), "%s %" PRIu64 "/%" PRIu64 " ",
> +					 name, curr, max);
> +				pr_out("%s", buf);

claude review:

The feature and backward-compat approach look correct.  A couple of
nits below.

> +             if (nla_line[RDMA_NLDEV_ATTR_RES_SUMMARY_ENTRY_MAX]) {
> +                     uint64_t max;
> +                     char max_name[64];
> +
> +                     max = mnl_attr_get_u64(
> +
nla_line[RDMA_NLDEV_ATTR_RES_SUMMARY_ENTRY_MAX]);
> +                     snprintf(max_name, sizeof(max_name), "%s-max",
name);
> +                     print_u64(PRINT_JSON, name, NULL, curr);
> +                     print_u64(PRINT_JSON, max_name, NULL, max);
> +                     if (!is_json_context()) {
> +                             char buf[64];
> +
> +                             snprintf(buf, sizeof(buf), "%s %" PRIu64
"/%" PRIu64 " ",
> +                                      name, curr, max);
> +                             pr_out("%s", buf);
> +                     }

The intermediate buf[] is unnecessary; pr_out() accepts a format string
directly.  The snprintf -> pr_out("%s") dance also silently truncates if
`name` is unusually long, since two u64 values and a slash can consume
up to 42 bytes, leaving only 22 bytes in a 64-byte buffer for the name.
While current RDMA resource names are short, the kernel is the source of
`name`, so it is better not to rely on that.

  if (!is_json_context())
      pr_out("%s %" PRIu64 "/%" PRIu64 " ", name, curr, max);

Similarly, the max_name[] buffer for the JSON key has the same size
concern; a 64-byte buffer with snprintf("%s-max", name) silently
truncates for any name longer than 59 characters.  Again unlikely in
practice, but worth noting if this pattern is copied elsewhere.

No functional issue with the netlink policy addition in utils.c or the
backward-compatible fallback to res_print_u64().

###

in addition, please provide json output in the commit message.

      reply	other threads:[~2026-07-15 15:11 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-13 13:12 [PATCH iproute2-next v6 0/2] rdma: display resource limits in curr/max format Tao Cui
2026-07-13 13:12 ` [PATCH iproute2-next v6 1/2] rdma: update uapi headers Tao Cui
2026-07-13 13:12 ` [PATCH iproute2-next v6 2/2] rdma: display resource limits in curr/max format Tao Cui
2026-07-15 15:11   ` David Ahern [this message]

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=2d83ccf4-952c-466e-a79a-ee93bf072380@kernel.org \
    --to=dsahern@kernel.org \
    --cc=cui.tao@linux.dev \
    --cc=cuitao@kylinos.cn \
    --cc=leonro@nvidia.com \
    --cc=linux-rdma@vger.kernel.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