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 4/5] tools/power turbostat: fix delimiter bug in print functions
Date: Wed, 11 Mar 2026 11:00:34 +0200	[thread overview]
Message-ID: <20260311090035.169539-5-dedekind1@gmail.com> (raw)
In-Reply-To: <20260311090035.169539-1-dedekind1@gmail.com>

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

Fix a bug in the following functions:
1. print_name()
2. print_hex_value()
3. print_decimal_value()
4. print_float_value()

The problem is that the 'int *printed' argument, that is intended to be
used as "has any column been printed yet" flag, never changes.

Reason: incorrect assumption about operator precedence in the expression
'(*printed++ ? delim : "")'. This expression increments the pointer,
but not the value it points to.

As a result, a command like 'turbostat --show C1,C1+' produces output
with columns merged together without any delimiter.

Fix this by using (*printed)++ instead.

Fixes: 56dbb878507b ("tools/power turbostat: Refactor added column header printing")
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
---
 tools/power/x86/turbostat/turbostat.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c
index 3487548841e1d..f5cf12ab84e09 100644
--- a/tools/power/x86/turbostat/turbostat.c
+++ b/tools/power/x86/turbostat/turbostat.c
@@ -2837,29 +2837,29 @@ static inline int print_name(int width, int *printed, char *delim, char *name, e
 	UNUSED(type);
 
 	if (format == FORMAT_RAW && width >= 64)
-		return (sprintf(outp, "%s%-8s", (*printed++ ? delim : ""), name));
+		return (sprintf(outp, "%s%-8s", ((*printed)++ ? delim : ""), name));
 	else
-		return (sprintf(outp, "%s%s", (*printed++ ? delim : ""), name));
+		return (sprintf(outp, "%s%s", ((*printed)++ ? delim : ""), name));
 }
 
 static inline int print_hex_value(int width, int *printed, char *delim, unsigned long long value)
 {
 	if (width <= 32)
-		return (sprintf(outp, "%s%08x", (*printed++ ? delim : ""), (unsigned int)value));
+		return (sprintf(outp, "%s%08x", (*(printed)++ ? delim : ""), (unsigned int)value));
 	else
-		return (sprintf(outp, "%s%016llx", (*printed++ ? delim : ""), value));
+		return (sprintf(outp, "%s%016llx", (*(printed)++ ? delim : ""), value));
 }
 
 static inline int print_decimal_value(int width, int *printed, char *delim, unsigned long long value)
 {
 	UNUSED(width);
 
-	return (sprintf(outp, "%s%lld", (*printed++ ? delim : ""), value));
+	return (sprintf(outp, "%s%lld", (*(printed)++ ? delim : ""), value));
 }
 
 static inline int print_float_value(int *printed, char *delim, double value)
 {
-	return (sprintf(outp, "%s%0.2f", (*printed++ ? delim : ""), value));
+	return (sprintf(outp, "%s%0.2f", (*(printed)++ ? delim : ""), 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 ` Artem Bityutskiy [this message]
2026-03-18  3:23   ` [PATCH 4/5] tools/power turbostat: fix delimiter bug in print functions Len Brown
2026-03-11  9:00 ` [PATCH 5/5] tools/power turbostat: cleanup print helper functions Artem Bityutskiy

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-5-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