Skip to content

Commit bd862b1

Browse files
He Zheacmel
authored andcommitted
perf probe: Check return value of strlist__add() for -ENOMEM
strlist__add() may fail with -ENOMEM. Check it and give debugging hint in advance. Signed-off-by: He Zhe <[email protected]> Acked-by: Jiri Olsa <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Kate Stewart <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Masami Hiramatsu <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent b0aaf4c commit bd862b1

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

tools/perf/builtin-probe.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,8 @@ static int perf_del_probe_events(struct strfilter *filter)
449449
ret = probe_file__del_strlist(kfd, klist);
450450
if (ret < 0)
451451
goto error;
452-
}
452+
} else if (ret == -ENOMEM)
453+
goto error;
453454

454455
ret2 = probe_file__get_events(ufd, filter, ulist);
455456
if (ret2 == 0) {
@@ -459,7 +460,8 @@ static int perf_del_probe_events(struct strfilter *filter)
459460
ret2 = probe_file__del_strlist(ufd, ulist);
460461
if (ret2 < 0)
461462
goto error;
462-
}
463+
} else if (ret2 == -ENOMEM)
464+
goto error;
463465

464466
if (ret == -ENOENT && ret2 == -ENOENT)
465467
pr_warning("\"%s\" does not hit any event.\n", str);

tools/perf/util/probe-file.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,15 @@ int probe_file__get_events(int fd, struct strfilter *filter,
301301
p = strchr(ent->s, ':');
302302
if ((p && strfilter__compare(filter, p + 1)) ||
303303
strfilter__compare(filter, ent->s)) {
304-
strlist__add(plist, ent->s);
304+
ret = strlist__add(plist, ent->s);
305+
if (ret == -ENOMEM) {
306+
pr_err("strlist__add failed with -ENOMEM\n");
307+
goto out;
308+
}
305309
ret = 0;
306310
}
307311
}
312+
out:
308313
strlist__delete(namelist);
309314

310315
return ret;
@@ -511,7 +516,11 @@ static int probe_cache__load(struct probe_cache *pcache)
511516
ret = -EINVAL;
512517
goto out;
513518
}
514-
strlist__add(entry->tevlist, buf);
519+
ret = strlist__add(entry->tevlist, buf);
520+
if (ret == -ENOMEM) {
521+
pr_err("strlist__add failed with -ENOMEM\n");
522+
goto out;
523+
}
515524
}
516525
}
517526
out:
@@ -672,7 +681,12 @@ int probe_cache__add_entry(struct probe_cache *pcache,
672681
command = synthesize_probe_trace_command(&tevs[i]);
673682
if (!command)
674683
goto out_err;
675-
strlist__add(entry->tevlist, command);
684+
ret = strlist__add(entry->tevlist, command);
685+
if (ret == -ENOMEM) {
686+
pr_err("strlist__add failed with -ENOMEM\n");
687+
goto out_err;
688+
}
689+
676690
free(command);
677691
}
678692
list_add_tail(&entry->node, &pcache->entries);
@@ -853,9 +867,15 @@ int probe_cache__scan_sdt(struct probe_cache *pcache, const char *pathname)
853867
break;
854868
}
855869

856-
strlist__add(entry->tevlist, buf);
870+
ret = strlist__add(entry->tevlist, buf);
871+
857872
free(buf);
858873
entry = NULL;
874+
875+
if (ret == -ENOMEM) {
876+
pr_err("strlist__add failed with -ENOMEM\n");
877+
break;
878+
}
859879
}
860880
if (entry) {
861881
list_del_init(&entry->node);

0 commit comments

Comments
 (0)