[PATCH 3/5] perf dso: Use stored fd error instead of stale errno in file_read()
Arnaldo Carvalho de Melo <[email protected]> Sun, 2 Aug 2026 11:20:20 -0300
| Newsgroups | org.kernel.vger.linux-perf-users,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
From: Arnaldo Carvalho de Melo <[email protected]> file_read() uses ret = -errno when dso__data(dso)->fd is negative after try_to_open_dso() fails. By this point errno has been through mutex_lock(), nsinfo__mountns_enter(), and multiple open() attempts inside try_to_open_dso() — it no longer reflects the actual open failure. If errno happens to be 0, ret = 0 looks like EOF rather than an error. The fd field already carries the negated errno from __open_dso() (e.g. -EINVAL, -ENOENT), so use it directly instead of reading the stale global errno. Fixes: 33bdedcea2d7 ("perf tools: Protect dso cache fd with a mutex") Reported-by: sashiko-bot <[email protected]> Cc: Namhyung Kim <[email protected]> Assisted-by: Claude:claude-opus-4.6 Signed-off-by: Arnaldo Carvalho de Melo <[email protected]> --- tools/perf/util/dso.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c index d9c008465f377e79..207f8744aac97e8c 100644 --- a/tools/perf/util/dso.c +++ b/tools/perf/util/dso.c @@ -1026,7 +1026,8 @@ static ssize_t file_read(struct dso *dso, struct machine *machine, if (dso__data(dso)->fd < 0) { dso__data(dso)->status = DSO_DATA_STATUS_ERROR; - ret = -errno; + /* fd already carries the negated errno from __open_dso() */ + ret = dso__data(dso)->fd; goto out; } -- 2.55.0