Skip to content

Commit 4519fab

Browse files
committed
hwloc/glibc-sched.h: handle bitmap realloc errors
And document them in the API, as well as the other function that cannot fail. Refs #578. Signed-off-by: Brice Goglin <[email protected]>
1 parent cef7d4e commit 4519fab

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

include/hwloc/glibc-sched.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright © 2009 CNRS
3-
* Copyright © 2009-2020 Inria. All rights reserved.
3+
* Copyright © 2009-2023 Inria. All rights reserved.
44
* Copyright © 2009-2011 Université Bordeaux
55
* Copyright © 2011 Cisco Systems, Inc. All rights reserved.
66
* See COPYING in top-level directory.
@@ -52,6 +52,8 @@ extern "C" {
5252
* that takes a cpu_set_t as input parameter.
5353
*
5454
* \p schedsetsize should be sizeof(cpu_set_t) unless \p schedset was dynamically allocated with CPU_ALLOC
55+
*
56+
* \return 0.
5557
*/
5658
static __hwloc_inline int
5759
hwloc_cpuset_to_glibc_sched_affinity(hwloc_topology_t topology __hwloc_attribute_unused, hwloc_const_cpuset_t hwlocset,
@@ -80,6 +82,9 @@ hwloc_cpuset_to_glibc_sched_affinity(hwloc_topology_t topology __hwloc_attribute
8082
* that takes a cpu_set_t as input parameter.
8183
*
8284
* \p schedsetsize should be sizeof(cpu_set_t) unless \p schedset was dynamically allocated with CPU_ALLOC
85+
*
86+
* \return 0 on success.
87+
* \return -1 with errno set to \c ENOMEM if some internal reallocation failed.
8388
*/
8489
static __hwloc_inline int
8590
hwloc_cpuset_from_glibc_sched_affinity(hwloc_topology_t topology __hwloc_attribute_unused, hwloc_cpuset_t hwlocset,
@@ -95,7 +100,8 @@ hwloc_cpuset_from_glibc_sched_affinity(hwloc_topology_t topology __hwloc_attribu
95100
cpu = 0;
96101
while (count) {
97102
if (CPU_ISSET_S(cpu, schedsetsize, schedset)) {
98-
hwloc_bitmap_set(hwlocset, cpu);
103+
if (hwloc_bitmap_set(hwlocset, cpu) < 0)
104+
return -1;
99105
count--;
100106
}
101107
cpu++;
@@ -107,7 +113,8 @@ hwloc_cpuset_from_glibc_sched_affinity(hwloc_topology_t topology __hwloc_attribu
107113
assert(schedsetsize == sizeof(cpu_set_t));
108114
for(cpu=0; cpu<CPU_SETSIZE; cpu++)
109115
if (CPU_ISSET(cpu, schedset))
110-
hwloc_bitmap_set(hwlocset, cpu);
116+
if (hwloc_bitmap_set(hwlocset, cpu) < 0)
117+
return -1;
111118
#endif /* !CPU_ZERO_S */
112119
return 0;
113120
}

0 commit comments

Comments
 (0)