[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <20241112065851.282787-1-luoyifan@cmss.chinamobile.com>
Date: Tue, 12 Nov 2024 14:58:51 +0800
From: Luo Yifan <luoyifan@...s.chinamobile.com>
To: acme@...nel.org
Cc: adrian.hunter@...el.com,
alexander.shishkin@...ux.intel.com,
irogers@...gle.com,
jolsa@...nel.org,
kan.liang@...ux.intel.com,
linux-kernel@...r.kernel.org,
linux-perf-users@...r.kernel.org,
mark.rutland@....com,
mingo@...hat.com,
namhyung@...nel.org,
peterz@...radead.org,
Luo Yifan <luoyifan@...s.chinamobile.com>
Subject: [PATCH] perf jvmti: Properly handle return value checks in jvmti_write_code
Following the approach in the jvmti_write_debug_info function, add
some return value checks in jvmti_write_code.
Signed-off-by: Luo Yifan <luoyifan@...s.chinamobile.com>
---
tools/perf/jvmti/jvmti_agent.c | 27 +++++++++++++++++----------
1 file changed, 17 insertions(+), 10 deletions(-)
diff --git a/tools/perf/jvmti/jvmti_agent.c b/tools/perf/jvmti/jvmti_agent.c
index 526dcaf9f..b52466a0c 100644
--- a/tools/perf/jvmti/jvmti_agent.c
+++ b/tools/perf/jvmti/jvmti_agent.c
@@ -361,9 +361,8 @@ jvmti_write_code(void *agent, char const *sym,
{
static int code_generation = 1;
struct jr_code_load rec;
- size_t sym_len;
+ size_t sret, sym_len;
FILE *fp = agent;
- int ret = -1;
/* don't care about 0 length function, no samples */
if (size == 0)
@@ -400,17 +399,25 @@ jvmti_write_code(void *agent, char const *sym,
*/
rec.code_index = code_generation++;
- ret = fwrite_unlocked(&rec, sizeof(rec), 1, fp);
- fwrite_unlocked(sym, sym_len, 1, fp);
-
- if (code)
- fwrite_unlocked(code, size, 1, fp);
+ sret = fwrite_unlocked(&rec, sizeof(rec), 1, fp);
+ if (sret != 1)
+ goto error;
- funlockfile(fp);
+ sret = fwrite_unlocked(sym, sym_len, 1, fp);
+ if (sret != 1)
+ goto error;
- ret = 0;
+ if (code) {
+ sret = fwrite_unlocked(code, size, 1, fp);
+ if (sret != 1)
+ goto error;
+ }
- return ret;
+ funlockfile(fp);
+ return 0;
+error:
+ funlockfile(fp);
+ return -1;
}
int
--
2.33.0
Powered by blists - more mailing lists