From nobody Sat Feb 7 18:20:41 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8E240C7EE2E for ; Mon, 12 Jun 2023 15:05:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239245AbjFLPF2 (ORCPT ); Mon, 12 Jun 2023 11:05:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238250AbjFLPFZ (ORCPT ); Mon, 12 Jun 2023 11:05:25 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6B98019A; Mon, 12 Jun 2023 08:05:18 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E60F91FB; Mon, 12 Jun 2023 08:06:02 -0700 (PDT) Received: from e127643.broadband (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 7782A3F5A1; Mon, 12 Jun 2023 08:05:15 -0700 (PDT) From: James Clark To: linux-perf-users@vger.kernel.org Cc: James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , linux-kernel@vger.kernel.org Subject: [PATCH] perf map: Fix refcount errors on Arm with -DREFCNT_CHECKING=1 Date: Mon, 12 Jun 2023 16:04:24 +0100 Message-Id: <20230612150424.198914-1-james.clark@arm.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" When quitting after running a perf report, the refcount checker finds some double frees. The issue is that map__put() is called on a function argument so it removes the refcount wrapper that someone else was using. Fix it by only calling map__put() on a reference that is owned by this function. Signed-off-by: James Clark Acked-by: Ian Rogers --- tools/perf/util/symbol-elf.c | 9 +++++---- tools/perf/util/symbol.c | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c index 63882a4db5c7..ec0d7810bbb0 100644 --- a/tools/perf/util/symbol-elf.c +++ b/tools/perf/util/symbol-elf.c @@ -1365,6 +1365,7 @@ static int dso__process_kernel_symbol(struct dso *dso= , struct map *map, struct dso *curr_dso =3D *curr_dsop; struct map *curr_map; char dso_name[PATH_MAX]; + struct map *map_ref; =20 /* Adjust symbol to map to file offset */ if (adjust_kernel_syms) @@ -1390,10 +1391,10 @@ static int dso__process_kernel_symbol(struct dso *d= so, struct map *map, if (kmaps) { int err; =20 - map__get(map); - maps__remove(kmaps, map); - err =3D maps__insert(kmaps, map); - map__put(map); + map_ref =3D map__get(map); + maps__remove(kmaps, map_ref); + err =3D maps__insert(kmaps, map_ref); + map__put(map_ref); if (err) return err; } diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index 6b9c55784b56..b3034fd5c0af 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c @@ -1368,6 +1368,7 @@ static int dso__load_kcore(struct dso *dso, struct ma= p *map, int err, fd; char kcore_filename[PATH_MAX]; u64 stext; + struct map *map_ref; =20 if (!kmaps) return -EINVAL; @@ -1464,10 +1465,10 @@ static int dso__load_kcore(struct dso *dso, struct = map *map, map__set_map_ip(map, map__map_ip_ptr(new_map)); map__set_unmap_ip(map, map__unmap_ip_ptr(new_map)); /* Ensure maps are correctly ordered */ - map__get(map); - maps__remove(kmaps, map); - err =3D maps__insert(kmaps, map); - map__put(map); + map_ref =3D map__get(map); + maps__remove(kmaps, map_ref); + err =3D maps__insert(kmaps, map_ref); + map__put(map_ref); map__put(new_map); if (err) goto out_err; --=20 2.34.1