Skip to content

Commit 55e1641

Browse files
Darksonnpcmoore
authored andcommitted
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 <[email protected]> Signed-off-by: Alice Ryhl <[email protected]> Reviewed-by: Fiona Behrens <[email protected]> [PM: trimmed long description lines, subj tweak] Signed-off-by: Paul Moore <[email protected]>
1 parent 9ec84f7 commit 55e1641

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

rust/kernel/security.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub struct SecurityCtx {
2323

2424
impl SecurityCtx {
2525
/// Get the security context given its id.
26+
#[inline]
2627
pub fn from_secid(secid: u32) -> Result<Self> {
2728
// SAFETY: `struct lsm_context` can be initialized to all zeros.
2829
let mut ctx: bindings::lsm_context = unsafe { core::mem::zeroed() };
@@ -35,16 +36,19 @@ impl SecurityCtx {
3536
}
3637

3738
/// Returns whether the security context is empty.
39+
#[inline]
3840
pub fn is_empty(&self) -> bool {
3941
self.ctx.len == 0
4042
}
4143

4244
/// Returns the length of this security context.
45+
#[inline]
4346
pub fn len(&self) -> usize {
4447
self.ctx.len as usize
4548
}
4649

4750
/// Returns the bytes for this security context.
51+
#[inline]
4852
pub fn as_bytes(&self) -> &[u8] {
4953
let ptr = self.ctx.context;
5054
if ptr.is_null() {
@@ -61,6 +65,7 @@ impl SecurityCtx {
6165
}
6266

6367
impl Drop for SecurityCtx {
68+
#[inline]
6469
fn drop(&mut self) {
6570
// SAFETY: By the invariant of `Self`, this frees a context that came from a successful
6671
// call to `security_secid_to_secctx` and has not yet been destroyed by

0 commit comments

Comments
 (0)