diff options
| author | Ian Rogers <irogers@google.com> | 2025-09-14 11:33:53 -0700 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2025-10-01 11:22:04 -0300 |
| commit | 58a606149c60d5da554302a7a08234cf3ca259f4 (patch) | |
| tree | 645d3e0eab4d2b56168d7b5d0df421a404bacc71 /tools/perf/builtin-sched.c | |
| parent | perf test perftool_testsuite: Use absolute paths (diff) | |
| download | linux-58a606149c60d5da554302a7a08234cf3ca259f4.tar.gz linux-58a606149c60d5da554302a7a08234cf3ca259f4.zip | |
perf sched: Avoid union type punning undefined behavior
A union is used to set the priv value in thread (a void*) to a boolean
value through type punning. Undefined behavior sanitizer fails on this.
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/builtin-sched.c')
| -rw-r--r-- | tools/perf/builtin-sched.c | 19 |
1 files changed, 4 insertions, 15 deletions
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index f166d6cbc083..eca3b1c58c4b 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -1532,35 +1532,24 @@ static int process_sched_wakeup_ignore(const struct perf_tool *tool __maybe_unus return 0; } -union map_priv { - void *ptr; - bool color; -}; - static bool thread__has_color(struct thread *thread) { - union map_priv priv = { - .ptr = thread__priv(thread), - }; - - return priv.color; + return thread__priv(thread) != NULL; } static struct thread* map__findnew_thread(struct perf_sched *sched, struct machine *machine, pid_t pid, pid_t tid) { struct thread *thread = machine__findnew_thread(machine, pid, tid); - union map_priv priv = { - .color = false, - }; + bool color = false; if (!sched->map.color_pids || !thread || thread__priv(thread)) return thread; if (thread_map__has(sched->map.color_pids, tid)) - priv.color = true; + color = true; - thread__set_priv(thread, priv.ptr); + thread__set_priv(thread, color ? ((void*)1) : NULL); return thread; } |
