Skip to content

Commit 5c5f6fe

Browse files
captain5050namhyung
authored andcommitted
perf symbol: Fix ENOENT case for filename__read_build_id
Some callers of filename__read_build_id assume the error value must be -1, fix by making them handle all < 0 values. If is_regular_file fails in filename__read_build_id then it could be the file is missing (ENOENT) and it would be wrong to return -EWOULDBLOCK in that case. Fix the logic so -EWOULDBLOCK is only reported if other errors with stat haven't occurred. Fixes: 834ebb5 ("perf tools: Don't read build-ids from non-regular files") Signed-off-by: Ian Rogers <irogers@google.com> Reviewed-by: James Clark <james.clark@linaro.org> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
1 parent 800ad1f commit 5c5f6fe

4 files changed

Lines changed: 13 additions & 5 deletions

File tree

tools/perf/builtin-buildid-cache.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,14 @@ static bool dso__missing_buildid_cache(struct dso *dso, int parm __maybe_unused)
276276
{
277277
char filename[PATH_MAX];
278278
struct build_id bid = { .size = 0, };
279+
int err;
279280

280281
if (!dso__build_id_filename(dso, filename, sizeof(filename), false))
281282
return true;
282283

283-
if (filename__read_build_id(filename, &bid) == -1) {
284-
if (errno == ENOENT)
284+
err = filename__read_build_id(filename, &bid);
285+
if (err < 0) {
286+
if (err == -ENOENT)
285287
return false;
286288

287289
pr_warning("Problems with %s file, consider removing it from the cache\n",

tools/perf/util/libbfd.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,10 @@ int libbfd__read_build_id(const char *filename, struct build_id *bid)
426426

427427
if (!filename)
428428
return -EFAULT;
429+
430+
errno = 0;
429431
if (!is_regular_file(filename))
430-
return -EWOULDBLOCK;
432+
return errno == 0 ? -EWOULDBLOCK : -errno;
431433

432434
fd = open(filename, O_RDONLY);
433435
if (fd < 0)

tools/perf/util/symbol-elf.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,8 +902,10 @@ int filename__read_build_id(const char *filename, struct build_id *bid)
902902

903903
if (!filename)
904904
return -EFAULT;
905+
906+
errno = 0;
905907
if (!is_regular_file(filename))
906-
return -EWOULDBLOCK;
908+
return errno == 0 ? -EWOULDBLOCK : -errno;
907909

908910
err = kmod_path__parse(&m, filename);
909911
if (err)

tools/perf/util/symbol-minimal.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,10 @@ int filename__read_build_id(const char *filename, struct build_id *bid)
104104

105105
if (!filename)
106106
return -EFAULT;
107+
108+
errno = 0;
107109
if (!is_regular_file(filename))
108-
return -EWOULDBLOCK;
110+
return errno == 0 ? -EWOULDBLOCK : -errno;
109111

110112
fd = open(filename, O_RDONLY);
111113
if (fd < 0)

0 commit comments

Comments
 (0)