linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tools/lib/perf: Fix -Werror=alloc-size-larger-than in cpumap.c
@ 2025-04-06 16:34 Likhitha Korrapati
  2025-04-06 18:40 ` Athira Rajeev
  2025-04-07  5:39 ` Mukesh Kumar Chaurasiya
  0 siblings, 2 replies; 17+ messages in thread
From: Likhitha Korrapati @ 2025-04-06 16:34 UTC (permalink / raw)
  To: acme, jolsa, adrian.hunter, irogers, namhyung
  Cc: linux-perf-users, linuxppc-dev, maddy, atrajeev,
	Likhitha Korrapati

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@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


^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2025-05-21 17:39 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-06 16:34 [PATCH] tools/lib/perf: Fix -Werror=alloc-size-larger-than in cpumap.c Likhitha Korrapati
2025-04-06 18:40 ` Athira Rajeev
2025-04-07 12:08   ` Venkat Rao Bagalkote
2025-04-14  1:38     ` Madhavan Srinivasan
2025-04-25 14:49       ` Athira Rajeev
2025-04-25 17:46         ` Arnaldo Carvalho de Melo
2025-04-29  5:11           ` Likhitha Korrapati
2025-05-02  7:44           ` Mukesh Kumar Chaurasiya
2025-05-13 21:13             ` Arnaldo Carvalho de Melo
2025-05-13 22:12               ` Ian Rogers
2025-05-13 22:36                 ` Ian Rogers
2025-05-21 13:03               ` Likhitha Korrapati
2025-05-21 15:45                 ` Ian Rogers
2025-05-21 17:28                   ` Likhitha Korrapati
2025-05-21 17:39                     ` Ian Rogers
2025-05-02  9:05           ` Likhitha Korrapati
2025-04-07  5:39 ` Mukesh Kumar Chaurasiya

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).