Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions rust/kernel/auxiliary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,9 @@ kernel::impl_device_context_into_aref!(Device);

// SAFETY: Instances of `Device` are always reference-counted.
unsafe impl crate::sync::aref::AlwaysRefCounted for Device {
fn inc_ref(&self) {
fn inc_ref(obj: &Self) {
// SAFETY: The existence of a shared reference guarantees that the refcount is non-zero.
unsafe { bindings::get_device(self.as_ref().as_raw()) };
unsafe { bindings::get_device(obj.as_ref().as_raw()) };
}

unsafe fn dec_ref(obj: NonNull<Self>) {
Expand Down
4 changes: 2 additions & 2 deletions rust/kernel/block/mq/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ unsafe impl<T: Operations> Sync for Request<T> {}
// keeps the object alive in memory at least until a matching reference count
// decrement is executed.
unsafe impl<T: Operations> AlwaysRefCounted for Request<T> {
fn inc_ref(&self) {
self.wrapper_ref().refcount().inc();
fn inc_ref(obj: &Self) {
obj.wrapper_ref().refcount().inc();
}

unsafe fn dec_ref(obj: core::ptr::NonNull<Self>) {
Expand Down
4 changes: 2 additions & 2 deletions rust/kernel/cred.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ impl Credential {
// SAFETY: The type invariants guarantee that `Credential` is always ref-counted.
unsafe impl AlwaysRefCounted for Credential {
#[inline]
fn inc_ref(&self) {
fn inc_ref(obj: &Self) {
// SAFETY: The existence of a shared reference means that the refcount is nonzero.
unsafe { bindings::get_cred(self.0.get()) };
unsafe { bindings::get_cred(obj.0.get()) };
}

#[inline]
Expand Down
4 changes: 2 additions & 2 deletions rust/kernel/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,9 @@ kernel::impl_device_context_into_aref!(Device);

// SAFETY: Instances of `Device` are always reference-counted.
unsafe impl crate::sync::aref::AlwaysRefCounted for Device {
fn inc_ref(&self) {
fn inc_ref(obj: &Self) {
// SAFETY: The existence of a shared reference guarantees that the refcount is non-zero.
unsafe { bindings::get_device(self.as_raw()) };
unsafe { bindings::get_device(obj.as_raw()) };
}

unsafe fn dec_ref(obj: ptr::NonNull<Self>) {
Expand Down
4 changes: 2 additions & 2 deletions rust/kernel/device/property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,10 @@ impl fmt::Debug for FwNodeReferenceArgs {

// SAFETY: Instances of `FwNode` are always reference-counted.
unsafe impl crate::sync::aref::AlwaysRefCounted for FwNode {
fn inc_ref(&self) {
fn inc_ref(obj: &Self) {
// SAFETY: The existence of a shared reference guarantees that the
// refcount is non-zero.
unsafe { bindings::fwnode_handle_get(self.as_raw()) };
unsafe { bindings::fwnode_handle_get(obj.as_raw()) };
}

unsafe fn dec_ref(obj: ptr::NonNull<Self>) {
Expand Down
4 changes: 2 additions & 2 deletions rust/kernel/drm/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,9 @@ impl<T: drm::Driver, C: DeviceContext> Deref for Device<T, C> {
// SAFETY: DRM device objects are always reference counted and the get/put functions
// satisfy the requirements.
unsafe impl<T: drm::Driver, C: DeviceContext> AlwaysRefCounted for Device<T, C> {
fn inc_ref(&self) {
fn inc_ref(obj: &Self) {
// SAFETY: The existence of a shared reference guarantees that the refcount is non-zero.
unsafe { bindings::drm_dev_get(self.as_raw()) };
unsafe { bindings::drm_dev_get(obj.as_raw()) };
}

unsafe fn dec_ref(obj: NonNull<Self>) {
Expand Down
4 changes: 2 additions & 2 deletions rust/kernel/drm/gem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ macro_rules! impl_aref_for_gem_obj {
Self: IntoGEMObject,
$( $( $bind_param : $bind_trait ),+ )?
{
fn inc_ref(&self) {
fn inc_ref(obj: &Self) {
// SAFETY: The existence of a shared reference guarantees that the refcount is
// non-zero.
unsafe { bindings::drm_gem_object_get(self.as_raw()) };
unsafe { bindings::drm_gem_object_get(obj.as_raw()) };
}

unsafe fn dec_ref(obj: core::ptr::NonNull<Self>) {
Expand Down
4 changes: 2 additions & 2 deletions rust/kernel/drm/gpuvm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ unsafe impl<T: DriverGpuVm> Sync for GpuVm<T> {}

// SAFETY: By type invariants, the allocation is managed by the refcount in `self.vm`.
unsafe impl<T: DriverGpuVm> AlwaysRefCounted for GpuVm<T> {
fn inc_ref(&self) {
fn inc_ref(obj: &Self) {
// SAFETY: By type invariants, the allocation is managed by the refcount in `self.vm`.
unsafe { bindings::drm_gpuvm_get(self.vm.get()) };
unsafe { bindings::drm_gpuvm_get(obj.vm.get()) };
}

unsafe fn dec_ref(obj: NonNull<Self>) {
Expand Down
4 changes: 2 additions & 2 deletions rust/kernel/drm/gpuvm/vm_bo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ pub struct GpuVmBo<T: DriverGpuVm> {

// SAFETY: By type invariants, the allocation is managed by the refcount in `self.inner`.
unsafe impl<T: DriverGpuVm> AlwaysRefCounted for GpuVmBo<T> {
fn inc_ref(&self) {
fn inc_ref(obj: &Self) {
// SAFETY: By type invariants, the allocation is managed by the refcount in `self.inner`.
unsafe { bindings::drm_gpuvm_bo_get(self.inner.get()) };
unsafe { bindings::drm_gpuvm_bo_get(obj.inner.get()) };
}

unsafe fn dec_ref(obj: NonNull<Self>) {
Expand Down
8 changes: 4 additions & 4 deletions rust/kernel/fs/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,9 @@ unsafe impl Sync for File {}
// makes `ARef<File>` own a normal refcount.
unsafe impl AlwaysRefCounted for File {
#[inline]
fn inc_ref(&self) {
fn inc_ref(obj: &Self) {
// SAFETY: The existence of a shared reference means that the refcount is nonzero.
unsafe { bindings::get_file(self.as_ptr()) };
unsafe { bindings::get_file(obj.as_ptr()) };
}

#[inline]
Expand Down Expand Up @@ -235,9 +235,9 @@ pub struct LocalFile {
// makes `ARef<LocalFile>` own a normal refcount.
unsafe impl AlwaysRefCounted for LocalFile {
#[inline]
fn inc_ref(&self) {
fn inc_ref(obj: &Self) {
// SAFETY: The existence of a shared reference means that the refcount is nonzero.
unsafe { bindings::get_file(self.as_ptr()) };
unsafe { bindings::get_file(obj.as_ptr()) };
}

#[inline]
Expand Down
8 changes: 4 additions & 4 deletions rust/kernel/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,9 @@ kernel::impl_device_context_into_aref!(I2cAdapter);

// SAFETY: Instances of `I2cAdapter` are always reference-counted.
unsafe impl AlwaysRefCounted for I2cAdapter {
fn inc_ref(&self) {
fn inc_ref(obj: &Self) {
// SAFETY: The existence of a shared reference guarantees that the refcount is non-zero.
unsafe { bindings::i2c_get_adapter(self.index()) };
unsafe { bindings::i2c_get_adapter(obj.index()) };
}

unsafe fn dec_ref(obj: NonNull<Self>) {
Expand Down Expand Up @@ -501,9 +501,9 @@ kernel::impl_device_context_into_aref!(I2cClient);

// SAFETY: Instances of `I2cClient` are always reference-counted.
unsafe impl AlwaysRefCounted for I2cClient {
fn inc_ref(&self) {
fn inc_ref(obj: &Self) {
// SAFETY: The existence of a shared reference guarantees that the refcount is non-zero.
unsafe { bindings::get_device(self.as_ref().as_raw()) };
unsafe { bindings::get_device(obj.as_ref().as_raw()) };
}

unsafe fn dec_ref(obj: NonNull<Self>) {
Expand Down
8 changes: 4 additions & 4 deletions rust/kernel/mm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ unsafe impl Sync for Mm {}
// SAFETY: By the type invariants, this type is always refcounted.
unsafe impl AlwaysRefCounted for Mm {
#[inline]
fn inc_ref(&self) {
fn inc_ref(obj: &Self) {
// SAFETY: The pointer is valid since self is a reference.
unsafe { bindings::mmgrab(self.as_raw()) };
unsafe { bindings::mmgrab(obj.as_raw()) };
}

#[inline]
Expand Down Expand Up @@ -93,9 +93,9 @@ unsafe impl Sync for MmWithUser {}
// SAFETY: By the type invariants, this type is always refcounted.
unsafe impl AlwaysRefCounted for MmWithUser {
#[inline]
fn inc_ref(&self) {
fn inc_ref(obj: &Self) {
// SAFETY: The pointer is valid since self is a reference.
unsafe { bindings::mmget(self.as_raw()) };
unsafe { bindings::mmget(obj.as_raw()) };
}

#[inline]
Expand Down
4 changes: 2 additions & 2 deletions rust/kernel/mm/mmput_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ unsafe impl Sync for MmWithUserAsync {}
// SAFETY: By the type invariants, this type is always refcounted.
unsafe impl AlwaysRefCounted for MmWithUserAsync {
#[inline]
fn inc_ref(&self) {
fn inc_ref(obj: &Self) {
// SAFETY: The pointer is valid since self is a reference.
unsafe { bindings::mmget(self.as_raw()) };
unsafe { bindings::mmget(obj.as_raw()) };
}

#[inline]
Expand Down
4 changes: 2 additions & 2 deletions rust/kernel/opp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1043,9 +1043,9 @@ unsafe impl Sync for OPP {}
/// SAFETY: The type invariants guarantee that [`OPP`] is always refcounted.
unsafe impl AlwaysRefCounted for OPP {
#[inline]
fn inc_ref(&self) {
fn inc_ref(obj: &Self) {
// SAFETY: The existence of a shared reference means that the refcount is nonzero.
unsafe { bindings::dev_pm_opp_get(self.0.get()) };
unsafe { bindings::dev_pm_opp_get(obj.0.get()) };
}

#[inline]
Expand Down
4 changes: 2 additions & 2 deletions rust/kernel/pci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,9 @@ impl<'a> crate::dma::Device<'a> for Device<device::Core<'a>> {}

// SAFETY: Instances of `Device` are always reference-counted.
unsafe impl crate::sync::aref::AlwaysRefCounted for Device {
fn inc_ref(&self) {
fn inc_ref(obj: &Self) {
// SAFETY: The existence of a shared reference guarantees that the refcount is non-zero.
unsafe { bindings::pci_dev_get(self.as_raw()) };
unsafe { bindings::pci_dev_get(obj.as_raw()) };
}

unsafe fn dec_ref(obj: NonNull<Self>) {
Expand Down
4 changes: 2 additions & 2 deletions rust/kernel/pid_namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ impl PidNamespace {
// SAFETY: Instances of `PidNamespace` are always reference-counted.
unsafe impl AlwaysRefCounted for PidNamespace {
#[inline]
fn inc_ref(&self) {
fn inc_ref(obj: &Self) {
// SAFETY: The existence of a shared reference means that the refcount is nonzero.
unsafe { bindings::get_pid_ns(self.as_ptr()) };
unsafe { bindings::get_pid_ns(obj.as_ptr()) };
}

#[inline]
Expand Down
4 changes: 2 additions & 2 deletions rust/kernel/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,9 +519,9 @@ impl<'a> crate::dma::Device<'a> for Device<device::Core<'a>> {}

// SAFETY: Instances of `Device` are always reference-counted.
unsafe impl crate::sync::aref::AlwaysRefCounted for Device {
fn inc_ref(&self) {
fn inc_ref(obj: &Self) {
// SAFETY: The existence of a shared reference guarantees that the refcount is non-zero.
unsafe { bindings::get_device(self.as_ref().as_raw()) };
unsafe { bindings::get_device(obj.as_ref().as_raw()) };
}

unsafe fn dec_ref(obj: NonNull<Self>) {
Expand Down
4 changes: 2 additions & 2 deletions rust/kernel/pwm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,10 +631,10 @@ impl<T: PwmOps> Chip<T> {
// SAFETY: Implements refcounting for `Chip` using the embedded `struct device`.
unsafe impl<T: PwmOps> AlwaysRefCounted for Chip<T> {
#[inline]
fn inc_ref(&self) {
fn inc_ref(obj: &Self) {
// SAFETY: `self.0.get()` points to a valid `pwm_chip` because `self` exists.
// The embedded `dev` is valid. `get_device` increments its refcount.
unsafe { bindings::get_device(&raw mut (*self.0.get()).dev) };
unsafe { bindings::get_device(&raw mut (*obj.0.get()).dev) };
}

#[inline]
Expand Down
11 changes: 7 additions & 4 deletions rust/kernel/sync/aref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ use core::{
/// alive.)
pub unsafe trait AlwaysRefCounted {
/// Increments the reference count on the object.
fn inc_ref(&self);
///
/// This function should not be called accidentally; a type might declare their own `inc_ref`
/// function and it shouldn't be confused with this one.
fn inc_ref(obj: &Self);

/// Decrements the reference count on the object.
///
Expand Down Expand Up @@ -126,7 +129,7 @@ impl<T: AlwaysRefCounted> ARef<T> {
///
/// # // SAFETY: TODO.
/// unsafe impl AlwaysRefCounted for Empty {
/// fn inc_ref(&self) {}
/// fn inc_ref(obj: &Self) {}
/// unsafe fn dec_ref(_obj: NonNull<Self>) {}
/// }
///
Expand All @@ -145,7 +148,7 @@ impl<T: AlwaysRefCounted> ARef<T> {

impl<T: AlwaysRefCounted> Clone for ARef<T> {
fn clone(&self) -> Self {
self.inc_ref();
T::inc_ref(self);
// SAFETY: We just incremented the refcount above.
unsafe { Self::from_raw(self.ptr) }
}
Expand All @@ -162,7 +165,7 @@ impl<T: AlwaysRefCounted> Deref for ARef<T> {

impl<T: AlwaysRefCounted> From<&T> for ARef<T> {
fn from(b: &T) -> Self {
b.inc_ref();
T::inc_ref(b);
// SAFETY: We just incremented the refcount above.
unsafe { Self::from_raw(NonNull::from(b)) }
}
Expand Down
4 changes: 2 additions & 2 deletions rust/kernel/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,9 @@ impl CurrentTask {
// SAFETY: The type invariants guarantee that `Task` is always refcounted.
unsafe impl crate::sync::aref::AlwaysRefCounted for Task {
#[inline]
fn inc_ref(&self) {
fn inc_ref(obj: &Self) {
// SAFETY: The existence of a shared reference means that the refcount is nonzero.
unsafe { bindings::get_task_struct(self.as_ptr()) };
unsafe { bindings::get_task_struct(obj.as_ptr()) };
}

#[inline]
Expand Down
8 changes: 4 additions & 4 deletions rust/kernel/usb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,11 +393,11 @@ impl<Ctx: device::DeviceContext> AsRef<Device> for Interface<Ctx> {

// SAFETY: Instances of `Interface` are always reference-counted.
unsafe impl AlwaysRefCounted for Interface {
fn inc_ref(&self) {
fn inc_ref(obj: &Self) {
// SAFETY: The invariants of `Interface` guarantee that `self.as_raw()`
// returns a valid `struct usb_interface` pointer, for which we will
// acquire a new refcount.
unsafe { bindings::usb_get_intf(self.as_raw()) };
unsafe { bindings::usb_get_intf(obj.as_raw()) };
}

unsafe fn dec_ref(obj: NonNull<Self>) {
Expand Down Expand Up @@ -444,11 +444,11 @@ kernel::impl_device_context_into_aref!(Device);

// SAFETY: Instances of `Device` are always reference-counted.
unsafe impl AlwaysRefCounted for Device {
fn inc_ref(&self) {
fn inc_ref(obj: &Self) {
// SAFETY: The invariants of `Device` guarantee that `self.as_raw()`
// returns a valid `struct usb_device` pointer, for which we will
// acquire a new refcount.
unsafe { bindings::usb_get_dev(self.as_raw()) };
unsafe { bindings::usb_get_dev(obj.as_raw()) };
}

unsafe fn dec_ref(obj: NonNull<Self>) {
Expand Down
Loading