From nobody Mon Feb 9 09:57:47 2026 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.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 2042F222563 for ; Tue, 1 Apr 2025 18:25:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743531926; cv=none; b=djBbKj/PIQg+qCIhVtTe8CFGdYIvhHVID0IIV7pJDZfFR/ligmglLXBdCLC1ZS0WsCsEsbB6lQqzPTPC4yhng2fKlLcrbbiMiDSffV5EeG/4tbcHC26hDHwEXr9FxZC6C9taCuRPbciSQ82knNNvaXbyl9/rW0wtVFkENsVGBGs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743531926; c=relaxed/simple; bh=OHSwmVRTG0HD488JeBe67A2CUxy+O0gCaGl1hO/MrlY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=FLIz4EJJltrCfJGS215RtEYQAswAEz0FgkoMiVgVY8TzAoBFFWuo82vIz2XK5LR6P5+T3kpUuwDoYF9cP8BpwY7TLdoUjSOVAaoLa3DjFwHxxmUowRKrTDNcEoOZTPYqXaxfLZv2BQhMxaZU4tA5c6rKzb+9uMqUQQ6f6se2Yho= 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=NQY263Q6; arc=none smtp.client-ip=209.85.214.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="NQY263Q6" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-224347aef79so160799925ad.2 for ; Tue, 01 Apr 2025 11:25:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1743531925; x=1744136725; 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=maDKewcfrTN/pXEuAvy1eHGZYrBP9VzStu+Vbun6bP0=; b=NQY263Q65d5AL6toZSHGWyPlpTaDtDpetDP9vuRK6xNoRJrROMGG6q8xIMGbIso4ju apI5PaqdFHojayaPnq3u3s71t4Piih/+GIc1jIXxitfnGfIPXMW14ALBp6BmuNerUA8S gROtL+tpwXmJxubiuMX++xM/QED7U5Up+H60mPdqdVs+lJ1b09cw1QrMVNnT41kbmkwf cFS9yvKshmrDyZtd+526zrxjX+/LAJ9Js129qMJTbsoMctI1vEQ1BtQ2Un/v7fHCj0dQ 7dcAdSH+riYoLAiS6C9KS8OToVkMXEr52DHmJN4oo/jvelfvJxN1tkWr/I/AIYyd2d4o PfEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743531925; x=1744136725; 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=maDKewcfrTN/pXEuAvy1eHGZYrBP9VzStu+Vbun6bP0=; b=MHdBtwWIpTQ4lDUc93kMjSsXLurNNoZNBGs8khr2C0EtMbT+sZcuttjIdiiKvAqkg6 tLiMbmOk0rj7UTjvX4fVnsh+9dMZRTFQp7m/+FAiMI+OA1yco8xZKVRmCxE12378rpP5 ogMRQkyWL0OzHTR+McVTAGwT97TQ4sZ/874XFGIuRrcsnUuBEw3JPVulbLZIuEttZne5 4Kdk7+3dTDYn9MA+kg9KwKkzc5UX3GQmB6kfUsyEXtPzI1mWd6fTINuZvYrSc3VVuuBl 1stsU2gNNfht7lXC8jKbcdh2vWVtsRCjRqKAMJ/fM2M4tlvjVmDLwOzuoHR05jXBPw3Q P2CA== X-Forwarded-Encrypted: i=1; AJvYcCVgmQuJ78QRxFUowGOL+iIh0Jvj687EIQGTkgoWmkDHop1sADTZVlC3ZKcXrH+SApEAf5x0Rvs1yoSFNXQ=@vger.kernel.org X-Gm-Message-State: AOJu0YyM0YtEM0xb0hjYJtKuuO3kkbbkhPdHkxnkjvUDv/lmNdIVWu78 OO99QkKUPcwzngRQZYCt4uTj3GulGE2EjQHy4FWAZ1jIKFLxnCHt2KIJZ6ElgcS0d9x94gOQX1z gRBQsKQ== X-Google-Smtp-Source: AGHT+IFNI0r4xdlVep8eZmgL2ok0j2hkk8AtyWpy1qsBmfszW0qOT/+uO0dTUbBWJ2V47z6JGjdY7ibJE2zJ X-Received: from plpf4.prod.google.com ([2002:a17:903:3c44:b0:223:58e2:570d]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:ebc6:b0:224:c76:5e57 with SMTP id d9443c01a7336-2292f9e8652mr220203935ad.39.1743531924561; Tue, 01 Apr 2025 11:25:24 -0700 (PDT) Date: Tue, 1 Apr 2025 11:23:22 -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-25-irogers@google.com> Subject: [PATCH v1 24/48] perf report: 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/builtin-report.c | 4 ++-- tools/perf/util/callchain.c | 12 ++++++------ tools/perf/util/callchain.h | 2 +- tools/perf/util/srccode.c | 6 +++--- tools/perf/util/srcline.c | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index b030ce72e13e..fff8f3db788e 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -800,7 +800,7 @@ static int count_lost_samples_event(const struct perf_t= ool *tool, evsel =3D evlist__id2evsel(rep->session->evlist, sample->id); if (evsel) { struct hists *hists =3D evsel__hists(evsel); - u32 count =3D event->lost_samples.lost; + u32 count =3D (u32)event->lost_samples.lost; =20 if (event->header.misc & PERF_RECORD_MISC_LOST_SAMPLES_BPF) hists__inc_nr_dropped_samples(hists, count); @@ -1602,7 +1602,7 @@ int cmd_report(int argc, const char **argv) =20 session =3D perf_session__new(&data, &report.tool); if (IS_ERR(session)) { - ret =3D PTR_ERR(session); + ret =3D (int)PTR_ERR(session); goto exit; } =20 diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c index d7b7eef740b9..c3206b9d7b52 100644 --- a/tools/perf/util/callchain.c +++ b/tools/perf/util/callchain.c @@ -214,7 +214,7 @@ __parse_callchain_report_opt(const char *arg, bool allo= w_record_opt) =20 if (get_stack_size(tok, &size) < 0) return -1; - callchain_param.dump_size =3D size; + callchain_param.dump_size =3D (u32)size; try_stack_size =3D false; } else if (!minpcnt_set) { /* try to get the min percent */ @@ -224,7 +224,7 @@ __parse_callchain_report_opt(const char *arg, bool allo= w_record_opt) minpcnt_set =3D true; } else { /* try print limit at last */ - callchain_param.print_limit =3D strtoul(tok, &endptr, 0); + callchain_param.print_limit =3D (u32)strtoul(tok, &endptr, 0); if (tok =3D=3D endptr) return -1; } @@ -295,7 +295,7 @@ int parse_callchain_record(const char *arg, struct call= chain_param *param) unsigned long size =3D 0; =20 ret =3D get_stack_size(tok, &size); - param->dump_size =3D size; + param->dump_size =3D (u32)size; } } else if (!strncmp(name, "lbr", sizeof("lbr"))) { if (!strtok_r(NULL, ",", &saveptr)) { @@ -332,7 +332,7 @@ int perf_callchain_config(const char *var, const char *= value) int ret; =20 ret =3D get_stack_size(value, &size); - callchain_param.dump_size =3D size; + callchain_param.dump_size =3D (u32)size; =20 return ret; } @@ -817,7 +817,7 @@ split_add_child(struct callchain_node *parent, { struct callchain_node *new; struct list_head *old_tail; - unsigned int idx_total =3D idx_parents + idx_local; + u64 idx_total =3D idx_parents + idx_local; =20 /* split */ new =3D create_child(parent, true); @@ -1027,7 +1027,7 @@ merge_chain_branch(struct callchain_cursor *cursor, struct callchain_node *child; struct callchain_list *list, *next_list; struct rb_node *n; - int old_pos =3D cursor->nr; + u64 old_pos =3D cursor->nr; int err =3D 0; =20 list_for_each_entry_safe(list, next_list, &src->val, list) { diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h index 86ed9e4d04f9..7a2abff6d0a5 100644 --- a/tools/perf/util/callchain.h +++ b/tools/perf/util/callchain.h @@ -65,7 +65,7 @@ struct callchain_node { struct rb_node rb_node; /* to sort nodes in an output tree */ struct rb_root rb_root_in; /* input tree of children */ struct rb_root rb_root; /* sorted output tree of children */ - unsigned int val_nr; + u64 val_nr; unsigned int count; unsigned int children_count; u64 hit; diff --git a/tools/perf/util/srccode.c b/tools/perf/util/srccode.c index 476e99896d5e..f5f8cdfd00c1 100644 --- a/tools/perf/util/srccode.c +++ b/tools/perf/util/srccode.c @@ -37,7 +37,7 @@ static LIST_HEAD(srcfile_list); static long map_total_sz; static int num_srcfiles; =20 -static int countlines(char *map, int maplen) +static int countlines(char *map, size_t maplen) { int numl; char *end =3D map + maplen; @@ -136,7 +136,7 @@ static struct srcfile *find_srcfile(char *fn) h->lines =3D calloc(h->numlines, sizeof(char *)); if (!h->lines) goto out_map; - fill_lines(h->lines, h->numlines, h->map, h->maplen); + fill_lines(h->lines, h->numlines, h->map, (int)h->maplen); list_add(&h->nd, &srcfile_list); hlist_add_head(&h->hash_nd, &srcfile_htab[hval]); map_total_sz +=3D h->maplen; @@ -166,6 +166,6 @@ char *find_sourceline(char *fn, unsigned line, int *len= p) if (!l) return NULL; p =3D memchr(l, '\n', sf->map + sf->maplen - l); - *lenp =3D p - l; + *lenp =3D (int)(p - l); return l; } diff --git a/tools/perf/util/srcline.c b/tools/perf/util/srcline.c index f32d0d4f4bc9..b2003c5490a2 100644 --- a/tools/perf/util/srcline.c +++ b/tools/perf/util/srcline.c @@ -443,7 +443,7 @@ static int filename_split(char *filename, unsigned int = *line_nr) sep =3D strchr(filename, ':'); if (sep) { *sep++ =3D '\0'; - *line_nr =3D strtoul(sep, NULL, 0); + *line_nr =3D (unsigned int)strtoul(sep, NULL, 0); return 1; } pr_debug("addr2line missing ':' in filename split\n"); --=20 2.49.0.504.g3bcea36a83-goog