]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
perf symbol: Fix ENOENT case for filename__read_build_id
authorIan Rogers <irogers@google.com>
Sun, 7 Dec 2025 02:23:45 +0000 (18:23 -0800)
committerNamhyung Kim <namhyung@kernel.org>
Wed, 17 Dec 2025 15:30:51 +0000 (07:30 -0800)
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: 834ebb5678d7 ("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>
tools/perf/builtin-buildid-cache.c
tools/perf/util/libbfd.c
tools/perf/util/symbol-elf.c
tools/perf/util/symbol-minimal.c

index c98104481c8a19e45ace6f38456c6697b1600651..539e779e32682c5d85f18299d680aa6d97f6d41f 100644 (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",
index cc0c474cbfaa8ec111ff77ef9208f80f28606cf5..79f4528234a9d6d5bc40665675af4e513255a55d 100644 (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)
index 957143fbf8a07ce525daa54550428a8fd16f3003..d1dcafa4b3b808445b88534c8b3b7cbb9d3ad485 100644 (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)
index c6b17c14a2e9941e9702db4aaf04c3fd816d6451..8221dc9868f7c9f8bf8e6f1509c2444487b1ead0 100644 (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)