From: Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com>
To: Ian Rogers <irogers@google.com>,
Wang ShaoBo <bobo.shaobowang@huawei.com>
Cc: cj.chengjian@huawei.com, Li Bin <huawei.libin@huawei.com>,
Jiri Olsa <jolsa@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
linux-perf-users <linux-perf-users@vger.kernel.org>
Subject: Re: [PATCH -next] tools build: Check return value of fwrite_unlocked in jvmti_agent.c
Date: Wed, 29 Jul 2020 22:12:46 -0300 [thread overview]
Message-ID: <F549EBCC-2BC0-43D4-B470-A53E9DF37A29@gmail.com> (raw)
In-Reply-To: <CAP-5=fX9YUucA-3QMxO_jV954104UPNg04=_JGstuLekNJHzJw@mail.gmail.com>
On July 29, 2020 8:47:36 PM GMT-03:00, Ian Rogers <irogers@google.com> wrote:
>On Fri, Jul 24, 2020 at 3:07 AM Wang ShaoBo
><bobo.shaobowang@huawei.com> wrote:
>>
>> Function jvmti_write_code called by compiled_method_load_cb may
>return
>> error in using fwrite_unlocked, this failure should be captured and
>> warned.
>>
>> Signed-off-by: Wang ShaoBo <bobo.shaobowang@huawei.com>
>> ---
>> tools/perf/jvmti/jvmti_agent.c | 23 +++++++++++++++--------
>> 1 file changed, 15 insertions(+), 8 deletions(-)
>>
>> diff --git a/tools/perf/jvmti/jvmti_agent.c
>b/tools/perf/jvmti/jvmti_agent.c
>> index 88108598d6e9..a1fe6aa16b6d 100644
>> --- a/tools/perf/jvmti/jvmti_agent.c
>> +++ b/tools/perf/jvmti/jvmti_agent.c
>> @@ -363,7 +363,7 @@ jvmti_write_code(void *agent, char const *sym,
>> struct jr_code_load rec;
>> size_t sym_len;
>> FILE *fp = agent;
>> - int ret = -1;
>> + int ret;
>>
>> /* don't care about 0 length function, no samples */
>> if (size == 0)
>> @@ -401,16 +401,23 @@ 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 (ret)
>> + goto error;
>
>Sorry, it seems I lost a reply to this. Won't ret here be the number
>of items written and not an error code? Consequently all writes will
>immediately goto error?
Good thing this is in tmp.perf/core, you're right, the test has to be (ret < 0)... I'll fix, thanks!
Also we need some 'perf test' for this :-/
- Arnaldo
>
>Thanks,
>Ian
>
>> + ret = fwrite_unlocked(sym, sym_len, 1, fp);
>> + if (ret)
>> + goto error;
>>
>> - if (code)
>> - fwrite_unlocked(code, size, 1, fp);
>> + if (code) {
>> + ret = fwrite_unlocked(code, size, 1, fp);
>> + if (ret)
>> + goto error;
>> + }
>>
>> funlockfile(fp);
>> -
>> - ret = 0;
>> -
>> - return ret;
>> + return 0;
>> +error:
>> + funlockfile(fp);
>> + return -1;
>> }
>>
>> int
>> --
>> 2.17.1
>>
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
next prev parent reply other threads:[~2020-07-30 1:13 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-24 10:07 Wang ShaoBo
2020-07-28 12:10 ` Arnaldo Carvalho de Melo
2020-07-29 23:47 ` Ian Rogers
2020-07-30 1:12 ` Arnaldo Carvalho de Melo [this message]
2020-07-30 10:03 ` Arnaldo Carvalho de Melo
2020-07-31 11:58 ` Wangshaobo (bobo)
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=F549EBCC-2BC0-43D4-B470-A53E9DF37A29@gmail.com \
--to=arnaldo.melo@gmail.com \
--cc=acme@kernel.org \
--cc=bobo.shaobowang@huawei.com \
--cc=cj.chengjian@huawei.com \
--cc=huawei.libin@huawei.com \
--cc=irogers@google.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
/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
all inboxes | Powered by JetHome®