[PATCH v1 35/48] perf ftrace: Silence -Wshorten-64-to-32 warnings

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

tools/perf/builtin-ftrace.c | 17 +++++++++++------
tools/perf/util/bpf_ftrace.c | 4 ++--
2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
index 7caa18d5ffc3..1484d798de40 100644
--- a/tools/perf/builtin-ftrace.c
+++ b/tools/perf/builtin-ftrace.c
@@ -182,7 +182,8 @@ static int read_tracing_file_to_stdout(const char *name)

/* read contents to stdout */
while (true) {
- int n = read(fd, buf, sizeof(buf));
+ ssize_t n = read(fd, buf, sizeof(buf));
+
if (n == 0)
break;
else if (n < 0)
@@ -449,7 +450,7 @@ static int set_tracing_percpu_buffer_size(struct perf_ftrace *ftrace)
return 0;

ret = write_tracing_file_int("buffer_size_kb",
- ftrace->percpu_buffer_size / 1024);
+ (int)(ftrace->percpu_buffer_size / 1024));
if (ret < 0)
return ret;

@@ -691,7 +692,8 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace)
break;

if (pollfd.revents & POLLIN) {
- int n = read(trace_fd, buf, sizeof(buf));
+ ssize_t n = read(trace_fd, buf, sizeof(buf));
+
if (n < 0)
break;
if (fwrite(buf, n, 1, stdout) != 1)
@@ -713,7 +715,8 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace)

/* read remaining buffer contents */
while (true) {
- int n = read(trace_fd, buf, sizeof(buf));
+ ssize_t n = read(trace_fd, buf, sizeof(buf));
+
if (n <= 0)
break;
if (fwrite(buf, n, 1, stdout) != 1)
@@ -1031,7 +1034,8 @@ static int __cmd_latency(struct perf_ftrace *ftrace)
break;

if (pollfd.revents & POLLIN) {
- int n = read(trace_fd, buf, sizeof(buf) - 1);
+ ssize_t n = read(trace_fd, buf, sizeof(buf) - 1);
+
if (n < 0)
break;

@@ -1049,7 +1053,8 @@ static int __cmd_latency(struct perf_ftrace *ftrace)

/* read remaining buffer contents */
while (!ftrace->target.use_bpf) {
- int n = read(trace_fd, buf, sizeof(buf) - 1);
+ ssize_t n = read(trace_fd, buf, sizeof(buf) - 1);
+
if (n <= 0)
break;
make_histogram(ftrace, buckets, buf, n, line);
diff --git a/tools/perf/util/bpf_ftrace.c b/tools/perf/util/bpf_ftrace.c
index 7324668cc83e..c4b3bb4e5922 100644
--- a/tools/perf/util/bpf_ftrace.c
+++ b/tools/perf/util/bpf_ftrace.c
@@ -97,7 +97,7 @@ int perf_ftrace__latency_prepare_bpf(struct perf_ftrace *ftrace)
false, func->name);
if (IS_ERR(skel->links.func_begin)) {
pr_err("Failed to attach fentry program\n");
- err = PTR_ERR(skel->links.func_begin);
+ err = (int)PTR_ERR(skel->links.func_begin);
goto out;
}

@@ -105,7 +105,7 @@ int perf_ftrace__latency_prepare_bpf(struct perf_ftrace *ftrace)
true, func->name);
if (IS_ERR(skel->links.func_end)) {
pr_err("Failed to attach fexit program\n");
- err = PTR_ERR(skel->links.func_end);
+ err = (int)PTR_ERR(skel->links.func_end);
goto out;
}

--
2.49.0.504.g3bcea36a83-goog