Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf color: Add printf format checking and resolve issues

Add printf format checking to vararg printf routines in
color.h. Resolve build errors/bugs that are found through this
checking.

Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Yicong Yang <yangyicong@hisilicon.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Will Deacon <will@kernel.org>
Cc: James Clark <james.clark@linaro.org>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Leo Yan <leo.yan@linux.dev>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Tim Chen <tim.c.chen@linux.intel.com>
Cc: John Garry <john.g.garry@oracle.com>
Link: https://lore.kernel.org/r/20241017175356.783793-2-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>

authored by

Ian Rogers and committed by
Namhyung Kim
58fc358a 4585038b

+15 -14
+1 -1
tools/perf/builtin-sched.c
··· 1743 1743 } 1744 1744 1745 1745 if (sched->map.comp && new_cpu) 1746 - color_fprintf(stdout, color, " (CPU %d)", this_cpu); 1746 + color_fprintf(stdout, color, " (CPU %d)", this_cpu.cpu); 1747 1747 1748 1748 if (proceed != 1) { 1749 1749 color_fprintf(stdout, color, "\n");
+1 -1
tools/perf/builtin-trace.c
··· 1873 1873 switch (event->header.type) { 1874 1874 case PERF_RECORD_LOST: 1875 1875 color_fprintf(trace->output, PERF_COLOR_RED, 1876 - "LOST %" PRIu64 " events!\n", event->lost.lost); 1876 + "LOST %" PRIu64 " events!\n", (u64)event->lost.lost); 1877 1877 ret = machine__process_lost_event(machine, event, sample); 1878 1878 break; 1879 1879 default:
+1 -1
tools/perf/util/arm-spe.c
··· 122 122 else 123 123 pkt_len = 1; 124 124 printf("."); 125 - color_fprintf(stdout, color, " %08x: ", pos); 125 + color_fprintf(stdout, color, " %08zx: ", pos); 126 126 for (i = 0; i < pkt_len; i++) 127 127 color_fprintf(stdout, color, " %02x", buf[i]); 128 128 for (; i < 16; i++)
+5 -4
tools/perf/util/color.h
··· 2 2 #ifndef __PERF_COLOR_H 3 3 #define __PERF_COLOR_H 4 4 5 + #include <linux/compiler.h> 5 6 #include <stdio.h> 6 7 #include <stdarg.h> 7 8 ··· 38 37 int color_vsnprintf(char *bf, size_t size, const char *color, 39 38 const char *fmt, va_list args); 40 39 int color_vfprintf(FILE *fp, const char *color, const char *fmt, va_list args); 41 - int color_fprintf(FILE *fp, const char *color, const char *fmt, ...); 42 - int color_snprintf(char *bf, size_t size, const char *color, const char *fmt, ...); 40 + int color_fprintf(FILE *fp, const char *color, const char *fmt, ...) __printf(3, 4); 41 + int color_snprintf(char *bf, size_t size, const char *color, const char *fmt, ...) __printf(4, 5); 43 42 int value_color_snprintf(char *bf, size_t size, const char *fmt, double value); 44 - int percent_color_snprintf(char *bf, size_t size, const char *fmt, ...); 45 - int percent_color_len_snprintf(char *bf, size_t size, const char *fmt, ...); 43 + int percent_color_snprintf(char *bf, size_t size, const char *fmt, ...) __printf(3, 4); 44 + int percent_color_len_snprintf(char *bf, size_t size, const char *fmt, ...) __printf(3, 4); 46 45 int percent_color_fprintf(FILE *fp, const char *fmt, double percent); 47 46 const char *get_percent_color(double percent); 48 47
+1 -1
tools/perf/util/intel-bts.c
··· 100 100 else 101 101 sz = len; 102 102 printf("."); 103 - color_fprintf(stdout, color, " %08x: ", pos); 103 + color_fprintf(stdout, color, " %08zx: ", pos); 104 104 for (i = 0; i < sz; i++) 105 105 color_fprintf(stdout, color, " %02x", buf[i]); 106 106 for (; i < br_sz; i++)
+1 -1
tools/perf/util/intel-pt.c
··· 249 249 else 250 250 pkt_len = 1; 251 251 printf("."); 252 - color_fprintf(stdout, color, " %08x: ", pos); 252 + color_fprintf(stdout, color, " %08zx: ", pos); 253 253 for (i = 0; i < pkt_len; i++) 254 254 color_fprintf(stdout, color, " %02x", buf[i]); 255 255 for (; i < 16; i++)
+1 -1
tools/perf/util/s390-cpumsf.c
··· 345 345 } 346 346 color_fprintf(stdout, color, " [%#08zx] Trailer %c%c%c bsdes:%d" 347 347 " dsdes:%d Overflow:%lld Time:%#llx\n" 348 - "\t\tC:%d TOD:%#lx\n", 348 + "\t\tC:%d TOD:%#llx\n", 349 349 pos, 350 350 te->f ? 'F' : ' ', 351 351 te->a ? 'A' : ' ',
+4 -4
tools/perf/util/s390-sample-raw.c
··· 98 98 te.res2 = be32_to_cpu(tep->res2); 99 99 100 100 color_fprintf(stdout, color, " [%#08zx] Trailer:%c%c%c%c%c" 101 - " Cfvn:%d Csvn:%d Speed:%d TOD:%#llx\n", 101 + " Cfvn:%d Csvn:%d Speed:%d TOD:%#lx\n", 102 102 offset, te.clock_base ? 'T' : ' ', 103 103 te.speed ? 'S' : ' ', te.mtda ? 'M' : ' ', 104 104 te.caca ? 'C' : ' ', te.lcda ? 'L' : ' ', 105 105 te.cfvn, te.csvn, te.cpu_speed, te.timestamp); 106 - color_fprintf(stdout, color, "\t\t1:%lx 2:%lx 3:%lx TOD-Base:%#llx" 106 + color_fprintf(stdout, color, "\t\t1:%lx 2:%lx 3:%lx TOD-Base:%#lx" 107 107 " Type:%x\n\n", 108 108 te.progusage1, te.progusage2, te.progusage3, 109 109 te.tod_base, te.mach_type); ··· 205 205 char *ev_name = get_counter_name(ce.set, i, pmu); 206 206 207 207 color_fprintf(stdout, color, 208 - "\tCounter:%03d %s Value:%#018lx\n", i, 208 + "\tCounter:%03zd %s Value:%#018"PRIx64"\n", i, 209 209 ev_name ?: "<unknown>", be64_to_cpu(*p)); 210 210 free(ev_name); 211 211 } ··· 260 260 261 261 ev_name = get_counter_name(evsel->core.attr.config, 262 262 pai_data.event_nr, evsel->pmu); 263 - color_fprintf(stdout, color, "\tCounter:%03d %s Value:%#018lx\n", 263 + color_fprintf(stdout, color, "\tCounter:%03d %s Value:%#018"PRIx64"\n", 264 264 pai_data.event_nr, ev_name ?: "<unknown>", 265 265 pai_data.event_val); 266 266 free(ev_name);