* [PATCH v3] perf drm_pmu: fix fd_dir leaks in for_each_drm_fdinfo_in_dir()
@ 2025-09-08 6:52 zhaoguohan
2025-09-08 8:02 ` Markus Elfring
2025-09-12 18:26 ` Arnaldo Carvalho de Melo
0 siblings, 2 replies; 3+ messages in thread
From: zhaoguohan @ 2025-09-08 6:52 UTC (permalink / raw)
To: peterz, mingo, acme, namhyung
Cc: mark.rutland, alexander.shishkin, jolsa, irogers, adrian.hunter,
kan.liang, open list:PERFORMANCE EVENTS SUBSYSTEM,
open list:PERFORMANCE EVENTS SUBSYSTEM, GuoHan Zhao,
Markus Elfring
From: GuoHan Zhao <zhaoguohan@kylinos.cn>
Fix file descriptor leak when callback function returns error. The
function was directly returning without closing fdinfo_dir_fd and
fd_dir when cb() returned non-zero value.
Fixes: 28917cb17f9d ("perf drm_pmu: Add a tool like PMU to expose DRM information")
Reviewed-by: Ian Rogers <irogers@google.com>
Reviewed-by: Namhyung Kim <namhyung@kernel.org>
Reviewed-by: Markus Elfring <Markus.Elfring@web.de>
Signed-off-by: GuoHan Zhao <zhaoguohan@kylinos.cn>
---
v2 -> v3: replaced "cleanup" with "close_fdinfo"
v1 -> v2: Added the Fixes tag in commit message
---
tools/perf/util/drm_pmu.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/tools/perf/util/drm_pmu.c b/tools/perf/util/drm_pmu.c
index 988890f37ba7..98d4d2b556d4 100644
--- a/tools/perf/util/drm_pmu.c
+++ b/tools/perf/util/drm_pmu.c
@@ -458,8 +458,10 @@ static int for_each_drm_fdinfo_in_dir(int (*cb)(void *args, int fdinfo_dir_fd, c
}
ret = cb(args, fdinfo_dir_fd, fd_entry->d_name);
if (ret)
- return ret;
+ goto close_fdinfo;
}
+
+close_fdinfo:
if (fdinfo_dir_fd != -1)
close(fdinfo_dir_fd);
closedir(fd_dir);
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v3] perf drm_pmu: fix fd_dir leaks in for_each_drm_fdinfo_in_dir()
2025-09-08 6:52 [PATCH v3] perf drm_pmu: fix fd_dir leaks in for_each_drm_fdinfo_in_dir() zhaoguohan
@ 2025-09-08 8:02 ` Markus Elfring
2025-09-12 18:26 ` Arnaldo Carvalho de Melo
1 sibling, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2025-09-08 8:02 UTC (permalink / raw)
To: GuoHan Zhao, linux-perf-users
Cc: LKML, Adrian Hunter, Alexander Shishkin, Arnaldo Carvalho de Melo,
Ian Rogers, Ingo Molnar, Jiri Olsa, Kan Liang, Mark Rutland,
Namhyung Kim, Peter Zijlstra
> Fix file descriptor leak when callback function returns error. The
…
Would it be nicer to move the last word into the next text line?
…> +++ b/tools/perf/util/drm_pmu.c
> @@ -458,8 +458,10 @@ static int for_each_drm_fdinfo_in_dir(int (*cb)(void *args, int fdinfo_dir_fd, c
> }
> ret = cb(args, fdinfo_dir_fd, fd_entry->d_name);
…> +close_fdinfo:
> if (fdinfo_dir_fd != -1)
May a repeated check be avoided here?
> close(fdinfo_dir_fd);
How do you think about to use such a label directly before
the function call?
> closedir(fd_dir);
Regards,
Markus
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3] perf drm_pmu: fix fd_dir leaks in for_each_drm_fdinfo_in_dir()
2025-09-08 6:52 [PATCH v3] perf drm_pmu: fix fd_dir leaks in for_each_drm_fdinfo_in_dir() zhaoguohan
2025-09-08 8:02 ` Markus Elfring
@ 2025-09-12 18:26 ` Arnaldo Carvalho de Melo
1 sibling, 0 replies; 3+ messages in thread
From: Arnaldo Carvalho de Melo @ 2025-09-12 18:26 UTC (permalink / raw)
To: zhaoguohan
Cc: peterz, mingo, namhyung, mark.rutland, alexander.shishkin, jolsa,
irogers, adrian.hunter, kan.liang,
open list:PERFORMANCE EVENTS SUBSYSTEM,
open list:PERFORMANCE EVENTS SUBSYSTEM, Markus Elfring
On Mon, Sep 08, 2025 at 02:52:03PM +0800, zhaoguohan@kylinos.cn wrote:
> From: GuoHan Zhao <zhaoguohan@kylinos.cn>
>
> Fix file descriptor leak when callback function returns error. The
> function was directly returning without closing fdinfo_dir_fd and
> fd_dir when cb() returned non-zero value.
Thanks, applying to perf-tools-next.
- Arnaldo
> Fixes: 28917cb17f9d ("perf drm_pmu: Add a tool like PMU to expose DRM information")
> Reviewed-by: Ian Rogers <irogers@google.com>
> Reviewed-by: Namhyung Kim <namhyung@kernel.org>
> Reviewed-by: Markus Elfring <Markus.Elfring@web.de>
> Signed-off-by: GuoHan Zhao <zhaoguohan@kylinos.cn>
> ---
> v2 -> v3: replaced "cleanup" with "close_fdinfo"
> v1 -> v2: Added the Fixes tag in commit message
> ---
> tools/perf/util/drm_pmu.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/tools/perf/util/drm_pmu.c b/tools/perf/util/drm_pmu.c
> index 988890f37ba7..98d4d2b556d4 100644
> --- a/tools/perf/util/drm_pmu.c
> +++ b/tools/perf/util/drm_pmu.c
> @@ -458,8 +458,10 @@ static int for_each_drm_fdinfo_in_dir(int (*cb)(void *args, int fdinfo_dir_fd, c
> }
> ret = cb(args, fdinfo_dir_fd, fd_entry->d_name);
> if (ret)
> - return ret;
> + goto close_fdinfo;
> }
> +
> +close_fdinfo:
> if (fdinfo_dir_fd != -1)
> close(fdinfo_dir_fd);
> closedir(fd_dir);
> --
> 2.43.0
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-09-12 18:26 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-08 6:52 [PATCH v3] perf drm_pmu: fix fd_dir leaks in for_each_drm_fdinfo_in_dir() zhaoguohan
2025-09-08 8:02 ` Markus Elfring
2025-09-12 18:26 ` Arnaldo Carvalho de Melo
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.