Skip to content

Commit ab938b5

Browse files
Darksonnpcmoore
authored andcommitted
cred,rust: mark Credential methods inline
When you build the kernel using the llvm-19.1.4-rust-1.83.0-x86_64 toolchain provided by kernel.org with ARCH=arm64, the following symbols are generated: $ nm out-linux/vmlinux | grep ' _R'.*Credential | rustfilt ... T <kernel::cred::Credential>::get_secid ... T <kernel::cred::Credential as kernel::types::AlwaysRefCounted>::dec_ref ... T <kernel::cred::Credential as kernel::types::AlwaysRefCounted>::inc_ref However, these Rust symbols are trivial wrappers around the functions security_cred_getsecid, get_cred, and put_cred respectively. It doesn't make sense to go through a trivial wrapper for these functions, so mark them inline. Also mark other trivial methods inline to prevent similar cases in the future. After applying this patch, the above command will produce no output. Reviewed-by: Boqun Feng <[email protected]> Reviewed-by: Andreas Hindborg <[email protected]> Reviewed-by: Christian Brauner <[email protected]> Signed-off-by: Alice Ryhl <[email protected]> [PM: subject tweak, description line trims] Signed-off-by: Paul Moore <[email protected]>
1 parent 0a01bea commit ab938b5

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

rust/kernel/cred.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,15 @@ impl Credential {
4747
///
4848
/// The caller must ensure that `ptr` is valid and remains valid for the lifetime of the
4949
/// returned [`Credential`] reference.
50+
#[inline]
5051
pub unsafe fn from_ptr<'a>(ptr: *const bindings::cred) -> &'a Credential {
5152
// SAFETY: The safety requirements guarantee the validity of the dereference, while the
5253
// `Credential` type being transparent makes the cast ok.
5354
unsafe { &*ptr.cast() }
5455
}
5556

5657
/// Get the id for this security context.
58+
#[inline]
5759
pub fn get_secid(&self) -> u32 {
5860
let mut secid = 0;
5961
// SAFETY: The invariants of this type ensures that the pointer is valid.
@@ -62,6 +64,7 @@ impl Credential {
6264
}
6365

6466
/// Returns the effective UID of the given credential.
67+
#[inline]
6568
pub fn euid(&self) -> Kuid {
6669
// SAFETY: By the type invariant, we know that `self.0` is valid. Furthermore, the `euid`
6770
// field of a credential is never changed after initialization, so there is no potential
@@ -72,11 +75,13 @@ impl Credential {
7275

7376
// SAFETY: The type invariants guarantee that `Credential` is always ref-counted.
7477
unsafe impl AlwaysRefCounted for Credential {
78+
#[inline]
7579
fn inc_ref(&self) {
7680
// SAFETY: The existence of a shared reference means that the refcount is nonzero.
7781
unsafe { bindings::get_cred(self.0.get()) };
7882
}
7983

84+
#[inline]
8085
unsafe fn dec_ref(obj: core::ptr::NonNull<Credential>) {
8186
// SAFETY: The safety requirements guarantee that the refcount is nonzero. The cast is okay
8287
// because `Credential` has the same representation as `struct cred`.

0 commit comments

Comments
 (0)