]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
perf annotate: Fix crashes on empty annotate windows
authorJames Clark <james.clark@linaro.org>
Mon, 20 Apr 2026 11:52:17 +0000 (12:52 +0100)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 4 Jun 2026 14:13:25 +0000 (11:13 -0300)
Annotate can open with an empty window if the disassembly tool fails.
After the linked change, the TUI started assuming there was a current
annotation line and could assert or segfault in the seek, refresh, and
source-toggle paths.

Handle empty annotate windows explicitly: set the asm entry count before
resetting the browser, return early when refreshing an empty list, and
ignore source line toggle when there is no current annotation line.

Fixes the following when opening an annotation:

  perf: ui/browser.c:125: ui_browser__list_head_seek: Assertion `pos != NULL' failed.
  Aborted

Fixes: e201757f7a0a901e ("perf annotate: Fix source code annotate with objdump")
Assisted-by: GitHub Copilot:GPT-5.4
Signed-off-by: James Clark <james.clark@linaro.org>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/ui/browser.c
tools/perf/ui/browsers/annotate.c

index dc88427b4ae5af4cfeaf52d8d57509a13f6300d3..321187b204d38d7b10912a7188543f814ff416e3 100644 (file)
@@ -513,6 +513,9 @@ unsigned int ui_browser__list_head_refresh(struct ui_browser *browser)
        struct list_head *head = browser->entries;
        int row = 0;
 
+       if (browser->nr_entries == 0)
+               return 0;
+
        if (browser->top == NULL || browser->top == browser->entries)
                 browser->top = ui_browser__list_head_filter_entries(browser, head->next);
 
index e220c4dfc8819c308c0e5bd08d33cb02c6516036..97ae4c86bebbe3bcf9aabafb46367f2d4cb9c362 100644 (file)
@@ -449,6 +449,9 @@ static bool annotate_browser__toggle_source(struct annotate_browser *browser,
        struct annotation_line *al;
        off_t offset = browser->b.index - browser->b.top_idx;
 
+       if (browser->b.nr_entries == 0)
+               return false;
+
        browser->b.seek(&browser->b, offset, SEEK_CUR);
        al = list_entry(browser->b.top, struct annotation_line, node);
 
@@ -542,8 +545,8 @@ static void annotate_browser__show_full_location(struct ui_browser *browser)
 static void ui_browser__init_asm_mode(struct ui_browser *browser)
 {
        struct annotation *notes = browser__annotation(browser);
-       ui_browser__reset_index(browser);
        browser->nr_entries = notes->src->nr_asm_entries;
+       ui_browser__reset_index(browser);
 }
 
 static int sym_title(struct symbol *sym, struct map *map, char *title,