public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
From: Artem Bityutskiy <dedekind1@gmail.com>
To: Len Brown <lenb@kernel.org>
Cc: Linux PM Mailing List <linux-pm@vger.kernel.org>,
	Artem Bityutskiy <dedekind1@gmail.com>
Subject: [PATCH 5/5] tools/power turbostat: cleanup print helper functions
Date: Wed, 11 Mar 2026 11:00:35 +0200	[thread overview]
Message-ID: <20260311090035.169539-6-dedekind1@gmail.com> (raw)
In-Reply-To: <20260311090035.169539-1-dedekind1@gmail.com>

From: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

Two cleanups in printing helpers:
1. Add a local 'sep' variable to avoid repeating the ternary
   expression in each branch.
2. Remove the redundant parentheses around sprintf() calls.
3. Remove an unnecessary cast to "unsigned int" by using the '%08llx' instead
   of '%08x'.

No functional changes.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
---
 tools/power/x86/turbostat/turbostat.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c
index f5cf12ab84e09..70dbd927b6521 100644
--- a/tools/power/x86/turbostat/turbostat.c
+++ b/tools/power/x86/turbostat/turbostat.c
@@ -2835,31 +2835,38 @@ void bic_lookup(cpu_set_t *ret_set, char *name_list, enum show_hide_mode mode)
 static inline int print_name(int width, int *printed, char *delim, char *name, enum counter_type type, enum counter_format format)
 {
 	UNUSED(type);
+	char *sep = (*printed)++ ? delim : "";
 
 	if (format == FORMAT_RAW && width >= 64)
-		return (sprintf(outp, "%s%-8s", ((*printed)++ ? delim : ""), name));
+		return sprintf(outp, "%s%-8s", sep, name);
 	else
-		return (sprintf(outp, "%s%s", ((*printed)++ ? delim : ""), name));
+		return sprintf(outp, "%s%s", sep, name);
 }
 
 static inline int print_hex_value(int width, int *printed, char *delim, unsigned long long value)
 {
+	char *sep = (*printed)++ ? delim : "";
+
 	if (width <= 32)
-		return (sprintf(outp, "%s%08x", (*(printed)++ ? delim : ""), (unsigned int)value));
+		return (sprintf(outp, "%s%08llx", sep, value));
 	else
-		return (sprintf(outp, "%s%016llx", (*(printed)++ ? delim : ""), value));
+		return (sprintf(outp, "%s%016llx", sep, value));
 }
 
 static inline int print_decimal_value(int width, int *printed, char *delim, unsigned long long value)
 {
+	char *sep = (*printed)++ ? delim : "";
+
 	UNUSED(width);
 
-	return (sprintf(outp, "%s%lld", (*(printed)++ ? delim : ""), value));
+	return (sprintf(outp, "%s%lld", sep, value));
 }
 
 static inline int print_float_value(int *printed, char *delim, double value)
 {
-	return (sprintf(outp, "%s%0.2f", (*(printed)++ ? delim : ""), value));
+	char *sep = (*printed)++ ? delim : "";
+
+	return (sprintf(outp, "%s%0.2f", sep, value));
 }
 
 void print_header(char *delim)
-- 
2.53.0


      parent reply	other threads:[~2026-03-11  9:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-11  9:00 [PATCH 0/6] tools/power turbostat: Fixes and cleanups Artem Bityutskiy
2026-03-11  9:00 ` [PATCH 1/5] tools/power turbostat: add missing print_float_value() Artem Bityutskiy
2026-03-18  3:37   ` Len Brown
2026-03-11  9:00 ` [PATCH 2/5] tools/power turbostat: fix incorrect format variable Artem Bityutskiy
2026-03-18  3:38   ` Len Brown
2026-03-11  9:00 ` [PATCH 3/5] tools/power turbostat: fix --show/--hide for individual cpuidle counters Artem Bityutskiy
2026-03-18  3:38   ` Len Brown
2026-03-11  9:00 ` [PATCH 4/5] tools/power turbostat: fix delimiter bug in print functions Artem Bityutskiy
2026-03-18  3:23   ` Len Brown
2026-03-11  9:00 ` Artem Bityutskiy [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=20260311090035.169539-6-dedekind1@gmail.com \
    --to=dedekind1@gmail.com \
    --cc=lenb@kernel.org \
    --cc=linux-pm@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