]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
tools/power turbostat: Fix delimiter bug in print functions
authorArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
Wed, 11 Mar 2026 09:00:34 +0000 (11:00 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 22 Apr 2026 11:30:35 +0000 (13:30 +0200)
[ Upstream commit cdbefe9d4029d4834d404f7ba13a960b38a69e88 ]

Commands that add counters, such as 'turbostat --show C1,C1+'
display merged columns without a delimiter.

This is caused by the bad syntax: '(*printed++ ? delim : "")', shared by
print_name()/print_hex_value()/print_decimal_value()/print_float_value()

Use '((*printed)++ ? delim : "")' to correctly increment the value at *printed.

[lenb: fix code and commit message typo, re-word]
Fixes: 56dbb878507b ("tools/power turbostat: Refactor added column header printing")
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Signed-off-by: Len Brown <len.brown@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
tools/power/x86/turbostat/turbostat.c

index b01a905bd24a74e911e45af7e7909b37599cd16f..c6060f65eaaf14d0f4ea119dc2724f88276a0f02 100644 (file)
@@ -2732,29 +2732,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)