Re: [PATCH 5/9] perf sched: Clean up idle_threads entry on init failure
From: David Ahern
Date: Sat Jun 06 2026 - 11:46:58 EST
On 6/5/26 5:38 PM, Arnaldo Carvalho de Melo wrote:
> From: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
>
> get_idle_thread() allocates a thread via thread__new() and stores it in
> idle_threads[cpu], then calls init_idle_thread() to set up the private
> data. If init_idle_thread() fails (e.g. OOM for the idle_thread_runtime
> struct), the function returns NULL but leaves the partially initialized
> thread in idle_threads[cpu].
>
> On subsequent calls for the same CPU, get_idle_thread() finds a non-NULL
> idle_threads[cpu], skips allocation, and returns thread__get() on a
> thread that has no priv data. Callers then get a thread whose
> thread__priv() returns NULL, leading to unexpected behavior.
>
> Release the thread and reset the slot to NULL on init failure so the
> entry doesn't persist in a corrupted state.
>
> Fixes: 49394a2a24c7 ("perf sched timehist: Introduce timehist command")
> Reported-by: sashiko-bot <sashiko-bot@xxxxxxxxxx>
> Cc: David Ahern <dsahern@xxxxxxxxx>
> Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
> Assisted-by: Claude Opus 4.6 <noreply@xxxxxxxxxxxxx>
> Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
> ---
> tools/perf/builtin-sched.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
Reviewed-by: David Ahern <dsahern@xxxxxxxxxx>