From: Peter Zijlstra <peterz@infradead.org>
To: mingo@kernel.org
Cc: linux-kernel@vger.kernel.org, peterz@infradead.org,
acme@kernel.org, mark.rutland@arm.com,
alexander.shishkin@linux.intel.com, jolsa@kernel.org,
namhyung@kernel.org, irogers@google.com, adrian.hunter@intel.com
Subject: [PATCH 03/13] perf: Simplify perf_fget_light()
Date: Thu, 02 Nov 2023 16:09:22 +0100 [thread overview]
Message-ID: <20231102152018.069585432@infradead.org> (raw)
In-Reply-To: 20231102150919.719936610@infradead.org
Introduce fdnull and use it to simplify perf_fget_light() to either
return a valid struct fd or not -- much like fdget() itself.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
include/linux/file.h | 7 ++++++-
kernel/events/core.c | 22 +++++++++++-----------
2 files changed, 17 insertions(+), 12 deletions(-)
--- a/include/linux/file.h
+++ b/include/linux/file.h
@@ -59,6 +59,8 @@ static inline struct fd __to_fd(unsigned
return (struct fd){(struct file *)(v & ~3),v & 3};
}
+#define fdnull __to_fd(0)
+
static inline struct fd fdget(unsigned int fd)
{
return __to_fd(__fdget(fd));
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -5802,18 +5802,17 @@ EXPORT_SYMBOL_GPL(perf_event_period);
static const struct file_operations perf_fops;
-static inline int perf_fget_light(int fd, struct fd *p)
+static inline struct fd perf_fdget(int fd)
{
struct fd f = fdget(fd);
if (!f.file)
- return -EBADF;
+ return fdnull;
if (f.file->f_op != &perf_fops) {
fdput(f);
- return -EBADF;
+ return fdnull;
}
- *p = f;
- return 0;
+ return f;
}
static int perf_event_set_output(struct perf_event *event,
@@ -5864,10 +5863,9 @@ static long _perf_ioctl(struct perf_even
int ret;
if (arg != -1) {
struct perf_event *output_event;
- struct fd output;
- ret = perf_fget_light(arg, &output);
- if (ret)
- return ret;
+ struct fd output = perf_fdget(arg);
+ if (!output.file)
+ return -EBADF;
output_event = output.file->private_data;
ret = perf_event_set_output(event, output_event);
fdput(output);
@@ -12401,9 +12399,11 @@ SYSCALL_DEFINE5(perf_event_open,
return event_fd;
if (group_fd != -1) {
- err = perf_fget_light(group_fd, &group);
- if (err)
+ group = perf_fdget(group_fd);
+ if (!group.file) {
+ err = -EBADF;
goto err_fd;
+ }
group_leader = group.file->private_data;
if (flags & PERF_FLAG_FD_OUTPUT)
output_event = group_leader;
next prev parent reply other threads:[~2023-11-02 15:33 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-02 15:09 [PATCH 00/13] perf: Employ SBRM to simplify error handling -- batch 1/3 Peter Zijlstra
2023-11-02 15:09 ` [PATCH 01/13] perf: Simplify perf_event_alloc() error path Peter Zijlstra
2023-11-03 12:38 ` Jiri Olsa
2023-11-03 19:50 ` Namhyung Kim
2023-11-15 9:58 ` Peter Zijlstra
2023-11-15 15:12 ` Namhyung Kim
2023-11-15 9:31 ` Peter Zijlstra
2023-11-02 15:09 ` [PATCH 02/13] perf: Simplify perf_pmu_register() " Peter Zijlstra
2023-11-02 15:09 ` Peter Zijlstra [this message]
2023-11-02 15:09 ` [PATCH 04/13] perf: Simplify event_function*() Peter Zijlstra
2023-11-02 15:09 ` [PATCH 05/13] perf: Simplify perf_cgroup_connect() Peter Zijlstra
2023-11-02 15:09 ` [PATCH 06/13] perf; Simplify event_sched_in() Peter Zijlstra
2023-11-02 15:09 ` [PATCH 07/13] perf: Simplify: __perf_install_in_context() Peter Zijlstra
2023-11-04 1:08 ` Namhyung Kim
2023-11-15 9:24 ` Peter Zijlstra
2023-11-02 15:09 ` [PATCH 08/13] perf: Simplify: *perf_event_{dis,en}able*() Peter Zijlstra
2023-11-02 15:09 ` [PATCH 09/13] perf: Simplify perf_event_modify_attr() Peter Zijlstra
2023-11-02 15:09 ` [PATCH 10/13] perf: Simplify perf_event_context_sched_in() Peter Zijlstra
2023-11-02 15:09 ` [PATCH 11/13] perf: Simplify perf_adjust_freq_unthr_context() Peter Zijlstra
2023-11-04 1:14 ` Namhyung Kim
2023-11-15 10:31 ` Peter Zijlstra
2023-11-02 15:09 ` [PATCH 12/13] perf: Simplify perf_event_*_on_exec() Peter Zijlstra
2023-11-02 15:09 ` [PATCH 13/13] perf: Simplify *perf_event_read*() Peter Zijlstra
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=20231102152018.069585432@infradead.org \
--to=peterz@infradead.org \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
/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