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 <kernel::security::SecurityCtx>::from_secid
... T <kernel::security::SecurityCtx as core::ops::drop::Drop>::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 <a.hindborg@kernel.org>
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Fiona Behrens <me@kloenk.dev>
[PM: trimmed long description lines, subj tweak]
Signed-off-by: Paul Moore <paul@paul-moore.com>

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 <aliceryhl@google.com>
This commit is contained in:
Alice Ryhl
2025-03-04 10:26:52 +00:00
parent 3fc1e21902
commit 98585677f8
+5
View File
@@ -58,6 +58,7 @@ pub struct SecurityCtx {
impl SecurityCtx {
/// Get the security context given its id.
#[inline]
pub fn from_secid(secid: u32) -> Result<Self> {
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