[PATCH v1 13/48] perf trace-event: Silence -Wshorten-64-to-32 warnings

Ian Rogers
2025-04-01T18:25:03Z

tools/perf/util/python.c | 4 ++--
.../scripting-engines/trace-event-python.c | 13 ++++++-----
tools/perf/util/trace-event-info.c | 3 ++-
tools/perf/util/trace-event-parse.c | 2 +-
tools/perf/util/trace-event-read.c | 23 +++++++++----------
tools/perf/util/trace-event-scripting.c | 2 +-
6 files changed, 24 insertions(+), 23 deletions(-)

diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index f3c05da25b4a..f55b2b7435ad 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -305,7 +305,7 @@ tracepoint_field(const struct pyrf_event *pe, struct tep_format_field *field)
len = field->size;
if (field->flags & TEP_FIELD_IS_DYNAMIC) {
val = tep_read_number(pevent, data + offset, len);
- offset = val;
+ offset = (unsigned int)val;
len = offset >> 16;
offset &= 0xffff;
if (tep_field_is_relative(field->flags))
@@ -599,7 +599,7 @@ static PyObject *pyrf_thread_map__item(PyObject *obj, Py_ssize_t i)
if (i >= perf_thread_map__nr(pthreads->threads))
return NULL;

- return Py_BuildValue("i", perf_thread_map__pid(pthreads->threads, i));
+ return Py_BuildValue("i", (int)perf_thread_map__pid(pthreads->threads, (int)i));
}

static PySequenceMethods pyrf_thread_map__sequence_methods = {
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
index 520729e78965..547eeb45a832 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -713,9 +713,10 @@ static void set_sample_datasrc_in_dict(PyObject *dict,
_PyUnicode_FromString(decode));
}

-static void regs_map(struct regs_dump *regs, uint64_t mask, const char *arch, char *bf, int size)
+static void regs_map(struct regs_dump *regs, uint64_t mask, const char *arch, char *bf, size_t size)
{
- unsigned int i = 0, r;
+ unsigned int i = 0;
+ u64 r;
int printed = 0;

bf[0] = 0;
@@ -731,7 +732,7 @@ static void regs_map(struct regs_dump *regs, uint64_t mask, const char *arch, ch

printed += scnprintf(bf + printed, size - printed,
"%5s:0x%" PRIx64 " ",
- perf_reg_name(r, arch), val);
+ perf_reg_name((int)r, arch), val);
}
}

@@ -744,7 +745,7 @@ static int set_regs_in_dict(PyObject *dict,
struct perf_event_attr *attr = &evsel->core.attr;
const char *arch = perf_env__arch(evsel__env(evsel));

- int size = (__sw_hweight64(attr->sample_regs_intr) * MAX_REG_SIZE) + 1;
+ size_t size = (__sw_hweight64(attr->sample_regs_intr) * MAX_REG_SIZE) + 1;
char *bf = NULL;

if (sample->intr_regs) {
@@ -957,7 +958,7 @@ static void python_process_tracepoint(struct perf_sample *sample,
Py_FatalError(handler_name);
}

- pid = raw_field_value(event, "common_pid", data);
+ pid = (int)raw_field_value(event, "common_pid", data);

sprintf(handler_name, "%s__%s", event->system, event->name);

@@ -1017,7 +1018,7 @@ static void python_process_tracepoint(struct perf_sample *sample,
if (field->flags & TEP_FIELD_IS_DYNAMIC) {
val = tep_read_number(scripting_context->pevent,
data + offset, len);
- offset = val;
+ offset = (unsigned int)val;
len = offset >> 16;
offset &= 0xffff;
if (tep_field_is_relative(field->flags))
diff --git a/tools/perf/util/trace-event-info.c b/tools/perf/util/trace-event-info.c
index c8755679281e..0f012890ff21 100644
--- a/tools/perf/util/trace-event-info.c
+++ b/tools/perf/util/trace-event-info.c
@@ -45,7 +45,8 @@ static int record_file(const char *file, ssize_t hdr_sz)
unsigned long long size = 0;
char buf[BUFSIZ], *sizep;
off_t hdr_pos = lseek(output_fd, 0, SEEK_CUR);
- int r, fd;
+ int fd;
+ ssize_t r;
int err = -EIO;

fd = open(file, O_RDONLY);
diff --git a/tools/perf/util/trace-event-parse.c b/tools/perf/util/trace-event-parse.c
index 9c015fc2bcfb..982cbbc57168 100644
--- a/tools/perf/util/trace-event-parse.c
+++ b/tools/perf/util/trace-event-parse.c
@@ -34,7 +34,7 @@ static int get_common_field(struct scripting_context *context,
*size = field->size;
}

- return tep_read_number(pevent, context->event_data + *offset, *size);
+ return (int)tep_read_number(pevent, context->event_data + *offset, *size);
}

int common_lock_depth(struct scripting_context *context)
diff --git a/tools/perf/util/trace-event-read.c b/tools/perf/util/trace-event-read.c
index ecbbb93f0185..78a3b3801d69 100644
--- a/tools/perf/util/trace-event-read.c
+++ b/tools/perf/util/trace-event-read.c
@@ -25,18 +25,18 @@ static int input_fd;
static ssize_t trace_data_size;
static bool repipe;

-static int __do_read(int fd, void *buf, int size)
+static int __do_read(int fd, void *buf, size_t size)
{
- int rsize = size;
+ int rsize = (int)size;

while (size) {
- int ret = read(fd, buf, size);
+ ssize_t ret = read(fd, buf, size);

if (ret <= 0)
return -1;

if (repipe) {
- int retw = write(STDOUT_FILENO, buf, ret);
+ ssize_t retw = write(STDOUT_FILENO, buf, ret);

if (retw <= 0 || retw != ret) {
pr_debug("repiping input file");
@@ -51,14 +51,13 @@ static int __do_read(int fd, void *buf, int size)
return rsize;
}

-static int do_read(void *data, int size)
+static int do_read(void *data, size_t size)
{
int r;

r = __do_read(input_fd, data, size);
if (r <= 0) {
- pr_debug("reading input file (size expected=%d received=%d)",
- size, r);
+ pr_debug("reading input file (size expected=%zd received=%d)", size, r);
return -1;
}

@@ -68,10 +67,10 @@ static int do_read(void *data, int size)
}

/* If it fails, the next read will report it */
-static void skip(int size)
+static void skip(unsigned long long size)
{
char buf[BUFSIZ];
- int r;
+ unsigned long long r;

while (size) {
r = size > BUFSIZ ? BUFSIZ : size;
@@ -86,7 +85,7 @@ static unsigned int read4(struct tep_handle *pevent)

if (do_read(&data, 4) < 0)
return 0;
- return tep_read_number(pevent, &data, 4);
+ return (unsigned int)tep_read_number(pevent, &data, 4);
}

static unsigned long long read8(struct tep_handle *pevent)
@@ -119,7 +118,7 @@ static char *read_string(void)
}

if (repipe) {
- int retw = write(STDOUT_FILENO, &c, 1);
+ ssize_t retw = write(STDOUT_FILENO, &c, 1);

if (retw <= 0 || retw != r) {
pr_debug("repiping input file string");
@@ -365,7 +364,7 @@ static int read_saved_cmdline(struct tep_handle *pevent)
}
buf[ret] = '\0';

- parse_saved_cmdline(pevent, buf, size);
+ parse_saved_cmdline(pevent, buf, (unsigned int)size);
ret = 0;
out:
free(buf);
diff --git a/tools/perf/util/trace-event-scripting.c b/tools/perf/util/trace-event-scripting.c
index 72abb28b7b5a..fb1fa227c98e 100644
--- a/tools/perf/util/trace-event-scripting.c
+++ b/tools/perf/util/trace-event-scripting.c
@@ -422,5 +422,5 @@ int perf_sample__sprintf_flags(u32 flags, char *str, size_t sz)
if (pos < sz)
str[pos] = 0;

- return pos;
+ return (int)pos;
}
--
2.49.0.504.g3bcea36a83-goog