[PATCH] tools/lib/perf: Fix -Werror=alloc-size-larger-than in cpumap.c
Likhitha Korrapati
likhitha at linux.ibm.com
Mon Apr 7 02:34:12 AEST 2025
perf build break observed when using gcc 13-3 (FC39 ppc64le)
with the following error.
cpumap.c: In function 'perf_cpu_map__merge':
cpumap.c:414:20: error: argument 1 range [18446744069414584320, 18446744073709551614] exceeds maximum object size 9223372036854775807 [-Werror=alloc-size-larger-than=]
414 | tmp_cpus = malloc(tmp_len * sizeof(struct perf_cpu));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from cpumap.c:4:
/usr/include/stdlib.h:672:14: note: in a call to allocation function 'malloc' declared here
672 | extern void *malloc (size_t __size) __THROW __attribute_malloc__
| ^~~~~~
cc1: all warnings being treated as errors
Error happens to be only in gcc13-3 and not in latest gcc 14.
Even though git-bisect pointed bad commit as:
'commit f5b07010c13c ("libperf: Don't remove -g when EXTRA_CFLAGS are used")',
issue is with tmp_len being "int". It holds number of cpus and making
it "unsigned int" fixes the issues.
After the fix:
CC util/pmu-flex.o
CC util/expr-flex.o
LD util/perf-util-in.o
LD perf-util-in.o
AR libperf-util.a
LINK perf
GEN python/perf.cpython-312-powerpc64le-linux-gnu.so
Signed-off-by: Likhitha Korrapati <likhitha at linux.ibm.com>
---
tools/lib/perf/cpumap.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/lib/perf/cpumap.c b/tools/lib/perf/cpumap.c
index 4454a5987570..c7c784e18225 100644
--- a/tools/lib/perf/cpumap.c
+++ b/tools/lib/perf/cpumap.c
@@ -398,7 +398,7 @@ bool perf_cpu_map__is_subset(const struct perf_cpu_map *a, const struct perf_cpu
int perf_cpu_map__merge(struct perf_cpu_map **orig, struct perf_cpu_map *other)
{
struct perf_cpu *tmp_cpus;
- int tmp_len;
+ unsigned int tmp_len;
int i, j, k;
struct perf_cpu_map *merged;
--
2.43.5
More information about the Linuxppc-dev
mailing list