Skip to content

Commit dbfb302

Browse files
captain5050gregkh
authored andcommitted
perf trace: Avoid an ERR_PTR in syscall_stats
[ Upstream commit d05073a ] hashmap__new may return an ERR_PTR and previously this would be assigned to syscall_stats meaning all use of syscall_stats needs to test for NULL (uninitialized) or an ERR_PTR. Given the only reason hashmap__new can fail is ENOMEM, just use NULL to indicate the allocation failure and avoid the code having to test for NULL and IS_ERR. Fixes: 96f202e (perf trace: Fix IS_ERR() vs NULL check bug) Signed-off-by: Ian Rogers <irogers@google.com> Signed-off-by: Namhyung Kim <namhyung@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 4d994ff commit dbfb302

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

tools/perf/builtin-trace.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,15 +1565,17 @@ static bool syscall_id_equal(long key1, long key2, void *ctx __maybe_unused)
15651565

15661566
static struct hashmap *alloc_syscall_stats(void)
15671567
{
1568-
return hashmap__new(syscall_id_hash, syscall_id_equal, NULL);
1568+
struct hashmap *result = hashmap__new(syscall_id_hash, syscall_id_equal, NULL);
1569+
1570+
return IS_ERR(result) ? NULL : result;
15691571
}
15701572

15711573
static void delete_syscall_stats(struct hashmap *syscall_stats)
15721574
{
15731575
struct hashmap_entry *pos;
15741576
size_t bkt;
15751577

1576-
if (IS_ERR(syscall_stats))
1578+
if (!syscall_stats)
15771579
return;
15781580

15791581
hashmap__for_each_entry(syscall_stats, pos, bkt)
@@ -1589,7 +1591,7 @@ static struct thread_trace *thread_trace__new(struct trace *trace)
15891591
ttrace->files.max = -1;
15901592
if (trace->summary) {
15911593
ttrace->syscall_stats = alloc_syscall_stats();
1592-
if (IS_ERR(ttrace->syscall_stats))
1594+
if (!ttrace->syscall_stats)
15931595
zfree(&ttrace);
15941596
}
15951597
}
@@ -4441,7 +4443,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
44414443

44424444
if (trace->summary_mode == SUMMARY__BY_TOTAL && !trace->summary_bpf) {
44434445
trace->syscall_stats = alloc_syscall_stats();
4444-
if (IS_ERR(trace->syscall_stats))
4446+
if (!trace->syscall_stats)
44454447
goto out_delete_evlist;
44464448
}
44474449

@@ -4749,7 +4751,7 @@ static int trace__replay(struct trace *trace)
47494751

47504752
if (trace->summary_mode == SUMMARY__BY_TOTAL) {
47514753
trace->syscall_stats = alloc_syscall_stats();
4752-
if (IS_ERR(trace->syscall_stats))
4754+
if (!trace->syscall_stats)
47534755
goto out;
47544756
}
47554757

0 commit comments

Comments
 (0)