From: Markus Elfring <Markus.Elfring@web.de>
To: kernel-janitors@vger.kernel.org,
linux-perf-users@vger.kernel.org,
Adrian Hunter <adrian.hunter@intel.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Ian Rogers <irogers@google.com>, Ingo Molnar <mingo@redhat.com>,
James Clark <james.clark@arm.com>, Jiri Olsa <jolsa@kernel.org>,
Kan Liang <kan.liang@linux.intel.com>,
Leo Yan <leo.yan@linaro.org>, Mark Rutland <mark.rutland@arm.com>,
Namhyung Kim <namhyung@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Suzuki Poulouse <suzuki.poulose@arm.com>
Cc: cocci@inria.fr, LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH RESEND] perf cputopo: Improve exception handling in build_cpu_topology()
Date: Tue, 4 Mar 2025 10:50:35 +0100 [thread overview]
Message-ID: <c69c79e4-04a3-4182-a694-809a5fa36083@web.de> (raw)
In-Reply-To: <b1c70348-6459-474e-6a0f-d956423368d5@web.de>
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 23 Mar 2023 22:00:07 +0100
The label “done” was used to jump to another pointer check despite of
the detail in the implementation of the function “build_cpu_topology”
that it was determined already that a corresponding variable contained
a null pointer because of a failed call of the function “fopen”.
1. Thus use more appropriate labels instead.
2. Reorder jump targets at the end.
3. Delete a redundant check.
This issue was detected by using the Coccinelle software.
Fixes: 5135d5efcbb4 ("perf tools: Add cpu_topology object")
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
tools/perf/util/cputopo.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/tools/perf/util/cputopo.c b/tools/perf/util/cputopo.c
index e08797c3cdbc..fd185951ee2c 100644
--- a/tools/perf/util/cputopo.c
+++ b/tools/perf/util/cputopo.c
@@ -112,10 +112,10 @@ static int build_cpu_topology(struct cpu_topology *tp, int cpu)
}
fp = fopen(filename, "r");
if (!fp)
- goto done;
+ goto exit;
if (getline(&buf, &len, fp) <= 0)
- goto done;
+ goto close_file;
p = strchr(buf, '\n');
if (p)
@@ -131,10 +131,10 @@ static int build_cpu_topology(struct cpu_topology *tp, int cpu)
buf = NULL;
}
ret = 0;
-done:
- if (fp)
- fclose(fp);
free(buf);
+close_file:
+ fclose(fp);
+exit:
return ret;
}
--
2.40.0
prev parent reply other threads:[~2025-03-04 9:50 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <f9303bdc-b1a7-be5e-56c6-dfa8232b8b55@web.de>
[not found] ` <ab860edf-79ca-2035-c5a3-d25be6fd9dac@web.de>
[not found] ` <3a35fb28-5937-72f8-b2e8-b1d9899b5e43@web.de>
2023-03-27 9:11 ` [PATCH resent] perf/x86/amd/uncore: Fix exception handling in amd_uncore_cpu_up_prepare() Adrian Hunter
2023-03-27 14:58 ` Peter Zijlstra
[not found] ` <b1c70348-6459-474e-6a0f-d956423368d5@web.de>
2025-03-04 9:50 ` Markus Elfring [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c69c79e4-04a3-4182-a694-809a5fa36083@web.de \
--to=markus.elfring@web.de \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=cocci@inria.fr \
--cc=irogers@google.com \
--cc=james.clark@arm.com \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=leo.yan@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=suzuki.poulose@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).