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: 834ebb5678 ("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>
This commit is contained in:
Ian Rogers
2025-12-06 18:23:45 -08:00
committed by Namhyung Kim
parent 800ad1f0e2
commit 5c5f6fe32d
4 changed files with 13 additions and 5 deletions

View File

@@ -276,12 +276,14 @@ static bool dso__missing_buildid_cache(struct dso *dso, int parm __maybe_unused)
{
char filename[PATH_MAX];
struct build_id bid = { .size = 0, };
int err;
if (!dso__build_id_filename(dso, filename, sizeof(filename), false))
return true;
if (filename__read_build_id(filename, &bid) == -1) {
if (errno == ENOENT)
err = filename__read_build_id(filename, &bid);
if (err < 0) {
if (err == -ENOENT)
return false;
pr_warning("Problems with %s file, consider removing it from the cache\n",

View File

@@ -426,8 +426,10 @@ int libbfd__read_build_id(const char *filename, struct build_id *bid)
if (!filename)
return -EFAULT;
errno = 0;
if (!is_regular_file(filename))
return -EWOULDBLOCK;
return errno == 0 ? -EWOULDBLOCK : -errno;
fd = open(filename, O_RDONLY);
if (fd < 0)

View File

@@ -902,8 +902,10 @@ int filename__read_build_id(const char *filename, struct build_id *bid)
if (!filename)
return -EFAULT;
errno = 0;
if (!is_regular_file(filename))
return -EWOULDBLOCK;
return errno == 0 ? -EWOULDBLOCK : -errno;
err = kmod_path__parse(&m, filename);
if (err)

View File

@@ -104,8 +104,10 @@ int filename__read_build_id(const char *filename, struct build_id *bid)
if (!filename)
return -EFAULT;
errno = 0;
if (!is_regular_file(filename))
return -EWOULDBLOCK;
return errno == 0 ? -EWOULDBLOCK : -errno;
fd = open(filename, O_RDONLY);
if (fd < 0)