mirror of
https://github.com/torvalds/linux.git
synced 2026-07-28 01:55:51 +02:00
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>
This commit is contained in:
parent
241f21be7d
commit
58a606149c
|
|
@ -1532,35 +1532,24 @@ static int process_sched_wakeup_ignore(const struct perf_tool *tool __maybe_unus
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
union map_priv {
|
|
||||||
void *ptr;
|
|
||||||
bool color;
|
|
||||||
};
|
|
||||||
|
|
||||||
static bool thread__has_color(struct thread *thread)
|
static bool thread__has_color(struct thread *thread)
|
||||||
{
|
{
|
||||||
union map_priv priv = {
|
return thread__priv(thread) != NULL;
|
||||||
.ptr = thread__priv(thread),
|
|
||||||
};
|
|
||||||
|
|
||||||
return priv.color;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct thread*
|
static struct thread*
|
||||||
map__findnew_thread(struct perf_sched *sched, struct machine *machine, pid_t pid, pid_t tid)
|
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);
|
struct thread *thread = machine__findnew_thread(machine, pid, tid);
|
||||||
union map_priv priv = {
|
bool color = false;
|
||||||
.color = false,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!sched->map.color_pids || !thread || thread__priv(thread))
|
if (!sched->map.color_pids || !thread || thread__priv(thread))
|
||||||
return thread;
|
return thread;
|
||||||
|
|
||||||
if (thread_map__has(sched->map.color_pids, tid))
|
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;
|
return thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user