Skip to content

Commit 509f68e

Browse files
Alexander Gordeevacmel
authored andcommitted
perf bench numa: Fix cpumask memory leak in node_has_cpus()
Couple numa_allocate_cpumask() and numa_free_cpumask() functions Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com> Reviewed-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Balamuruhan S <bala24@linux.vnet.ibm.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Satheesh Rajendran <sathnaga@linux.vnet.ibm.com> Link: http://lore.kernel.org/lkml/20200813113041.GA1685@oc3871087118.ibm.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent fa5c893 commit 509f68e

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

‎tools/perf/bench/numa.c‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,16 +248,21 @@ static int is_node_present(int node)
248248
static bool node_has_cpus(int node)
249249
{
250250
struct bitmask *cpu = numa_allocate_cpumask();
251+
bool ret = false; /* fall back to nocpus */
251252
unsigned int i;
252253

253-
if (cpu && !numa_node_to_cpus(node, cpu)) {
254+
BUG_ON(!cpu);
255+
if (!numa_node_to_cpus(node, cpu)) {
254256
for (i = 0; i < cpu->size; i++) {
255-
if (numa_bitmask_isbitset(cpu, i))
256-
return true;
257+
if (numa_bitmask_isbitset(cpu, i)) {
258+
ret = true;
259+
break;
260+
}
257261
}
258262
}
263+
numa_free_cpumask(cpu);
259264

260-
return false; /* lets fall back to nocpus safely */
265+
return ret;
261266
}
262267

263268
static cpu_set_t bind_to_cpu(int target_cpu)

0 commit comments

Comments
 (0)