Message ID | 20230612150424.198914-1-james.clark@arm.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2667708vqr; Mon, 12 Jun 2023 08:27:22 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4zTd/Og9Nk+efmdIx+BQK+Figq9QaDGXyv+RzqTOsUkx7/r896HT0vIdegLs36VMtfjD6g X-Received: by 2002:a19:760e:0:b0:4cc:96f8:f9c6 with SMTP id c14-20020a19760e000000b004cc96f8f9c6mr3483428lff.5.1686583641794; Mon, 12 Jun 2023 08:27:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686583641; cv=none; d=google.com; s=arc-20160816; b=EPjNGKioKvCpdoytutmmkA9ZMLKrWJ0/hFSdrAIw7Gn5FdAjnrInF1dus0Lcn4zzNU JbRs38RYbcxw1B+sjbWfwGYrmIZzFow2iv3B2Ek8BdmT0dwW3wtQNf4hl9AFGBAGHwWx vBVxU0Gzw/3tmn3yCTtVWJd8U2vY3881NNA83Cv78Mnefd9YdGmbwOkdcLsDjbx/iPAY pCDEzeNyWaU7XoV2OrVr0udRddSb4Rdz0+t2MWWaJIze0sGng+wtDDde8x11kEcrgFhx VfXb8xhMND2B7ZsUmiIo1ymTlt8S41bRQMvD069N0I5iXS0RJapvju/PWYIhFMdfQQO8 b7dQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=WTWZRup5sgpixESglHUJGHH75x1O+y5zSGRj95PRq5s=; b=n1+dY7yATo3c40jlidoe/YbKV0CESEvBw9Ig9LI6+i3mT5hVAefoJUAWzsViAZyfIc e65c4eA5ZkTc5pH16cre2kTLeA9ucyiPcCjDAaorzTocZHvVFRmXwRZh0YL+B/STmhyh 6qiYLHcryir7nDvAKvxgOo9KYSpAvmL75r4iE0kLA1o3GkHvJXDNL60ybo22tqlC9wsR rURgmtgq4dc1dZe/t1WjGDHD3pT2qejFc0lwWdnSy7N6+rGddSQcH++f94eYzAul0XDS 5kpi8eC2XMuvnYuonB3sQQNBIXKXwVv5Ehh3tec1nwqU1IPjMwGXmQmnkntmc/X8evaY VC4A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p15-20020a056402044f00b0051843062054si923200edw.66.2023.06.12.08.26.57; Mon, 12 Jun 2023 08:27:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239109AbjFLPF1 (ORCPT <rfc822;rust.linux@gmail.com> + 99 others); Mon, 12 Jun 2023 11:05:27 -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 <rfc822;linux-kernel@vger.kernel.org>); 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 <james.clark@arm.com> To: linux-perf-users@vger.kernel.org Cc: James Clark <james.clark@arm.com>, Peter Zijlstra <peterz@infradead.org>, Ingo Molnar <mingo@redhat.com>, Arnaldo Carvalho de Melo <acme@kernel.org>, Mark Rutland <mark.rutland@arm.com>, Alexander Shishkin <alexander.shishkin@linux.intel.com>, Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>, Ian Rogers <irogers@google.com>, Adrian Hunter <adrian.hunter@intel.com>, 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: 8bit X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768511128649173358?= X-GMAIL-MSGID: =?utf-8?q?1768511128649173358?= |
Series |
perf map: Fix refcount errors on Arm with -DREFCNT_CHECKING=1
|
|
Commit Message
James Clark
June 12, 2023, 3:04 p.m. UTC
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 <james.clark@arm.com>
---
tools/perf/util/symbol-elf.c | 9 +++++----
tools/perf/util/symbol.c | 9 +++++----
2 files changed, 10 insertions(+), 8 deletions(-)
Comments
On Mon, Jun 12, 2023 at 8:05 AM James Clark <james.clark@arm.com> wrote: > > 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 <james.clark@arm.com> Acked-by: Ian Rogers <irogers@google.com> > --- > 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 = *curr_dsop; > struct map *curr_map; > char dso_name[PATH_MAX]; > + struct map *map_ref; nit: can we narrow the scope of this by moving it to the scope where it is used. > > /* Adjust symbol to map to file offset */ > if (adjust_kernel_syms) > @@ -1390,10 +1391,10 @@ static int dso__process_kernel_symbol(struct dso *dso, struct map *map, > if (kmaps) { > int err; > > - map__get(map); > - maps__remove(kmaps, map); > - err = maps__insert(kmaps, map); > - map__put(map); > + map_ref = map__get(map); > + maps__remove(kmaps, map_ref); > + err = 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 map *map, > int err, fd; > char kcore_filename[PATH_MAX]; > u64 stext; > + struct map *map_ref; nit: can we narrow the scope of this by moving it to the scope where it is used. Thanks, Ian > > 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 = maps__insert(kmaps, map); > - map__put(map); > + map_ref = map__get(map); > + maps__remove(kmaps, map_ref); > + err = maps__insert(kmaps, map_ref); > + map__put(map_ref); > map__put(new_map); > if (err) > goto out_err; > -- > 2.34.1 >
Em Mon, Jun 12, 2023 at 09:32:30AM -0700, Ian Rogers escreveu: > On Mon, Jun 12, 2023 at 8:05 AM James Clark <james.clark@arm.com> wrote: > > > > 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 <james.clark@arm.com> > > Acked-by: Ian Rogers <irogers@google.com> > > > --- > > 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 = *curr_dsop; > > struct map *curr_map; > > char dso_name[PATH_MAX]; > > + struct map *map_ref; > > nit: can we narrow the scope of this by moving it to the scope where it is used. Which is what you did in a patch I already processed, its only in tmp.perf-tools-next as I was going thru the other patches, but this one is there already. I'm checking the tools/perf/util/symbol.c part. - Arnaldo > > > > /* Adjust symbol to map to file offset */ > > if (adjust_kernel_syms) > > @@ -1390,10 +1391,10 @@ static int dso__process_kernel_symbol(struct dso *dso, struct map *map, > > if (kmaps) { > > int err; > > > > - map__get(map); > > - maps__remove(kmaps, map); > > - err = maps__insert(kmaps, map); > > - map__put(map); > > + map_ref = map__get(map); > > + maps__remove(kmaps, map_ref); > > + err = 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 map *map, > > int err, fd; > > char kcore_filename[PATH_MAX]; > > u64 stext; > > + struct map *map_ref; > > nit: can we narrow the scope of this by moving it to the scope where it is used. > > Thanks, > Ian > > > > > 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 = maps__insert(kmaps, map); > > - map__put(map); > > + map_ref = map__get(map); > > + maps__remove(kmaps, map_ref); > > + err = maps__insert(kmaps, map_ref); > > + map__put(map_ref); > > map__put(new_map); > > if (err) > > goto out_err; > > -- > > 2.34.1 > >
Em Mon, Jun 12, 2023 at 02:29:42PM -0300, Arnaldo Carvalho de Melo escreveu: > Em Mon, Jun 12, 2023 at 09:32:30AM -0700, Ian Rogers escreveu: > > On Mon, Jun 12, 2023 at 8:05 AM James Clark <james.clark@arm.com> wrote: > > > > > > 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 <james.clark@arm.com> > > > > Acked-by: Ian Rogers <irogers@google.com> > > > > > --- > > > 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 = *curr_dsop; > > > struct map *curr_map; > > > char dso_name[PATH_MAX]; > > > + struct map *map_ref; > > > > nit: can we narrow the scope of this by moving it to the scope where it is used. > > Which is what you did in a patch I already processed, its only in > tmp.perf-tools-next as I was going thru the other patches, but this one > is there already. > > I'm checking the tools/perf/util/symbol.c part. I narrowed the scope and removed the symbol-elf.c part, end result: From 6fd34445b8c94aa7f519fb0b1ed45c7ef9f6cc4e Mon Sep 17 00:00:00 2001 From: James Clark <james.clark@arm.com> Date: Mon, 12 Jun 2023 16:04:24 +0100 Subject: [PATCH 1/1] perf map: Fix double 'struct map' reference free found with -DREFCNT_CHECKING=1 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. Committer notes: Narrowed the map_ref scope as suggested by Ian, removed the symbol-elf part as it was already fixed by another patch, from Ian. Signed-off-by: James Clark <james.clark@arm.com> Acked-by: Ian Rogers <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: https://lore.kernel.org/r/20230612150424.198914-1-james.clark@arm.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> --- tools/perf/util/symbol.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index 6b9c55784b56a4be..d275d3bef7d54a40 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c @@ -1458,16 +1458,18 @@ static int dso__load_kcore(struct dso *dso, struct map *map, list_del_init(&new_node->node); if (RC_CHK_ACCESS(new_map) == RC_CHK_ACCESS(replacement_map)) { + struct map *map_ref; + map__set_start(map, map__start(new_map)); map__set_end(map, map__end(new_map)); map__set_pgoff(map, map__pgoff(new_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 = maps__insert(kmaps, map); - map__put(map); + map_ref = map__get(map); + maps__remove(kmaps, map_ref); + err = maps__insert(kmaps, map_ref); + map__put(map_ref); map__put(new_map); if (err) goto out_err;
On Mon, Jun 12, 2023 at 10:40 AM Arnaldo Carvalho de Melo <acme@kernel.org> wrote: > > Em Mon, Jun 12, 2023 at 02:29:42PM -0300, Arnaldo Carvalho de Melo escreveu: > > Em Mon, Jun 12, 2023 at 09:32:30AM -0700, Ian Rogers escreveu: > > > On Mon, Jun 12, 2023 at 8:05 AM James Clark <james.clark@arm.com> wrote: > > > > > > > > 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 <james.clark@arm.com> > > > > > > Acked-by: Ian Rogers <irogers@google.com> > > > > > > > --- > > > > 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 = *curr_dsop; > > > > struct map *curr_map; > > > > char dso_name[PATH_MAX]; > > > > + struct map *map_ref; > > > > > > nit: can we narrow the scope of this by moving it to the scope where it is used. > > > > Which is what you did in a patch I already processed, its only in > > tmp.perf-tools-next as I was going thru the other patches, but this one > > is there already. > > > > I'm checking the tools/perf/util/symbol.c part. > > I narrowed the scope and removed the symbol-elf.c part, end result: > > From 6fd34445b8c94aa7f519fb0b1ed45c7ef9f6cc4e Mon Sep 17 00:00:00 2001 > From: James Clark <james.clark@arm.com> > Date: Mon, 12 Jun 2023 16:04:24 +0100 > Subject: [PATCH 1/1] perf map: Fix double 'struct map' reference free found > with -DREFCNT_CHECKING=1 > > 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. > > Committer notes: > > Narrowed the map_ref scope as suggested by Ian, removed the symbol-elf > part as it was already fixed by another patch, from Ian. > > Signed-off-by: James Clark <james.clark@arm.com> > Acked-by: Ian Rogers <irogers@google.com> > Cc: Adrian Hunter <adrian.hunter@intel.com> > Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> > Cc: Ingo Molnar <mingo@redhat.com> > Cc: Jiri Olsa <jolsa@kernel.org> > Cc: Mark Rutland <mark.rutland@arm.com> > Cc: Namhyung Kim <namhyung@kernel.org> > Cc: Peter Zijlstra <peterz@infradead.org> > Link: https://lore.kernel.org/r/20230612150424.198914-1-james.clark@arm.com > Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Thanks Arnaldo! I think we should be able to automate finding these issues with the warn_unused_result function attribute: ``` diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h index 66a87b3d9965..2c77c28ff000 100644 --- a/tools/perf/util/map.h +++ b/tools/perf/util/map.h @@ -172,7 +172,7 @@ struct map *map__new2(u64 start, struct dso *dso); void map__delete(struct map *map); struct map *map__clone(struct map *map); -static inline struct map *map__get(struct map *map) +__attribute__ ((warn_unused_result)) static inline struct map *map__get(struct map *map) { struct map *result; diff --git a/tools/perf/util/maps.h b/tools/perf/util/maps.h index 83144e0645ed..5b74465316dd 100644 --- a/tools/perf/util/maps.h +++ b/tools/perf/util/maps.h @@ -60,7 +60,7 @@ struct maps *maps__new(struct machine *machine); bool maps__empty(struct maps *maps); int maps__clone(struct thread *thread, struct maps *parent); -struct maps *maps__get(struct maps *maps); +struct maps *maps__get(struct maps *maps) __attribute__ ((warn_unused_result)); void maps__put(struct maps *maps); static inline void __maps__zput(struct maps **map) diff --git a/tools/perf/util/namespaces.h b/tools/perf/util/namespaces.h index 8c0731c6cbb7..04e1878b9551 100644 --- a/tools/perf/util/namespaces.h +++ b/tools/perf/util/namespaces.h @@ -50,7 +50,7 @@ int nsinfo__init(struct nsinfo *nsi); struct nsinfo *nsinfo__new(pid_t pid); struct nsinfo *nsinfo__copy(const struct nsinfo *nsi); -struct nsinfo *nsinfo__get(struct nsinfo *nsi); +struct nsinfo *nsinfo__get(struct nsinfo *nsi) __attribute__ ((warn_unused_result)); void nsinfo__put(struct nsinfo *nsi); bool nsinfo__need_setns(const struct nsinfo *nsi); diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h index 9068a21ce0fa..c6228252b093 100644 --- a/tools/perf/util/thread.h +++ b/tools/perf/util/thread.h @@ -71,7 +71,7 @@ struct thread *thread__new(pid_t pid, pid_t tid); irogers@irogers-glaptop0:~/kernel.org$ git diff diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h index 66a87b3d9965..2c77c28ff000 100644 --- a/tools/perf/util/map.h +++ b/tools/perf/util/map.h @@ -172,7 +172,7 @@ struct map *map__new2(u64 start, struct dso *dso); void map__delete(struct map *map); struct map *map__clone(struct map *map); -static inline struct map *map__get(struct map *map) +__attribute__ ((warn_unused_result)) static inline struct map *map__get(struct map *map) { struct map *result; diff --git a/tools/perf/util/maps.h b/tools/perf/util/maps.h index 83144e0645ed..5b74465316dd 100644 --- a/tools/perf/util/maps.h +++ b/tools/perf/util/maps.h @@ -60,7 +60,7 @@ struct maps *maps__new(struct machine *machine); bool maps__empty(struct maps *maps); int maps__clone(struct thread *thread, struct maps *parent); -struct maps *maps__get(struct maps *maps); +struct maps *maps__get(struct maps *maps) __attribute__ ((warn_unused_result)); void maps__put(struct maps *maps); static inline void __maps__zput(struct maps **map) diff --git a/tools/perf/util/namespaces.h b/tools/perf/util/namespaces.h index 8c0731c6cbb7..04e1878b9551 100644 --- a/tools/perf/util/namespaces.h +++ b/tools/perf/util/namespaces.h @@ -50,7 +50,7 @@ int nsinfo__init(struct nsinfo *nsi); struct nsinfo *nsinfo__new(pid_t pid); struct nsinfo *nsinfo__copy(const struct nsinfo *nsi); -struct nsinfo *nsinfo__get(struct nsinfo *nsi); +struct nsinfo *nsinfo__get(struct nsinfo *nsi) __attribute__ ((warn_unused_result)); void nsinfo__put(struct nsinfo *nsi); bool nsinfo__need_setns(const struct nsinfo *nsi); diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h index 9068a21ce0fa..c6228252b093 100644 --- a/tools/perf/util/thread.h +++ b/tools/perf/util/thread.h @@ -71,7 +71,7 @@ struct thread *thread__new(pid_t pid, pid_t tid); int thread__init_maps(struct thread *thread, struct machine *machine); void thread__delete(struct thread *thread); -struct thread *thread__get(struct thread *thread); +struct thread *thread__get(struct thread *thread) __attribute__ ((warn_unused_result)); void thread__put(struct thread *thread); static inline void __thread__zput(struct thread **thread) ``` This shows the problem like: ``` util/symbol.c: In function ‘dso__load_kcore’: util/symbol.c:1467:25: error: ignoring return value of ‘map__get’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result] 1467 | map__get(map); | ``` I double checked and the symbol.c issue was the only one in my build environment. Using warn_unused_result should be done via compiler.h which is a bit more than the patch above. Thanks, Ian > --- > tools/perf/util/symbol.c | 10 ++++++---- > 1 file changed, 6 insertions(+), 4 deletions(-) > > diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c > index 6b9c55784b56a4be..d275d3bef7d54a40 100644 > --- a/tools/perf/util/symbol.c > +++ b/tools/perf/util/symbol.c > @@ -1458,16 +1458,18 @@ static int dso__load_kcore(struct dso *dso, struct map *map, > list_del_init(&new_node->node); > > if (RC_CHK_ACCESS(new_map) == RC_CHK_ACCESS(replacement_map)) { > + struct map *map_ref; > + > map__set_start(map, map__start(new_map)); > map__set_end(map, map__end(new_map)); > map__set_pgoff(map, map__pgoff(new_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 = maps__insert(kmaps, map); > - map__put(map); > + map_ref = map__get(map); > + maps__remove(kmaps, map_ref); > + err = maps__insert(kmaps, map_ref); > + map__put(map_ref); > map__put(new_map); > if (err) > goto out_err; > -- > 2.37.1 >
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 = *curr_dsop; struct map *curr_map; char dso_name[PATH_MAX]; + struct map *map_ref; /* Adjust symbol to map to file offset */ if (adjust_kernel_syms) @@ -1390,10 +1391,10 @@ static int dso__process_kernel_symbol(struct dso *dso, struct map *map, if (kmaps) { int err; - map__get(map); - maps__remove(kmaps, map); - err = maps__insert(kmaps, map); - map__put(map); + map_ref = map__get(map); + maps__remove(kmaps, map_ref); + err = 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 map *map, int err, fd; char kcore_filename[PATH_MAX]; u64 stext; + struct map *map_ref; 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 = maps__insert(kmaps, map); - map__put(map); + map_ref = map__get(map); + maps__remove(kmaps, map_ref); + err = maps__insert(kmaps, map_ref); + map__put(map_ref); map__put(new_map); if (err) goto out_err;