From: Antonio Hickey <antoniohickey99@gmail.com>
To: ojeda@kernel.org, alex.gaynor@gmail.com, wedsonaf@gmail.com
Cc: boqun.feng@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com,
benno.lossin@proton.me, a.hindborg@samsung.com,
aliceryhl@google.com, rust-for-linux@vger.kernel.org,
Antonio Hickey <antoniohickey99@gmail.com>
Subject: [PATCH] rust: task: use safe `current!` macro
Date: Mon, 15 Jan 2024 21:28:23 -0500 [thread overview]
Message-ID: <20240116022823.64058-2-antoniohickey99@gmail.com> (raw)
In-Reply-To: <20240116022823.64058-1-antoniohickey99@gmail.com>
Refactor the `Task::pid_in_current_ns()` to use the safe abstraction
`current!()` instead of the unsafe `bindings::get_current()` binding.
Signed-off-by: Antonio Hickey <antoniohickey99@gmail.com>
---
rust/kernel/task.rs | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/rust/kernel/task.rs b/rust/kernel/task.rs
index 72737f5d86ab..ffe08c348b72 100644
--- a/rust/kernel/task.rs
+++ b/rust/kernel/task.rs
@@ -168,8 +168,9 @@ pub fn signal_pending(&self) -> bool {
/// Returns the given task's pid in the current pid namespace.
pub fn pid_in_current_ns(&self) -> Pid {
+ let current = current!();
// SAFETY: Calling `task_active_pid_ns` with the current task is always safe.
- let namespace = unsafe { bindings::task_active_pid_ns(bindings::get_current()) };
+ let namespace = unsafe { bindings::task_active_pid_ns(current.as_raw()) };
// SAFETY: We know that `self.raw()` is valid by the type invariant.
unsafe { bindings::task_tgid_nr_ns(self.as_raw(), namespace) }
}
--
2.43.0
next prev parent reply other threads:[~2024-01-16 2:29 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-16 2:28 [PATCH] rust: task: add `as_raw()` to `Task` Antonio Hickey
2024-01-16 2:28 ` Antonio Hickey [this message]
2024-01-16 8:57 ` [PATCH] rust: task: use safe `current!` macro Alice Ryhl
2024-01-16 7:20 ` [PATCH] rust: task: add `as_raw()` to `Task` Greg KH
2024-01-16 7:29 ` Wedson Almeida Filho
2024-01-16 8:53 ` Alice Ryhl
2024-01-16 18:24 ` Boqun Feng
2024-01-16 19:03 ` Miguel Ojeda
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=20240116022823.64058-2-antoniohickey99@gmail.com \
--to=antoniohickey99@gmail.com \
--cc=a.hindborg@samsung.com \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=gary@garyguo.net \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=wedsonaf@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;
as well as URLs for NNTP newsgroup(s).