lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20220902021122.18142-1-shangxiaojing@huawei.com>
Date:   Fri, 2 Sep 2022 10:11:22 +0800
From:   Shang XiaoJing <shangxiaojing@...wei.com>
To:     <peterz@...radead.org>, <mingo@...hat.com>, <acme@...nel.org>,
        <mark.rutland@....com>, <alexander.shishkin@...ux.intel.com>,
        <jolsa@...nel.org>, <namhyung@...nel.org>,
        <linux-perf-users@...r.kernel.org>, <linux-kernel@...r.kernel.org>
CC:     <shangxiaojing@...wei.com>
Subject: [PATCH] perf: Add build_id_cahce__read_build_id helper

Wrap repeated code in helper function build_id_cahce__read_build_id, which
gets build id if success, or return -1 for failed to read build id.

Signed-off-by: Shang XiaoJing <shangxiaojing@...wei.com>
---
 tools/perf/builtin-buildid-cache.c | 41 +++++++++++++++---------------
 1 file changed, 20 insertions(+), 21 deletions(-)

diff --git a/tools/perf/builtin-buildid-cache.c b/tools/perf/builtin-buildid-cache.c
index cd381693658b..a55d1c6496ea 100644
--- a/tools/perf/builtin-buildid-cache.c
+++ b/tools/perf/builtin-buildid-cache.c
@@ -172,20 +172,31 @@ static int build_id_cache__add_kcore(const char *filename, bool force)
 	return 0;
 }
 
-static int build_id_cache__add_file(const char *filename, struct nsinfo *nsi)
+static int build_id_cahce__read_build_id(const char *filename, struct nsinfo *nsi,
+					  struct build_id *bid)
 {
-	char sbuild_id[SBUILD_ID_SIZE];
-	struct build_id bid;
-	int err;
 	struct nscookie nsc;
+	int err;
 
 	nsinfo__mountns_enter(nsi, &nsc);
-	err = filename__read_build_id(filename, &bid);
+	err = filename__read_build_id(filename, bid);
 	nsinfo__mountns_exit(&nsc);
 	if (err < 0) {
 		pr_debug("Couldn't read a build-id in %s\n", filename);
 		return -1;
 	}
+	return err;
+}
+
+static int build_id_cache__add_file(const char *filename, struct nsinfo *nsi)
+{
+	char sbuild_id[SBUILD_ID_SIZE];
+	struct build_id bid;
+	int err;
+
+	err = build_id_cahce__read_build_id(filename, nsi, &bid);
+	if (err < 0)
+		return -1;
 
 	build_id__sprintf(&bid, sbuild_id);
 	err = build_id_cache__add_s(sbuild_id, filename, nsi,
@@ -199,17 +210,11 @@ static int build_id_cache__remove_file(const char *filename, struct nsinfo *nsi)
 {
 	char sbuild_id[SBUILD_ID_SIZE];
 	struct build_id bid;
-	struct nscookie nsc;
-
 	int err;
 
-	nsinfo__mountns_enter(nsi, &nsc);
-	err = filename__read_build_id(filename, &bid);
-	nsinfo__mountns_exit(&nsc);
-	if (err < 0) {
-		pr_debug("Couldn't read a build-id in %s\n", filename);
+	err = build_id_cahce__read_build_id(filename, nsi, &bid);
+	if (err < 0)
 		return -1;
-	}
 
 	build_id__sprintf(&bid, sbuild_id);
 	err = build_id_cache__remove_s(sbuild_id);
@@ -302,17 +307,11 @@ static int build_id_cache__update_file(const char *filename, struct nsinfo *nsi)
 {
 	char sbuild_id[SBUILD_ID_SIZE];
 	struct build_id bid;
-	struct nscookie nsc;
-
 	int err;
 
-	nsinfo__mountns_enter(nsi, &nsc);
-	err = filename__read_build_id(filename, &bid);
-	nsinfo__mountns_exit(&nsc);
-	if (err < 0) {
-		pr_debug("Couldn't read a build-id in %s\n", filename);
+	err = build_id_cahce__read_build_id(filename, nsi, &bid);
+	if (err < 0)
 		return -1;
-	}
 	err = 0;
 
 	build_id__sprintf(&bid, sbuild_id);
-- 
2.17.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ