[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aJ5HhZsRPN-ZY_cK@google.com>
Date: Thu, 14 Aug 2025 13:31:01 -0700
From: Namhyung Kim <namhyung@...nel.org>
To: Sergio Perez Gonzalez <sperezglz@...il.com>
Cc: peterz@...radead.org, mingo@...hat.com, acme@...nel.org,
mark.rutland@....com, alexander.shishkin@...ux.intel.com,
jolsa@...nel.org, irogers@...gle.com, adrian.hunter@...el.com,
kan.liang@...ux.intel.com, colin.i.king@...il.com,
linux-perf-users@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] perf drm_pmu: Prevent resource leak in
for_each_drm_fdinfo_in_dir()
Hello,
On Thu, Aug 14, 2025 at 12:06:11AM -0600, Sergio Perez Gonzalez wrote:
> Close fdinfo_dir_fd and fd_dir prior to exit, in the event of
> cb() error.
>
> Signed-off-by: Sergio Perez Gonzalez <sperezglz@...il.com>
Acked-by: Namhyung Kim <namhyung@...nel.org>
Only a nitpick below.
> ---
> tools/perf/util/drm_pmu.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/tools/perf/util/drm_pmu.c b/tools/perf/util/drm_pmu.c
> index 988890f37ba7..416aeac7956e 100644
> --- a/tools/perf/util/drm_pmu.c
> +++ b/tools/perf/util/drm_pmu.c
> @@ -403,7 +403,7 @@ static int for_each_drm_fdinfo_in_dir(int (*cb)(void *args, int fdinfo_dir_fd, c
> DIR *fd_dir;
> struct dirent *fd_entry;
> int fd_dir_fd, fdinfo_dir_fd = -1;
> -
> + int ret = 0;
>
> scnprintf(buf, sizeof(buf), "%s/fd", pid_name);
> fd_dir_fd = openat(proc_dir, buf, O_DIRECTORY);
> @@ -418,7 +418,6 @@ static int for_each_drm_fdinfo_in_dir(int (*cb)(void *args, int fdinfo_dir_fd, c
> struct stat stat;
> unsigned int minor;
> bool is_dup = false;
> - int ret;
>
> if (fd_entry->d_type != DT_LNK)
> continue;
> @@ -458,12 +457,13 @@ 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 out;
It could be just 'break'.
Thanks,
Namhyung
> }
> +out:
> if (fdinfo_dir_fd != -1)
> close(fdinfo_dir_fd);
> closedir(fd_dir);
> - return 0;
> + return ret;
> }
>
> static int for_each_drm_fdinfo(bool skip_all_duplicates,
> --
> 2.43.0
>
Powered by blists - more mailing lists