From nobody Mon Feb 9 20:43:14 2026 Received: from mail-oa1-f74.google.com (mail-oa1-f74.google.com [209.85.160.74]) (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 580E62206B8 for ; Tue, 1 Apr 2025 18:25:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743531910; cv=none; b=EqWJStAVSsyWaoYpc7IwImESmGk8bgIECM9cfORjDIAJviDqvzhEpc26GUV5wRTdw5LiwXSSoZg5QoF0fUjaZsizkwTX5R+sqze5HdpOy1uCwnSN81TRksEniS21W31GGohgs2tzA5tPWUmXijr0m+DQmDS/ZXS4dQVFHUt4TYQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743531910; c=relaxed/simple; bh=LJ5bCbL+1daj73vhuubS5IIoYg4jtmiDU7rvTqttR9Q=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=eqUmgqIau0EKTCVt3sDfKCtT6h53iuEN4icQXy+UAwchyxl9FHyZKFConM7g8DyYtq6rOZ1WGj2qldCmHrx71EK4IVhHSJ482EoJSFJ/88ao5JSFRiiMqrDSHloZ4fvBNRgA72XuRJQ3SFBUL3LvsMnSmoPA3Lpje6B+hrUSb94= 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=Ee1gaJVF; arc=none smtp.client-ip=209.85.160.74 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="Ee1gaJVF" Received: by mail-oa1-f74.google.com with SMTP id 586e51a60fabf-2c8786a89d3so1239084fac.0 for ; Tue, 01 Apr 2025 11:25:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1743531907; x=1744136707; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=Da5DUiJVSsEnsA3gzfAHXUpLTR3Ufuk1FvHZfSFlCg4=; b=Ee1gaJVF00LEQ6hDSsNMINNiE9yL7LSeT9izMBg/ST1mSddj4XsNBnkPsBfP5rbIT+ DW9I/XnOi8ZnRgMro8xUyxDtJmNk2zPx0WMvDlFpPqfW9qx+kkwLCwJ8G0K7Ax2DxhRx YdpTzyq3Xbt8VC+KaymsiJgT+U2aVA8jBjlIyG/bPICLP3TNP/XXXx536YrTaIOQ7vdF a/D8pdpdyLiyEW7+OMyYk2lo1rHcGca+S69xgb1NOvDXfNsz21m3HDsiMlL3fub634R2 QsGiubqsgglNohJCBKDNbQZB1MP1COP1Jgzkos7hT4ZmFSq/ROAmmuhuPoSgHyVMCY6K wqZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743531907; x=1744136707; h=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=Da5DUiJVSsEnsA3gzfAHXUpLTR3Ufuk1FvHZfSFlCg4=; b=se2gMlM2pdqeOkLI05QgG6ok5s9PzGJ6R/fl1tCXyMVE2Dn1jaiizV7g0hbt/l6rUE QY4XUpuJa8jx5TCRgka13ZHl1ntNozai3QdmpF1qqFiRcUzf/odejIDrIeQQChvTXf+9 jFFKb2ktKXwB1JqbnKWTWyZ+LGJntM2EUS+uSyyXv0Ccfjx6/ne99yOQ1r8ubEMsjbOx 5Ntqa/YOXNrZaeWme8/RTewxV0Glo4PIKlqkMplddXD2UTNhfxst8WDEVG9HcXTGgszr mz17u0FudwI41H7HF6FPFfS1uoec2Yaq80fU7xOrx3ekh6Tg0R2zFOgtw8lSnGXJ38My R99Q== X-Forwarded-Encrypted: i=1; AJvYcCXRqY3SPHdFUVG1ew6izL0HeaPgJjzBOF1P3zfcdhnyG05L8lEnkcXWhTYtcUIlnqTDJEgk5Kn5JEx36Rw=@vger.kernel.org X-Gm-Message-State: AOJu0Ywn1fBt/tutJQESXVoJhDzRbqWv2IK2HrwqOY544qR5ZZPucrrl xMh+Pnuv9zDrXKazZyEBIh9P0EOqMqZrhE21BWIKn7b6zKH/uEyIbG3RMJZEv5AdPYGeiXN8gK3 USBfoiQ== X-Google-Smtp-Source: AGHT+IHEwV4zAtKk0PBs2gzq5sOI+YyZoow9R1UWlEQXJU1TorP5CNFdlUvUeobymJBu8Fg99nd3p4RriyMG X-Received: from oabsc17.prod.google.com ([2002:a05:6871:2211:b0:2c1:665d:545e]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6871:3a0b:b0:29e:5897:e9d1 with SMTP id 586e51a60fabf-2cbcf825a7emr7646545fac.39.1743531907119; Tue, 01 Apr 2025 11:25:07 -0700 (PDT) Date: Tue, 1 Apr 2025 11:23:13 -0700 In-Reply-To: <20250401182347.3422199-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250401182347.3422199-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.504.g3bcea36a83-goog Message-ID: <20250401182347.3422199-16-irogers@google.com> Subject: [PATCH v1 15/48] perf pmu: Silence -Wshorten-64-to-32 warnings From: Ian Rogers To: Yury Norov , Rasmus Villemoes , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , 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 Content-Transfer-Encoding: quoted-printable 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/hwmon_pmu.c | 8 ++++---- tools/perf/util/pmu.c | 9 ++++----- tools/perf/util/pmus.c | 16 ++++++++-------- tools/perf/util/tool_pmu.c | 2 +- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/tools/perf/util/hwmon_pmu.c b/tools/perf/util/hwmon_pmu.c index 3cce77fc8004..6245eeb593c9 100644 --- a/tools/perf/util/hwmon_pmu.c +++ b/tools/perf/util/hwmon_pmu.c @@ -170,7 +170,7 @@ bool parse_hwmon_filename(const char *filename, for (size_t i =3D 0; fn_type[i] !=3D '\0'; i++) { if (fn_type[i] >=3D '0' && fn_type[i] <=3D '9') { fn_type[i] =3D '\0'; - *number =3D strtoul(&filename[i], (char **)&fn_item, 10); + *number =3D (int)strtoul(&filename[i], (char **)&fn_item, 10); if (*fn_item =3D=3D '_') fn_item++; break; @@ -194,7 +194,7 @@ bool parse_hwmon_filename(const char *filename, return false; } =20 - *type =3D elem - &hwmon_type_strs[0]; + *type =3D (enum hwmon_type)(elem - &hwmon_type_strs[0]); if (!item) return true; =20 @@ -213,7 +213,7 @@ bool parse_hwmon_filename(const char *filename, fn_item, filename); return false; } - *item =3D elem - &hwmon_item_strs[0]; + *item =3D (enum hwmon_item)(elem - &hwmon_item_strs[0]); return true; } =20 @@ -352,7 +352,7 @@ struct perf_pmu *hwmon_pmu__new(struct list_head *pmus,= int hwmon_dir, const cha return NULL; =20 hwm->hwmon_dir_fd =3D hwmon_dir; - hwm->pmu.type =3D PERF_PMU_TYPE_HWMON_START + strtoul(sysfs_name + 5, NUL= L, 10); + hwm->pmu.type =3D PERF_PMU_TYPE_HWMON_START + (int)strtoul(sysfs_name + 5= , NULL, 10); if (hwm->pmu.type > PERF_PMU_TYPE_HWMON_END) { pr_err("Unable to encode hwmon type from %s in valid PMU type\n", sysfs_= name); goto err_out; diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index b7ebac5ab1d1..5a940bf004fb 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1269,7 +1269,7 @@ __u64 perf_pmu__format_bits(struct perf_pmu *pmu, con= st char *name) { struct perf_pmu_format *format =3D pmu_find_format(&pmu->format, name); __u64 bits =3D 0; - int fbit; + size_t fbit; =20 if (!format) return 0; @@ -1314,9 +1314,8 @@ static void pmu_format_value(unsigned long *format, _= _u64 value, __u64 *v, =20 static __u64 pmu_format_max_value(const unsigned long *format) { - int w; + size_t w =3D bitmap_weight(format, PERF_PMU_FORMAT_BITS); =20 - w =3D bitmap_weight(format, PERF_PMU_FORMAT_BITS); if (!w) return 0; if (w < 64) @@ -1824,7 +1823,7 @@ int perf_pmu__for_each_format(struct perf_pmu *pmu, v= oid *state, pmu_format_call if (!pmu->is_core) return 0; =20 - for (size_t i =3D 0; i < ARRAY_SIZE(terms); i++) { + for (int i =3D 0; i < (int)ARRAY_SIZE(terms); i++) { int config =3D PERF_PMU_FORMAT_VALUE_CONFIG; =20 if (i < PERF_PMU_FORMAT_VALUE_CONFIG_END) @@ -2281,7 +2280,7 @@ static void perf_pmu__compute_config_masks(struct per= f_pmu *pmu) return; =20 list_for_each_entry(format, &pmu->format, list) { - unsigned int i; + size_t i; __u64 *mask; =20 if (format->value >=3D PERF_PMU_FORMAT_VALUE_CONFIG_END) diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c index b99292de7669..0b9071219376 100644 --- a/tools/perf/util/pmus.c +++ b/tools/perf/util/pmus.c @@ -59,7 +59,7 @@ static void pmu_read_sysfs(unsigned int to_read_pmus); =20 size_t pmu_name_len_no_suffix(const char *str) { - int orig_len, len; + size_t orig_len, len; bool has_hex_digits =3D false; =20 orig_len =3D len =3D strlen(str); @@ -353,7 +353,7 @@ struct perf_pmu *perf_pmus__scan_core(struct perf_pmu *= pmu) static struct perf_pmu *perf_pmus__scan_skip_duplicates(struct perf_pmu *p= mu) { bool use_core_pmus =3D !pmu || pmu->is_core; - int last_pmu_name_len =3D 0; + size_t last_pmu_name_len =3D 0; const char *last_pmu_name =3D (pmu && pmu->name) ? pmu->name : ""; =20 if (!pmu) { @@ -364,7 +364,7 @@ static struct perf_pmu *perf_pmus__scan_skip_duplicates= (struct perf_pmu *pmu) =20 if (use_core_pmus) { list_for_each_entry_continue(pmu, &core_pmus, list) { - int pmu_name_len =3D pmu_name_len_no_suffix(pmu->name ?: ""); + size_t pmu_name_len =3D pmu_name_len_no_suffix(pmu->name ?: ""); =20 if (last_pmu_name_len =3D=3D pmu_name_len && !strncmp(last_pmu_name, pmu->name ?: "", pmu_name_len)) @@ -376,7 +376,7 @@ static struct perf_pmu *perf_pmus__scan_skip_duplicates= (struct perf_pmu *pmu) pmu =3D list_prepare_entry(pmu, &other_pmus, list); } list_for_each_entry_continue(pmu, &other_pmus, list) { - int pmu_name_len =3D pmu_name_len_no_suffix(pmu->name ?: ""); + size_t pmu_name_len =3D pmu_name_len_no_suffix(pmu->name ?: ""); =20 if (last_pmu_name_len =3D=3D pmu_name_len && !strncmp(last_pmu_name, pmu->name ?: "", pmu_name_len)) @@ -581,7 +581,7 @@ static int build_format_string(void *state, const char = *name, int config, const unsigned long *bits) { struct build_format_string_args *args =3D state; - unsigned int num_bits; + size_t num_bits; int ret1, ret2 =3D 0; =20 (void)config; @@ -631,14 +631,14 @@ void perf_pmus__print_raw_pmu_events(const struct pri= nt_callbacks *print_cb, voi .long_string =3D STRBUF_INIT, .num_formats =3D 0, }; - int len =3D pmu_name_len_no_suffix(pmu->name); + size_t len =3D pmu_name_len_no_suffix(pmu->name); const char *desc =3D "(see 'man perf-list' or 'man perf-record' on how t= o encode it)"; =20 if (!pmu->is_core) desc =3D NULL; =20 - strbuf_addf(&format_args.short_string, "%.*s/", len, pmu->name); - strbuf_addf(&format_args.long_string, "%.*s/", len, pmu->name); + strbuf_addf(&format_args.short_string, "%.*s/", (int)len, pmu->name); + strbuf_addf(&format_args.long_string, "%.*s/", (int)len, pmu->name); perf_pmu__for_each_format(pmu, &format_args, build_format_string); =20 if (format_args.num_formats > 3) diff --git a/tools/perf/util/tool_pmu.c b/tools/perf/util/tool_pmu.c index 97b327d1ce4a..155eea8a0a49 100644 --- a/tools/perf/util/tool_pmu.c +++ b/tools/perf/util/tool_pmu.c @@ -103,7 +103,7 @@ enum tool_pmu_event evsel__tool_event(const struct evse= l *evsel) =20 const char *evsel__tool_pmu_event_name(const struct evsel *evsel) { - return tool_pmu__event_to_str(evsel->core.attr.config); + return tool_pmu__event_to_str((enum tool_pmu_event)evsel->core.attr.confi= g); } =20 static bool read_until_char(struct io *io, char e) --=20 2.49.0.504.g3bcea36a83-goog