From: Namhyung Kim <namhyung@kernel.org>
To: Sergio Perez Gonzalez <sperezglz@gmail.com>
Cc: peterz@infradead.org, mingo@redhat.com, acme@kernel.org,
mark.rutland@arm.com, alexander.shishkin@linux.intel.com,
jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com,
kan.liang@linux.intel.com, colin.i.king@gmail.com,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] perf drm_pmu: Prevent resource leak in for_each_drm_fdinfo_in_dir()
Date: Thu, 14 Aug 2025 13:31:01 -0700 [thread overview]
Message-ID: <aJ5HhZsRPN-ZY_cK@google.com> (raw)
In-Reply-To: <20250814060614.450696-1-sperezglz@gmail.com>
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@gmail.com>
Acked-by: Namhyung Kim <namhyung@kernel.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
>
next prev parent reply other threads:[~2025-08-14 20:31 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-14 6:06 Sergio Perez Gonzalez
2025-08-14 20:31 ` Namhyung Kim [this message]
2025-08-14 20:42 ` Namhyung Kim
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aJ5HhZsRPN-ZY_cK@google.com \
--to=namhyung@kernel.org \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=colin.i.king@gmail.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=sperezglz@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®