lkml.org 
[lkml]   [2022]   [Jan]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
Subject[PATCH v4 33/48] libperf: Allow NULL in perf_cpu_map__idx
From
Return -1, not found, if NULL is passed.

Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/lib/perf/cpumap.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/tools/lib/perf/cpumap.c b/tools/lib/perf/cpumap.c
index 3c36a06771af..eacea3ab965a 100644
--- a/tools/lib/perf/cpumap.c
+++ b/tools/lib/perf/cpumap.c
@@ -270,8 +270,13 @@ bool perf_cpu_map__empty(const struct perf_cpu_map *map)

int perf_cpu_map__idx(const struct perf_cpu_map *cpus, int cpu)
{
- int low = 0, high = cpus->nr;
+ int low, high;

+ if (!cpus)
+ return -1;
+
+ low = 0;
+ high = cpus->nr;
while (low < high) {
int idx = (low + high) / 2,
cpu_at_idx = cpus->map[idx];
--
2.34.1.448.ga2b2bfdf31-goog
\
 
 \ /
  Last update: 2022-01-05 07:17    [W:0.298 / U:0.636 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site