From b54bde522777347f877e1f35981acb58621fe5d8 Mon Sep 17 00:00:00 2001 From: Antonio Hickey Date: Thu, 4 Jan 2024 01:43:36 -0500 Subject: [PATCH] rust: task: use safe `current!` macro 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 --- 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 72737f5d86abdd..ffe08c348b7263 100644 --- a/rust/kernel/task.rs +++ b/rust/kernel/task.rs @@ -168,8 +168,9 @@ impl Task { /// 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) } }