netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tariq Toukan <tariqt@mellanox.com>
To: Stephen Hemminger <stephen@networkplumber.org>
Cc: netdev@vger.kernel.org, moshe@mellanox.com, ayal@mellanox.com,
	Tariq Toukan <tariqt@mellanox.com>
Subject: [PATCH iproute2 master 2/3] devlink: Fix binary values print
Date: Wed, 10 Jul 2019 14:03:20 +0300	[thread overview]
Message-ID: <1562756601-19171-3-git-send-email-tariqt@mellanox.com> (raw)
In-Reply-To: <1562756601-19171-1-git-send-email-tariqt@mellanox.com>

From: Aya Levin <ayal@mellanox.com>

Fix function pr_out_binary_value() to start printing the binary buffer
from offset 0 instead of offset 1. Remove redundant new line at the
beginning of the output

Example:
With patch:
 mlx5e_txqsq:
   05 00 00 00 05 00 00 00 01 00 00 00 00 00 00 00
   00 00 00 00 00 00 00 00 8e 6e 3a 13 07 00 00 00
   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
   c0
Without patch
  mlx5e_txqsq:

  00 00 00 05 00 00 00 01 00 00 00 00 00 00 00 00
  00 00 00 00 00 00 00 8e 6e 3a 13 07 00 00 00 00
  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 c0

Fixes: 844a61764c6f ("devlink: Add helper functions for name and value separately")
Signed-off-by: Aya Levin <ayal@mellanox.com>
Signed-off-by: Tariq Toukan <tariqt@mellanox.com>
---
 devlink/devlink.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/devlink/devlink.c b/devlink/devlink.c
index e3e1e27ab312..4bced4e60ae8 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -1779,29 +1779,31 @@ static void pr_out_uint64_value(struct dl *dl, uint64_t value)
 		pr_out(" %"PRIu64, value);
 }
 
+static bool is_binary_eol(int i)
+{
+	return !(i%16);
+}
+
 static void pr_out_binary_value(struct dl *dl, uint8_t *data, uint32_t len)
 {
-	int i = 1;
+	int i = 0;
 
 	if (dl->json_output)
 		jsonw_start_array(dl->jw);
-	else
-		pr_out("\n");
 
 	while (i < len) {
-		if (dl->json_output) {
+		if (dl->json_output)
 			jsonw_printf(dl->jw, "%d", data[i]);
-		} else {
-			pr_out(" %02x", data[i]);
-			if (!(i % 16))
-				pr_out("\n");
-		}
+		else
+			pr_out("%02x ", data[i]);
 		i++;
+		if (!dl->json_output && is_binary_eol(i))
+			__pr_out_newline();
 	}
 	if (dl->json_output)
 		jsonw_end_array(dl->jw);
-	else if ((i - 1) % 16)
-		pr_out("\n");
+	else if (!is_binary_eol(i))
+		__pr_out_newline();
 }
 
 static void pr_out_str_value(struct dl *dl, const char *value)
-- 
1.8.3.1


  parent reply	other threads:[~2019-07-10 11:03 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-10 11:03 [PATCH iproute2 master 0/3] devlink dumpit fixes Tariq Toukan
2019-07-10 11:03 ` [PATCH iproute2 master 1/3] devlink: Change devlink health dump show command to dumpit Tariq Toukan
2019-07-10 11:47   ` Jiri Pirko
2019-07-10 11:03 ` Tariq Toukan [this message]
2019-07-10 11:03 ` [PATCH iproute2 master 3/3] devlink: Remove enclosing array brackets binary print with json format Tariq Toukan
2019-07-15 20:51 ` [PATCH iproute2 master 0/3] devlink dumpit fixes 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=1562756601-19171-3-git-send-email-tariqt@mellanox.com \
    --to=tariqt@mellanox.com \
    --cc=ayal@mellanox.com \
    --cc=moshe@mellanox.com \
    --cc=netdev@vger.kernel.org \
    --cc=stephen@networkplumber.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;
as well as URLs for NNTP newsgroup(s).