From 98585677f866706f72009f149ebb5f81f77ad5dc Mon Sep 17 00:00:00 2001 From: Alice Ryhl Date: Tue, 4 Mar 2025 10:26:52 +0000 Subject: [PATCH] FROMGIT: lsm,rust: mark SecurityCtx 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 vmlinux | grep ' _R'.*SecurityCtx | rustfilt ... T ::from_secid ... T ::drop However, these Rust symbols are trivial wrappers around the functions security_secid_to_secctx and security_release_secctx 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: Andreas Hindborg Signed-off-by: Alice Ryhl Reviewed-by: Fiona Behrens [PM: trimmed long description lines, subj tweak] Signed-off-by: Paul Moore Bug: 403200195 (cherry picked from commit 55e16418dd08fdccb7dc97fb8e975ded7c7ade9c git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/lsm.git next) Change-Id: I085121908bc18fccfdaa14c8e85091da504ede51 Signed-off-by: Alice Ryhl --- rust/kernel/security.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/rust/kernel/security.rs b/rust/kernel/security.rs index 7e50b375df26..4bb41a8f07b7 100644 --- a/rust/kernel/security.rs +++ b/rust/kernel/security.rs @@ -58,6 +58,7 @@ pub struct SecurityCtx { impl SecurityCtx { /// Get the security context given its id. + #[inline] pub fn from_secid(secid: u32) -> Result { let mut secdata = core::ptr::null_mut(); let mut seclen = 0u32; @@ -72,16 +73,19 @@ impl SecurityCtx { } /// Returns whether the security context is empty. + #[inline] pub fn is_empty(&self) -> bool { self.seclen == 0 } /// Returns the length of this security context. + #[inline] pub fn len(&self) -> usize { self.seclen } /// Returns the bytes for this security context. + #[inline] pub fn as_bytes(&self) -> &[u8] { let ptr = self.secdata; if ptr.is_null() { @@ -98,6 +102,7 @@ impl SecurityCtx { } impl Drop for SecurityCtx { + #[inline] fn drop(&mut self) { // SAFETY: By the invariant of `Self`, this frees a pointer that came from a successful // call to `security_secid_to_secctx` and has not yet been destroyed by