perf: probe-file: Check return value of strlist__add for -ENOMEM
PATCH v2 1/1 perf: probe-file: Check return value of strlist__add for -ENOMEM
From: He Zhe <[email protected]>
strlist__add may fail with -ENOMEM. Check it and give debugging hint in advance.
---
v2: Only catch -ENOMEM
tools/perf/builtin-probe.c | 6 ++++-- tools/perf/util/probe-file.c | 28 ++++++++++++++++++++++++---- 2 files changed, 28 insertions(+), 6 deletions(-)
tools/perf/builtin-probe.c +4 -2
@@ -449,7 +449,8 @@ static int perf_del_probe_events(struct strfilter *filter) ret =probe_file__del_strlist (kfd, klist);if (ret <0 ) goto error; - } + }else if (ret == -ENOMEM ) + goto error; ret2 =probe_file__get_events (ufd, filter, ulist);if (ret2 ==0 ) {
@@ -459,7 +460,8 @@ static int perf_del_probe_events(struct strfilter *filter) ret2 =probe_file__del_strlist (ufd, ulist);if (ret2 <0 ) goto error; - } + }else if (ret2 == -ENOMEM ) + goto error;if (ret == -ENOENT && ret2 == -ENOENT )pr_warning ("\"%s\" does not hit any event.\n" , str);
tools/perf/util/probe-file.c +24 -4
@@ -307,10 +307,15 @@ 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 =strlist__add (plist, ent->s); +if (ret == -ENOMEM ) { +pr_err ("strlist__add failed with -ENOMEM\n" ); + goto out; + } ret =0 ; } } +out:strlist__delete (namelist);return ret;
@@ -517,7 +522,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 == -ENOMEM ) { +pr_err ("strlist__add failed with -ENOMEM\n" ); + goto out; + } } } out:
@@ -678,7 +687,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 == -ENOMEM ) { +pr_err ("strlist__add failed with -ENOMEM\n" ); + goto out_err; + } +free (command); }list_add_tail (&entry->node, &pcache->entries);
@@ -859,9 +873,15 @@ int probe_cache__scan_sdt(struct probe_cache *pcache, const char *pathname)break ; } -strlist__add (entry->tevlist, buf); + ret =strlist__add (entry->tevlist, buf); +free (buf); entry =NULL ; + +if (ret == -ENOMEM ) { +pr_err ("strlist__add failed with -ENOMEM\n" ); +break ; + } }if (entry) {list_del_init (&entry->node);
Signature · 1 line
2.24.1
Quoted 6 lines · On Wed, Feb 26, 2020 at 10:30:04PM +0800, [email protected] wrote:
From: He Zhe <[email protected]>
strlist__addmay fail with-ENOMEM. Check it and give debugging hint in advance.Signed-off-by He Zhe <[email protected]>
thanks,
jirka
Arnaldo Carvalho de Melo
AppliedEm Wed, Feb 26, 2020 at 04:31:53PM +0100, Jiri Olsa escreveu:
Quoted 9 lines · On Wed, Feb 26, 2020 at 10:30:04PM +0800, [email protected] wrote:
Quoted 6 lines
From: He Zhe <[email protected]>
strlist__addmay fail with-ENOMEM. Check it and give debugging hint in advance.Signed-off-by He Zhe <[email protected]>Acked-by Jiri Olsa <[email protected]>
Thanks, applied,
- Arnaldo
Masami Hiramatsu
Acked-byQuoted 4 lines · On Thu, 27 Feb 2020 11:03:41 -0300 Arnaldo Carvalho de Melo <[email protected]>…
Em Wed, Feb 26, 2020 at 04:31:53PM +0100, Jiri Olsa escreveu:
Quoted 3 lines · On Wed, Feb 26, 2020 at 10:30:04PM +0800, [email protected] wrote:
Quoted 2 lines
From: He Zhe <[email protected]>
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
strlist__addmay fail with-ENOMEM. Check it and give debugging hint in advance.Signed-off-by He Zhe <[email protected]>Acked-by Jiri Olsa <[email protected]>Thanks, applied,
Thanks Arnaldo and He, Sorry I missed to reply my Ack.
Thanks,
Signature · 1 line
Masami Hiramatsu <[email protected]>
[tip: perf/urgent] perf probe: Check return value of strlist__add() for -ENOMEM
In reply to [email protected]The following commit has been merged into the perf/urgent branch of tip:
The following commit has been merged into the perf/urgent branch of tip:
Commit-ID: bd862b1d839221322b2e38eb8a06861604804b5e Gitweb: https://git.kernel.org/tip/bd862b1d839221322b2e38eb8a06861604804b5e Author: He Zhe <[email protected]> AuthorDate: Wed, 26 Feb 2020 22:30:04 +08:00 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitterDate: Thu, 27 Feb 2020 11:03:13 -03:00
perf probe: Check return value of strlist__add() for -ENOMEM
strlist__add() may fail with -ENOMEM. Check it and give debugging hint in advance.
--- tools/perf/builtin-probe.c | 6 ++++-- tools/perf/util/probe-file.c | 28 ++++++++++++++++++++++++---- 2 files changed, 28 insertions(+), 6 deletions(-)
tools/perf/builtin-probe.c +4 -2
@@ -449,7 +449,8 @@ static int perf_del_probe_events(struct strfilter *filter) ret =probe_file__del_strlist (kfd, klist);if (ret <0 ) goto error; - } + }else if (ret == -ENOMEM ) + goto error; ret2 =probe_file__get_events (ufd, filter, ulist);if (ret2 ==0 ) {
@@ -459,7 +460,8 @@ static int perf_del_probe_events(struct strfilter *filter) ret2 =probe_file__del_strlist (ufd, ulist);if (ret2 <0 ) goto error; - } + }else if (ret2 == -ENOMEM ) + goto error;if (ret == -ENOENT && ret2 == -ENOENT )pr_warning ("\"%s\" does not hit any event.\n" , str);
tools/perf/util/probe-file.c +24 -4
@@ -301,10 +301,15 @@ 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 =strlist__add (plist, ent->s); +if (ret == -ENOMEM ) { +pr_err ("strlist__add failed with -ENOMEM\n" ); + goto out; + } ret =0 ; } } +out:strlist__delete (namelist);return ret;
@@ -511,7 +516,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 == -ENOMEM ) { +pr_err ("strlist__add failed with -ENOMEM\n" ); + goto out; + } } } out:
@@ -672,7 +681,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 == -ENOMEM ) { +pr_err ("strlist__add failed with -ENOMEM\n" ); + goto out_err; + } +free (command); }list_add_tail (&entry->node, &pcache->entries);
@@ -853,9 +867,15 @@ int probe_cache__scan_sdt(struct probe_cache *pcache, const char *pathname)break ; } -strlist__add (entry->tevlist, buf); + ret =strlist__add (entry->tevlist, buf); +free (buf); entry =NULL ; + +if (ret == -ENOMEM ) { +pr_err ("strlist__add failed with -ENOMEM\n" ); +break ; + } }if (entry) {list_del_init (&entry->node);