From: Masami Hiramatsu <mhiramat@kernel.org>
To: He Zhe <zhe.he@windriver.com>
Cc: <peterz@infradead.org>, <mingo@redhat.com>, <acme@kernel.org>,
<mark.rutland@arm.com>, <alexander.shishkin@linux.intel.com>,
<jolsa@redhat.com>, <namhyung@kernel.org>,
<kstewart@linuxfoundation.org>, <tglx@linutronix.de>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/2] perf: probe-file: Check return value of strlist__add
Date: Wed, 26 Feb 2020 16:11:32 +0900 [thread overview]
Message-ID: <20200226161132.2aeea72b71d48e9988aa27d9@kernel.org> (raw)
In-Reply-To: <b07f670b-6539-1590-88a8-20c58dec3a7e@windriver.com>
On Wed, 26 Feb 2020 10:49:19 +0800
He Zhe <zhe.he@windriver.com> wrote:
>
>
> On 2/26/20 6:49 AM, Masami Hiramatsu wrote:
> > On Tue, 25 Feb 2020 22:41:43 +0800
> > <zhe.he@windriver.com> wrote:
> >
> >> From: He Zhe <zhe.he@windriver.com>
> >>
> >> strlist__add may fail with -ENOMEM or -EEXIST. Check it and give debugging
> >> hint when necessary.
> >>
> >> Signed-off-by: He Zhe <zhe.he@windriver.com>
> >> ---
> >> tools/perf/builtin-probe.c | 30 ++++++++++++++++--------------
> >> tools/perf/util/probe-file.c | 26 +++++++++++++++++++++-----
> >> 2 files changed, 37 insertions(+), 19 deletions(-)
> >>
> >> diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
> >> index 26bc5923e6b5..8b4511c70fed 100644
> >> --- a/tools/perf/builtin-probe.c
> >> +++ b/tools/perf/builtin-probe.c
> >> @@ -442,24 +442,26 @@ static int perf_del_probe_events(struct strfilter *filter)
> >> }
> >>
> >> ret = probe_file__get_events(kfd, filter, klist);
> >> - if (ret == 0) {
> >> - strlist__for_each_entry(ent, klist)
> >> - pr_info("Removed event: %s\n", ent->s);
> >> + if (ret < 0)
> >> + goto out;
> > No, this is ignored by design.
> > Since probe_file__get_events() returns -ENOENT when no event is matched,
> > this should be just ignored, and goto uprobe event matching.
>
> Thanks for pointing it out. However when strlist__add in probe_file__get_events
> returns a -ENOMEM and we ignore that, though it happens not very likely, we
> would miss some entries. So I add checks here and in probe_file__get_events to
> give a heads-up in advance.
If you are aware of -ENOMEM ( I guess in such case you'll see OOM killer
sooner or later ), please just catch it. I mean
if (ret == -ENOMEM)
goto out;
will be good.
Thank you,
>
> And the same reason is for the checks below for probe_cache__load,
> probe_cache__add_entry and probe_cache__scan_sdt.
>
>
> Regards,
> Zhe
>
> >
> >>
> >> - ret = probe_file__del_strlist(kfd, klist);
> >> - if (ret < 0)
> >> - goto error;
> >> - }
> >> + strlist__for_each_entry(ent, klist)
> >> + pr_info("Removed event: %s\n", ent->s);
> >> +
> >> + ret = probe_file__del_strlist(kfd, klist);
> >> + if (ret < 0)
> >> + goto error;
> >>
> >> ret2 = probe_file__get_events(ufd, filter, ulist);
> >> - if (ret2 == 0) {
> >> - strlist__for_each_entry(ent, ulist)
> >> - pr_info("Removed event: %s\n", ent->s);
> >> + if (ret2 < 0)
> >> + goto out;
> > Ditto.
> >
> > Thank you,
> >
> >>
> >> - ret2 = probe_file__del_strlist(ufd, ulist);
> >> - if (ret2 < 0)
> >> - goto error;
> >> - }
> >> + strlist__for_each_entry(ent, ulist)
> >> + pr_info("Removed event: %s\n", ent->s);
> >> +
> >> + ret2 = probe_file__del_strlist(ufd, ulist);
> >> + if (ret2 < 0)
> >> + goto error;
> >>
> >> if (ret == -ENOENT && ret2 == -ENOENT)
> >> pr_warning("\"%s\" does not hit any event.\n", str);
> >> diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c
> >> index cf44c05f89c1..00f086cba88f 100644
> >> --- a/tools/perf/util/probe-file.c
> >> +++ b/tools/perf/util/probe-file.c
> >> @@ -307,10 +307,14 @@ int probe_file__get_events(int fd, struct strfilter *filter,
> >> p = strchr(ent->s, ':');
> >> if ((p && strfilter__compare(filter, p + 1)) ||
> >> strfilter__compare(filter, ent->s)) {
> >> - strlist__add(plist, ent->s);
> >> - ret = 0;
> >> + ret = strlist__add(plist, ent->s);
> >> + if (ret < 0) {
> >> + pr_debug("strlist__add failed (%d)\n", ret);
> >> + goto out;
> >> + }
> >> }
> >> }
> >> +out:
> >> strlist__delete(namelist);
> >>
> >> return ret;
> >> @@ -517,7 +521,11 @@ static int probe_cache__load(struct probe_cache *pcache)
> >> ret = -EINVAL;
> >> goto out;
> >> }
> >> - strlist__add(entry->tevlist, buf);
> >> + ret = strlist__add(entry->tevlist, buf);
> >> + if (ret < 0) {
> >> + pr_debug("strlist__add failed (%d)\n", ret);
> >> + goto out;
> >> + }
> >> }
> >> }
> >> out:
> >> @@ -678,7 +686,12 @@ int probe_cache__add_entry(struct probe_cache *pcache,
> >> command = synthesize_probe_trace_command(&tevs[i]);
> >> if (!command)
> >> goto out_err;
> >> - strlist__add(entry->tevlist, command);
> >> + ret = strlist__add(entry->tevlist, command);
> >> + if (ret < 0) {
> >> + pr_debug("strlist__add failed (%d)\n", ret);
> >> + goto out_err;
> >> + }
> >> +
> >> free(command);
> >> }
> >> list_add_tail(&entry->node, &pcache->entries);
> >> @@ -859,7 +872,10 @@ int probe_cache__scan_sdt(struct probe_cache *pcache, const char *pathname)
> >> break;
> >> }
> >>
> >> - strlist__add(entry->tevlist, buf);
> >> + ret = strlist__add(entry->tevlist, buf);
> >> + if (ret < 0)
> >> + pr_debug("strlist__add failed (%d)\n", ret);
> >> +
> >> free(buf);
> >> entry = NULL;
> >> }
> >> --
> >> 2.24.1
> >>
> >
>
--
Masami Hiramatsu <mhiramat@kernel.org>
next prev parent reply other threads:[~2020-02-26 7:11 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-25 14:41 [PATCH 1/2] perf: Fix checking of duplicate probe to give proper hint zhe.he
2020-02-25 14:41 ` [PATCH 2/2] perf: probe-file: Check return value of strlist__add zhe.he
2020-02-25 22:49 ` Masami Hiramatsu
2020-02-26 2:49 ` He Zhe
2020-02-26 7:11 ` Masami Hiramatsu [this message]
2020-02-25 22:34 ` [PATCH 1/2] perf: Fix checking of duplicate probe to give proper hint Masami Hiramatsu
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=20200226161132.2aeea72b71d48e9988aa27d9@kernel.org \
--to=mhiramat@kernel.org \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=jolsa@redhat.com \
--cc=kstewart@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=zhe.he@windriver.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