From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A5DA7C004EF for ; Wed, 10 Jul 2019 11:03:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 800C72064B for ; Wed, 10 Jul 2019 11:03:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727217AbfGJLDf (ORCPT ); Wed, 10 Jul 2019 07:03:35 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:54917 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727030AbfGJLDe (ORCPT ); Wed, 10 Jul 2019 07:03:34 -0400 Received: from Internal Mail-Server by MTLPINE2 (envelope-from tariqt@mellanox.com) with ESMTPS (AES256-SHA encrypted); 10 Jul 2019 14:03:30 +0300 Received: from dev-l-vrt-206-006.mtl.labs.mlnx (dev-l-vrt-206-006.mtl.labs.mlnx [10.134.206.6]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id x6AB3US0020650; Wed, 10 Jul 2019 14:03:30 +0300 From: Tariq Toukan To: Stephen Hemminger Cc: netdev@vger.kernel.org, moshe@mellanox.com, ayal@mellanox.com, Tariq Toukan Subject: [PATCH iproute2 master 2/3] devlink: Fix binary values print Date: Wed, 10 Jul 2019 14:03:20 +0300 Message-Id: <1562756601-19171-3-git-send-email-tariqt@mellanox.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1562756601-19171-1-git-send-email-tariqt@mellanox.com> References: <1562756601-19171-1-git-send-email-tariqt@mellanox.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Aya Levin 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 Signed-off-by: Tariq Toukan --- 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