FROMGIT: 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 <boqun.feng@gmail.com>
Reviewed-by: Andreas Hindborg <a.hindborg@kernel.org>
Reviewed-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
[PM: subject tweak, description line trims]
Signed-off-by: Paul Moore <paul@paul-moore.com>
Bug: 403200195
(cherry picked from commit ab938b59e9de924de20ba4a8f768649573421204
git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/lsm.git next)
Change-Id: I946dfbeaddc86e622063d282f767be220dd7b94c
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
This commit is contained in:
@@ -47,6 +47,7 @@ impl Credential {
|
||||
///
|
||||
/// The caller must ensure that `ptr` is valid and remains valid for the lifetime of the
|
||||
/// returned [`Credential`] reference.
|
||||
#[inline]
|
||||
pub unsafe fn from_ptr<'a>(ptr: *const bindings::cred) -> &'a Credential {
|
||||
// SAFETY: The safety requirements guarantee the validity of the dereference, while the
|
||||
// `Credential` type being transparent makes the cast ok.
|
||||
@@ -59,6 +60,7 @@ impl Credential {
|
||||
}
|
||||
|
||||
/// Get the id for this security context.
|
||||
#[inline]
|
||||
pub fn get_secid(&self) -> u32 {
|
||||
let mut secid = 0;
|
||||
// SAFETY: The invariants of this type ensures that the pointer is valid.
|
||||
@@ -67,6 +69,7 @@ impl Credential {
|
||||
}
|
||||
|
||||
/// Returns the effective UID of the given credential.
|
||||
#[inline]
|
||||
pub fn euid(&self) -> Kuid {
|
||||
// SAFETY: By the type invariant, we know that `self.0` is valid. Furthermore, the `euid`
|
||||
// field of a credential is never changed after initialization, so there is no potential
|
||||
@@ -77,11 +80,13 @@ impl Credential {
|
||||
|
||||
// SAFETY: The type invariants guarantee that `Credential` is always ref-counted.
|
||||
unsafe impl AlwaysRefCounted for Credential {
|
||||
#[inline]
|
||||
fn inc_ref(&self) {
|
||||
// SAFETY: The existence of a shared reference means that the refcount is nonzero.
|
||||
unsafe { bindings::get_cred(self.0.get()) };
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn dec_ref(obj: core::ptr::NonNull<Credential>) {
|
||||
// SAFETY: The safety requirements guarantee that the refcount is nonzero. The cast is okay
|
||||
// because `Credential` has the same representation as `struct cred`.
|
||||
|
||||
Reference in New Issue
Block a user