From: Ian Rogers <irogers@google.com>
To: "Yury Norov" <yury.norov@gmail.com>,
"Rasmus Villemoes" <linux@rasmusvillemoes.dk>,
"Peter Zijlstra" <peterz@infradead.org>,
"Ingo Molnar" <mingo@redhat.com>,
"Arnaldo Carvalho de Melo" <acme@kernel.org>,
"Namhyung Kim" <namhyung@kernel.org>,
"Mark Rutland" <mark.rutland@arm.com>,
"Alexander Shishkin" <alexander.shishkin@linux.intel.com>,
"Jiri Olsa" <jolsa@kernel.org>, "Ian Rogers" <irogers@google.com>,
"Adrian Hunter" <adrian.hunter@intel.com>,
"Kan Liang" <kan.liang@linux.intel.com>,
"Thomas Gleixner" <tglx@linutronix.de>,
"Darren Hart" <dvhart@infradead.org>,
"Davidlohr Bueso" <dave@stgolabs.net>,
"André Almeida" <andrealmeid@igalia.com>,
"John Garry" <john.g.garry@oracle.com>,
"Will Deacon" <will@kernel.org>,
"James Clark" <james.clark@linaro.org>,
"Mike Leach" <mike.leach@linaro.org>,
"Leo Yan" <leo.yan@linux.dev>,
"Yicong Yang" <yangyicong@hisilicon.com>,
"Jonathan Cameron" <jonathan.cameron@huawei.com>,
"Nathan Chancellor" <nathan@kernel.org>,
"Bill Wendling" <morbo@google.com>,
"Justin Stitt" <justinstitt@google.com>,
"Josh Poimboeuf" <jpoimboe@kernel.org>,
"Al Viro" <viro@zeniv.linux.org.uk>,
"Kyle Meyer" <kyle.meyer@hpe.com>,
"Ben Gainey" <ben.gainey@arm.com>,
"Athira Rajeev" <atrajeev@linux.vnet.ibm.com>,
"Kajol Jain" <kjain@linux.ibm.com>,
"Aditya Gupta" <adityag@linux.ibm.com>,
"Eder Zulian" <ezulian@redhat.com>,
"Dapeng Mi" <dapeng1.mi@linux.intel.com>,
"Kuan-Wei Chiu" <visitorckw@gmail.com>,
"He Zhe" <zhe.he@windriver.com>,
"Dirk Gouders" <dirk@gouders.net>,
"Brian Geffon" <bgeffon@google.com>,
"Ravi Bangoria" <ravi.bangoria@amd.com>,
"Howard Chu" <howardchu95@gmail.com>,
"Charlie Jenkins" <charlie@rivosinc.com>,
"Colin Ian King" <colin.i.king@gmail.com>,
"Dominique Martinet" <asmadeus@codewreck.org>,
"Jann Horn" <jannh@google.com>,
"Masahiro Yamada" <masahiroy@kernel.org>,
"Arnd Bergmann" <arnd@arndb.de>,
"Yang Jihong" <yangjihong@bytedance.com>,
"Dmitry Vyukov" <dvyukov@google.com>,
"Andi Kleen" <ak@linux.intel.com>,
"Graham Woodward" <graham.woodward@arm.com>,
"Ilkka Koskinen" <ilkka@os.amperecomputing.com>,
"Anshuman Khandual" <anshuman.khandual@arm.com>,
"Zhongqiu Han" <quic_zhonhan@quicinc.com>,
"Hao Ge" <gehao@kylinos.cn>,
"Tengda Wu" <wutengda@huaweicloud.com>,
"Gabriele Monaco" <gmonaco@redhat.com>,
"Chun-Tse Shao" <ctshao@google.com>,
"Casey Chen" <cachen@purestorage.com>,
"Dr. David Alan Gilbert" <linux@treblig.org>,
"Li Huafei" <lihuafei1@huawei.com>,
"Steinar H. Gunderson" <sesse@google.com>,
"Levi Yun" <yeoreum.yun@arm.com>,
"Weilin Wang" <weilin.wang@intel.com>,
"Thomas Falcon" <thomas.falcon@intel.com>,
"Thomas Richter" <tmricht@linux.ibm.com>,
"Andrew Kreimer" <algonell@gmail.com>,
"Krzysztof Łopatowski" <krzysztof.m.lopatowski@gmail.com>,
"Christophe Leroy" <christophe.leroy@csgroup.eu>,
"Jean-Philippe Romain" <jean-philippe.romain@foss.st.com>,
"Junhao He" <hejunhao3@huawei.com>,
"Masami Hiramatsu (Google)" <mhiramat@kernel.org>,
"Xu Yang" <xu.yang_2@nxp.com>,
"Steve Clevenger" <scclevenger@os.amperecomputing.com>,
"Zixian Cai" <fzczx123@gmail.com>,
"Stephen Brennan" <stephen.s.brennan@oracle.com>,
"Yujie Liu" <yujie.liu@intel.com>,
linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, llvm@lists.linux.dev
Subject: [PATCH v1 13/48] perf trace-event: Silence -Wshorten-64-to-32 warnings
Date: Tue, 1 Apr 2025 11:23:11 -0700 [thread overview]
Message-ID: <20250401182347.3422199-14-irogers@google.com> (raw)
In-Reply-To: <20250401182347.3422199-1-irogers@google.com>
The clang warning -Wshorten-64-to-32 can be useful to catch
inadvertent truncation. In some instances this truncation can lead to
changing the sign of a result, for example, truncation to return an
int to fit a sort routine. Silence the warning by making the implicit
truncation explicit.
Signed-off-by: Ian Rogers <irogers@google.com>
---
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
next prev parent reply other threads:[~2025-04-01 18:25 UTC|newest]
Thread overview: 70+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-01 18:22 [PATCH v1 00/48] Perf build support for -Wshorten-64-to-32 Ian Rogers
2025-04-01 18:22 ` [PATCH v1 01/48] perf build: Avoid building libbpf/bpftool with LIBBPF_DYNAMIC Ian Rogers
2025-04-01 18:23 ` [PATCH v1 02/48] tools headers: Silence -Wshorten-64-to-32 warnings Ian Rogers
2025-04-03 14:08 ` Yury Norov
2025-04-03 14:26 ` Yury Norov
2025-04-03 14:52 ` Ian Rogers
2025-04-03 15:23 ` Yury Norov
2025-04-03 15:45 ` Ian Rogers
2025-04-03 18:12 ` Ian Rogers
2025-04-03 18:18 ` Yury Norov
2025-04-03 18:25 ` Ian Rogers
2025-04-01 18:23 ` [PATCH v1 03/48] arm64: cputype: " Ian Rogers
2025-04-01 18:23 ` [PATCH v1 04/48] x86/insn: " Ian Rogers
2025-04-02 11:10 ` Eder Zulian
2025-04-01 18:23 ` [PATCH v1 05/48] tools lib: " Ian Rogers
2025-04-03 14:19 ` Yury Norov
2025-04-01 18:23 ` [PATCH v1 06/48] libperf: " Ian Rogers
2025-04-01 18:23 ` [PATCH v1 07/48] tools subcmd: " Ian Rogers
2025-04-01 18:23 ` [PATCH v1 08/48] perf bench: " Ian Rogers
2025-04-01 18:23 ` [PATCH v1 09/48] perf tests: " Ian Rogers
2025-04-02 14:35 ` Leo Yan
2025-04-02 15:42 ` Ian Rogers
2025-04-02 16:38 ` Leo Yan
2025-04-02 16:53 ` Ian Rogers
2025-04-03 4:53 ` Namhyung Kim
2025-04-03 15:20 ` Ian Rogers
2025-04-28 11:10 ` Leo Yan
2025-04-28 16:29 ` Ian Rogers
2025-04-29 9:53 ` Leo Yan
2025-04-02 22:01 ` David Laight
2025-04-02 22:32 ` Ian Rogers
2025-04-01 18:23 ` [PATCH v1 10/48] perf arch x86: " Ian Rogers
2025-04-01 18:23 ` [PATCH v1 11/48] perf arm-spe: " Ian Rogers
2025-04-01 18:23 ` [PATCH v1 12/48] perf trace: " Ian Rogers
2025-04-01 18:23 ` Ian Rogers [this message]
2025-04-01 18:23 ` [PATCH v1 14/48] perf jvmti: " Ian Rogers
2025-04-01 18:23 ` [PATCH v1 15/48] perf pmu: " Ian Rogers
2025-04-01 18:23 ` [PATCH v1 16/48] perf annotate powerpc: " Ian Rogers
2025-04-01 18:23 ` [PATCH v1 17/48] perf s390: " Ian Rogers
2025-04-01 18:23 ` [PATCH v1 18/48] perf cs-etm: " Ian Rogers
2025-04-01 18:23 ` [PATCH v1 19/48] perf stat: " Ian Rogers
2025-04-01 18:23 ` [PATCH v1 20/48] perf dlfilter: " Ian Rogers
2025-04-01 18:23 ` [PATCH v1 21/48] perf demangle: " Ian Rogers
2025-04-01 18:23 ` [PATCH v1 22/48] perf ui: " Ian Rogers
2025-04-01 18:23 ` [PATCH v1 23/48] perf annotate: " Ian Rogers
2025-04-01 18:23 ` [PATCH v1 24/48] perf report: " Ian Rogers
2025-04-01 18:23 ` [PATCH v1 25/48] perf help: " Ian Rogers
2025-04-01 18:23 ` [PATCH v1 26/48] perf hisi-ptt: " Ian Rogers
2025-04-01 18:23 ` [PATCH v1 27/48] perf probe: " Ian Rogers
2025-04-01 18:23 ` [PATCH v1 28/48] perf kwork: " Ian Rogers
2025-04-01 18:23 ` [PATCH v1 29/48] perf buildid: " Ian Rogers
2025-04-01 18:23 ` [PATCH v1 30/48] perf lock: " Ian Rogers
2025-04-01 18:23 ` [PATCH v1 31/48] perf mem: " Ian Rogers
2025-04-01 18:23 ` [PATCH v1 32/48] perf script: " Ian Rogers
2025-04-01 18:23 ` [PATCH v1 33/48] perf evlist: " Ian Rogers
2025-04-01 18:23 ` [PATCH v1 34/48] perf bpf_counter: " Ian Rogers
2025-04-01 18:23 ` [PATCH v1 35/48] perf ftrace: " Ian Rogers
2025-04-01 18:23 ` [PATCH v1 36/48] perf record: " Ian Rogers
2025-04-01 18:23 ` [PATCH v1 37/48] perf inject: " Ian Rogers
2025-04-01 18:23 ` [PATCH v1 38/48] perf sched: " Ian Rogers
2025-04-01 18:23 ` [PATCH v1 39/48] perf timechart: " Ian Rogers
2025-04-01 18:23 ` [PATCH v1 40/48] perf list: " Ian Rogers
2025-04-01 18:23 ` [PATCH v1 41/48] perf kvm: " Ian Rogers
2025-04-01 18:23 ` [PATCH v1 42/48] perf diff: " Ian Rogers
2025-04-01 18:23 ` [PATCH v1 43/48] perf daemon: " Ian Rogers
2025-04-01 18:23 ` [PATCH v1 44/48] perf zlib: " Ian Rogers
2025-04-01 18:23 ` [PATCH v1 45/48] perf symbol: " Ian Rogers
2025-04-01 18:23 ` [PATCH v1 46/48] perf util: " Ian Rogers
2025-04-01 18:23 ` [PATCH v1 47/48] perf hashmap: " Ian Rogers
2025-04-01 18:23 ` [PATCH v1 48/48] perf: " Ian Rogers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250401182347.3422199-14-irogers@google.com \
--to=irogers@google.com \
--cc=acme@kernel.org \
--cc=adityag@linux.ibm.com \
--cc=adrian.hunter@intel.com \
--cc=ak@linux.intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=algonell@gmail.com \
--cc=andrealmeid@igalia.com \
--cc=anshuman.khandual@arm.com \
--cc=arnd@arndb.de \
--cc=asmadeus@codewreck.org \
--cc=atrajeev@linux.vnet.ibm.com \
--cc=ben.gainey@arm.com \
--cc=bgeffon@google.com \
--cc=cachen@purestorage.com \
--cc=charlie@rivosinc.com \
--cc=christophe.leroy@csgroup.eu \
--cc=colin.i.king@gmail.com \
--cc=ctshao@google.com \
--cc=dapeng1.mi@linux.intel.com \
--cc=dave@stgolabs.net \
--cc=dirk@gouders.net \
--cc=dvhart@infradead.org \
--cc=dvyukov@google.com \
--cc=ezulian@redhat.com \
--cc=fzczx123@gmail.com \
--cc=gehao@kylinos.cn \
--cc=gmonaco@redhat.com \
--cc=graham.woodward@arm.com \
--cc=hejunhao3@huawei.com \
--cc=howardchu95@gmail.com \
--cc=ilkka@os.amperecomputing.com \
--cc=james.clark@linaro.org \
--cc=jannh@google.com \
--cc=jean-philippe.romain@foss.st.com \
--cc=john.g.garry@oracle.com \
--cc=jolsa@kernel.org \
--cc=jonathan.cameron@huawei.com \
--cc=jpoimboe@kernel.org \
--cc=justinstitt@google.com \
--cc=kan.liang@linux.intel.com \
--cc=kjain@linux.ibm.com \
--cc=krzysztof.m.lopatowski@gmail.com \
--cc=kyle.meyer@hpe.com \
--cc=leo.yan@linux.dev \
--cc=lihuafei1@huawei.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=linux@treblig.org \
--cc=llvm@lists.linux.dev \
--cc=mark.rutland@arm.com \
--cc=masahiroy@kernel.org \
--cc=mhiramat@kernel.org \
--cc=mike.leach@linaro.org \
--cc=mingo@redhat.com \
--cc=morbo@google.com \
--cc=namhyung@kernel.org \
--cc=nathan@kernel.org \
--cc=peterz@infradead.org \
--cc=quic_zhonhan@quicinc.com \
--cc=ravi.bangoria@amd.com \
--cc=scclevenger@os.amperecomputing.com \
--cc=sesse@google.com \
--cc=stephen.s.brennan@oracle.com \
--cc=tglx@linutronix.de \
--cc=thomas.falcon@intel.com \
--cc=tmricht@linux.ibm.com \
--cc=viro@zeniv.linux.org.uk \
--cc=visitorckw@gmail.com \
--cc=weilin.wang@intel.com \
--cc=will@kernel.org \
--cc=wutengda@huaweicloud.com \
--cc=xu.yang_2@nxp.com \
--cc=yangjihong@bytedance.com \
--cc=yangyicong@hisilicon.com \
--cc=yeoreum.yun@arm.com \
--cc=yujie.liu@intel.com \
--cc=yury.norov@gmail.com \
--cc=zhe.he@windriver.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox