From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 36BB729290C for ; Wed, 30 Apr 2025 17:51:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746035512; cv=none; b=AVkn/grgFneZmnOCiRGJ+XeVFkxq3NzV36M8ezPsVmctN8E4+NTwBdYxKJ7FntBlbUbFbDnKXkn3k2rDreFqrgAbW8lQsxNTcYYUqY0Z9YYFKfsCYtpazVZEVuXylPchnlZcVlSeKcQYhdx2GqgVI2dRJvlP2pDcpoVmvZsBUt0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746035512; c=relaxed/simple; bh=fQPKb2tvExN0lDvsWfwtFVM9KmnDm0fiUGU2uLUv3bU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=SRvJJ04inL0yDRXSh9Mtp9+QubeZvRI4A4xCNRUATdzLxrdAXlHG82H92ICZ7ehbiYOuuivb/DO3AGsgKJrtxO3jWv2dCZGaHezyAvnDhoxMkk6dKingphM8I4XrCCDf94hhDPeSbPcocZgLd1UAa8kla8sD2vXc8MYrmF3nT6o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=2s5IQzIs; arc=none smtp.client-ip=209.85.210.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="2s5IQzIs" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-7370e73f690so168264b3a.3 for ; Wed, 30 Apr 2025 10:51:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1746035509; x=1746640309; darn=lists.linux.dev; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=JCXEeH2++brLGuPtaI9HX8GOKQIfJPPTyPL2HMhADPg=; b=2s5IQzIs+4Jd/whVgnkQwEVcv6E3kF8CgcMAgjG8bE8iIsEt2JRRNk2NwhAtezU6Zf klTLjP7J9KIj1lNkgrLoerS3qVo6x/1jlsIxZ+bscL/EkeaizoqQdya0oTIo15Jn0QY/ fAjDmbruwLS8EdWnilCQo4nOj1JHPy+dC3cWry/W34n8/8qxD80kKH0WR9yWsPgcokrs WN0NM2kygzlZql+yJzFBPNTjy12Mk63KDxf+FeFEqAZeQrn9UPhnNvXNpuUBrmiJLB9K J6ZdlhjyGD3oXH93bAow4Sgd/SCqEcTaeDFRQvY5F/dNfrDGdyOfRSldD6KPR2ESg3Jc BXWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746035509; x=1746640309; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=JCXEeH2++brLGuPtaI9HX8GOKQIfJPPTyPL2HMhADPg=; b=h2CRjQ3kJSdV1NAzj5wvYzzHna1UOE+OQhOwwp+8amo9gpIYuSLLZoQrrshcBODWal Bj9RnlDz0RRsik/67RvPVKj+Evab/+AJ6T1PPzVpPOpba3com7WtM6mEx0gJlF7j1IUt 3bN1TMY+hA4u8tJ+kgWlUi6KHAZXbd/oLzCXJfMNDocR5NT0E/UHJm9FV0LDAVICU2Nc fUEIV1NV+sKKF5gXX7xI+pvwFn3vD25M0bfMNHVmPfHxkGyp2/HN9ntPDlJr6YZqjGvx kT5wQRgORk/tDv/npRN0bIuNnzSsusEQc4l0NkcpE9HJqZ7/IlQs9mfw9GKSVcShEWEP WLOg== X-Forwarded-Encrypted: i=1; AJvYcCVgZm+n81Hk23DXe3tY05/XWJ/KHDXx1l5WP8JuaAeU0h1q7p1/Tv4/4gJZoHf6u9AOZjQA@lists.linux.dev X-Gm-Message-State: AOJu0YxpH3xiPkx3jMiY090vg7BoiXqVCdISMWMcY66nxMbp8lZztLVY 6nidQPFijNDQQCivqppOipzQwGmXi9Gsk9YlO3yIBeAYtPO/lCtxz2gC9kdsTAJeSHTt7XNV/fr oISQHcA== X-Google-Smtp-Source: AGHT+IEfUWrcjNsU0ffRE3xfCfQBJUVEGiO9SdsAEQnnMSUi7Qwz6JGDA0vDAX4/+G9g5F2zB5NK4DSVmE8v X-Received: from pgcv17.prod.google.com ([2002:a05:6a02:5311:b0:af0:e359:c50a]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:3292:b0:1f5:8eec:e517 with SMTP id adf61e73a8af0-20ba6a18158mr146417637.9.1746035509372; Wed, 30 Apr 2025 10:51:49 -0700 (PDT) Date: Wed, 30 Apr 2025 10:50:14 -0700 In-Reply-To: <20250430175036.184610-1-irogers@google.com> Precedence: bulk X-Mailing-List: llvm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250430175036.184610-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.906.g1f30a19c02-goog Message-ID: <20250430175036.184610-27-irogers@google.com> Subject: [PATCH v2 26/47] perf probe: Silence -Wshorten-64-to-32 warnings From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , Kan Liang , Yury Norov , Rasmus Villemoes , Thomas Gleixner , Darren Hart , Davidlohr Bueso , "=?UTF-8?q?Andr=C3=A9=20Almeida?=" , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Yicong Yang , Jonathan Cameron , Nathan Chancellor , Bill Wendling , Justin Stitt , Josh Poimboeuf , Al Viro , Kyle Meyer , Ben Gainey , Athira Rajeev , Kajol Jain , Aditya Gupta , Eder Zulian , Dapeng Mi , Kuan-Wei Chiu , He Zhe , Dirk Gouders , Brian Geffon , Ravi Bangoria , Howard Chu , Charlie Jenkins , Colin Ian King , Dominique Martinet , Jann Horn , Masahiro Yamada , Arnd Bergmann , Yang Jihong , Dmitry Vyukov , Andi Kleen , Graham Woodward , Ilkka Koskinen , Anshuman Khandual , Zhongqiu Han , Hao Ge , Tengda Wu , Gabriele Monaco , Chun-Tse Shao , Casey Chen , "Dr. David Alan Gilbert" , Li Huafei , "Steinar H. Gunderson" , Levi Yun , Weilin Wang , Thomas Falcon , Thomas Richter , Andrew Kreimer , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , Christophe Leroy , Jean-Philippe Romain , Junhao He , "Masami Hiramatsu (Google)" , Xu Yang , Steve Clevenger , Zixian Cai , Stephen Brennan , Yujie Liu , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org, llvm@lists.linux.dev Cc: Ian Rogers Content-Type: text/plain; charset="UTF-8" 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 --- tools/perf/util/probe-event.c | 13 +++++++------ tools/perf/util/probe-file.c | 12 +++++++----- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index 307ad6242a4e..55bc68e5bd97 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c @@ -1336,7 +1336,7 @@ static int parse_line_num(char **ptr, int *val, const char *what) const char *start = *ptr; errno = 0; - *val = strtol(*ptr, ptr, 0); + *val = (int)strtol(*ptr, ptr, 0); if (errno || *ptr == start) { semantic_error("'%s' is not a valid number.\n", what); return -EINVAL; @@ -1620,7 +1620,7 @@ static int parse_perf_probe_point(char *arg, struct perf_probe_event *pev) } switch (c) { case ':': /* Line number */ - pp->line = strtoul(arg, &tmp, 0); + pp->line = (int)strtoul(arg, &tmp, 0); if (*tmp != '\0') { semantic_error("There is non-digit char" " in line number.\n"); @@ -2065,8 +2065,8 @@ char *synthesize_perf_probe_arg(struct perf_probe_arg *pa) static char *synthesize_perf_probe_point(struct perf_probe_point *pp) { struct strbuf buf; - char *tmp, *ret = NULL; - int len, err = 0; + char *ret = NULL; + int err = 0; if (strbuf_init(&buf, 64) < 0) return NULL; @@ -2084,8 +2084,9 @@ static char *synthesize_perf_probe_point(struct perf_probe_point *pp) goto out; } if (pp->file) { - tmp = pp->file; - len = strlen(tmp); + char *tmp = pp->file; + size_t len = strlen(tmp); + if (len > 30) { tmp = strchr(pp->file + len - 30, '/'); tmp = tmp ? tmp + 1 : pp->file + len - 30; diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c index ec8ac242fedb..2d84002710f3 100644 --- a/tools/perf/util/probe-file.c +++ b/tools/perf/util/probe-file.c @@ -167,7 +167,7 @@ int probe_file__open_both(int *kfd, int *ufd, int flag) /* Get raw string list of current kprobe_events or uprobe_events */ struct strlist *probe_file__get_rawlist(int fd) { - int ret, idx, fddup; + int ret, fddup; FILE *fp; char buf[MAX_CMDLEN]; char *p; @@ -189,6 +189,8 @@ struct strlist *probe_file__get_rawlist(int fd) goto out_close_fddup; while (!feof(fp)) { + size_t idx; + p = fgets(buf, MAX_CMDLEN, fp); if (!p) break; @@ -307,7 +309,7 @@ static int __del_trace_probe_event(int fd, struct str_node *ent) *p = '/'; pr_debug("Writing event: %s\n", buf); - ret = write(fd, buf, strlen(buf)); + ret = (int)write(fd, buf, strlen(buf)); if (ret < 0) { ret = -errno; goto error; @@ -962,7 +964,7 @@ static int probe_cache_entry__write(struct probe_cache_entry *entry, int fd) iov[0].iov_base = (void *)prefix; iov[0].iov_len = 1; iov[1].iov_base = entry->spev; iov[1].iov_len = strlen(entry->spev); iov[2].iov_base = (void *)"\n"; iov[2].iov_len = 1; - ret = writev(fd, iov, 3); + ret = (int)writev(fd, iov, 3); if (ret < (int)iov[1].iov_len + 2) goto rollback; @@ -970,7 +972,7 @@ static int probe_cache_entry__write(struct probe_cache_entry *entry, int fd) iov[0].iov_base = (void *)snode->s; iov[0].iov_len = strlen(snode->s); iov[1].iov_base = (void *)"\n"; iov[1].iov_len = 1; - ret = writev(fd, iov, 2); + ret = (int)writev(fd, iov, 2); if (ret < (int)iov[0].iov_len + 1) goto rollback; } @@ -992,7 +994,7 @@ int probe_cache__commit(struct probe_cache *pcache) int ret = 0; /* TBD: if we do not update existing entries, skip it */ - ret = lseek(pcache->fd, 0, SEEK_SET); + ret = (int)lseek(pcache->fd, 0, SEEK_SET); if (ret < 0) goto out; -- 2.49.0.906.g1f30a19c02-goog